Answer the question
In order to leave comments, you need to log in
Adding initial data with migrations?
I usephp artisan db:seed
User::create(array(
'name' => 'admin',
'email' => '[email protected]',
'password' => bcrypt('adminadmin'),
));
Role::create(array(
'name' => 'superadmin',
'display_name' => 'superadmin',
'description' => 'superadmin',
));
role_user
that links the role and the user (fields role_id
and user_id
). How after INSERT'a to connect the user and a role? users
and roles
then add these id to the table role_user
?$user = User::create(array(
'name' => 'admin',
'email' => '[email protected]',
'password' => bcrypt('adminadmin'),
));
$user_id = $user->id;
...
аналогично с ролью
...
$user_id = 'user_id' => 'data';
$role_id = 'role_id' => 'data';
DB::table('role_user')->insert($data);
Answer the question
In order to leave comments, you need to log in
You just need to read the section Eloquent: Relationships : Many To Many , Attaching / Detaching .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question