I have problem in laravel 5.2 when i Register a new user With A Form All Records Inserted In database in table users But My remember_token Field is always null If I click logout remember_token will be inserted. but I want to create multiple users from this form Because I want the administrator alone to have the right to create user accounts I want when i create the user accounts without logout for each time
Controller
class AuthController extends Controller
{
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
protected function create(array $data)
{
$user =User::create([
'username' => $data['username'],
'droit'=> $data['droit'],
'idUtilisateur'=> $data['idUtilisateur'],
'password' => bcrypt($data['password']),
]);
return $user;
}
}
View
<form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
<label for="username" class="col-md-4 control-label">Nom d'utilisateur</label>
<div class="col-md-6">
<input id="username" type="text" class="form-control" name="username" value="{{ old('username') }}">
@if ($errors->has('username'))
<span class="help-block">
<strong>{{ $errors->first('username') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Mot de Passe </label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password">
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
...
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-user"></i> Ajouter
</button>
</div>
</div>
</form>
Model
class CreateUsersTable extends Migration
{
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('username')->unique();
$table->string('password');
$table->integer('droit');
$table->integer('idUtilisateur');
$table->integer('EtatCompte');
$table->rememberToken();
$table->timestamps();
});
}
thank you
答案 0 :(得分:0)
If all you want is to allow an administrator to create user accounts, do not use AuthController@create
method for that.
So, create a form in admin dashboard and just create a user manually without logging in as created user:
public function store(Request $request)
{
User::create([
'email' => $request->email,
'username' => $request->username,
'password' => bcrypt($request->password),
]);
return redirect()->back()->with('message', 'User was created');
}