<?php
use App\Role;
use App\User;
use App\Permission;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$developer = Role::where('slug','web-developer')->first();
$manager = Role::where('slug','project-manager')->first();
$createTasks = Permission::where('slug','create-tasks')->first();
$mangeUsers = Permission::where('slug','mange-users')->first();
$user1 = new User();
$user1->name = 'Armen';
$user1->surname = 'Karapetyan';
$user1->email = 'arm@gmail.com';
$user1->password = bcrypt('secret');
$user1->save();
$user1->roles()->attach($developer);
$user1->permissions()->attach($createTasks);
$user2 = new User();
$user2->name = 'Karen';
$user2->surname = 'Minasyan';
$user2->email = 'karen@gmail.com';
$user2->password = bcrypt('secret');
$user2->roles()->attach($manager);
$user2->permissions()->attach($mangeUsers);
}
}
<?php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
use App\Role;
class RoleSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$manager = new Role();
$manager->name = 'Project-manager';
$manager->slug = 'project-manager';
$manager->save();
$developer = new Role();
$developer->name = 'Web Developer';
$developer->slug = 'web-developer';
$developer->save();
}
}
<?php
use Illuminate\Database\Eloquent\Model;
use App\Permission;
use Illuminate\Database\Seeder;
class PermissionSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$managerUser = new Permission();
$managerUser->name = 'Mange-users';
$managerUser->slug = 'mange-users';
$managerUser->save();
$createTasks = new Permission();
$createTasks->name = 'Create-Tasks';
$createTasks->slug = 'create-tasks';
$createTasks->save();
}
}
<?php
use App\Role;
use App\User;
use App\Permission;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call(RoleSeeder::class);
$this->call(PermissionSeeder::class);
$this->call(UserSeeder::class);
}
}
JhaoDa, Мне только одно интересно к чему этот отношение ко мне чего хотите добытся ? не кто сразу не начял пысать код и ты в том ряду и я преже чем обсуждать мои ответы вспомни свое прошлое