Я хочу назначить роль пользователю во время регистрации в Laravel 5.2 по умолчанию AuthController, так как это сделать, если кто-нибудь идеи? Здесь у меня есть три таблицы пользователи, роли и user_roles благодаритКак назначить роль в Larvel по умолчанию AuthController
Мои миграции: users_migration:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
}
USER_ROLE:
public function up()
{
Schema::create('user_roles', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('role_id');
$table->timestamps();
});
}
роли миграции:
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 60);
$table->text('description');
$table->timestamps();
});
}
И модели:
модели Пользователь:
.
.
.
public function roles()
{
return $this->belongsToMany('App\Role', 'user_roles','user_id','role_id');
}
модель Роль:
class Role extends Model
{
protected $primaryKey = 'r_id';
public function users()
{
return $this->belongsToMany('App\User', 'user_roles','role_id','user_id');
}
}