/** * Run the database seeds. * * @return void */ public function run() { $adminRole = App\Models\Role::where('slug', 'admin')->first(); $userRole = App\Models\Role::where('slug', 'user')->first(); $adminRole->permissions()->sync(App\Models\Permission::all()->lists('id')->toArray()); $userRole->permissions()->sync(App\Models\Permission::whereIn('slug', ['permission.index', 'role.index'])->lists('id')->toArray()); $admin = App\Models\User::where('email', '*****@*****.**')->first(); $user = App\Models\User::where('email', '*****@*****.**')->first(); $admin->roles()->sync(App\Models\Role::where('slug', 'admin')->lists('id')->toArray()); $user->roles()->sync(App\Models\Role::where('slug', 'user')->lists('id')->toArray()); }
// // $createPost = new App\Models\Permission(); // $createPost->name = 'create-post'; // $createPost->display_name = 'Create Posts'; // optional // // Allow a user to... // $createPost->description = 'create new blog posts'; // optional // $createPost->save(); // // $editUser = new App\Models\Permission(); // $editUser->name = 'edit-user'; // $editUser->display_name = 'Edit Users'; // optional // // Allow a user to... // $editUser->description = 'edit existing users'; // optional // $editUser->save(); // $user = App\Models\User::where('email', '=', '*****@*****.**')->first(); // $client = App\Models\Role::where('name', '=', 'client')->first(); // $user->attachRole($client); // // $createPost = App\Models\Permission::where('name','=','create-post')->first(); // $editUser = App\Models\Permission::where('name','=','edit-user')->first(); // $admin = App\Models\Role::where('name', '=', 'admin')->first(); // $admin->attachPermissions(array($createPost, $editUser)); // $client->attachPermission($createPost); var_dump($user->hasRole('admin')); // false var_dump($user->hasRole('client')); // true var_dump($user->can('edit-user')); // false var_dump($user->can('create-post'));
public function testLogin() { App\Models\User::create(['email' => '*****@*****.**', 'password' => bcrypt('testing')]); $this->visit('/login')->type('*****@*****.**', 'email')->type('testing', 'password')->press('Login')->seePageIs('/dashboard'); App\Models\User::where('email', '*****@*****.**')->delete(); }
$user->user_type_id = 3; $user->username = '******' . (App\Models\User::count() + 1); $user->save(); return ['occupation' => $faker->word, 'user_id' => $user->id]; }); $factory->define(App\Models\Foundation::class, function ($faker) { $user = factory('App\\Models\\User')->make(); $user->user_type_id = 4; $user->username = '******' . (App\Models\User::count() + 1); $user->save(); return ['designation' => $faker->word, 'user_id' => $user->id]; }); $factory->define(App\Models\StudentTimetable::class, function ($faker) { $subjects = App\Models\Subject::all(); $courseSchool = App\Models\CourseSchool::all()->random(); return ['period' => $faker->numberBetween(1, 7), 'mon' => $subjects->random()->id, 'tue' => $subjects->random()->id, 'wed' => $subjects->random()->id, 'thu' => $subjects->random()->id, 'fri' => $subjects->random()->id, 'sat' => $subjects->random()->id, 'course_school_id' => $courseSchool->id]; }); $factory->define(App\Models\StaffTimetable::class, function ($faker) { $course = App\Models\Course::all(); $staff = App\Models\User::where('user_type_id', 2)->get()->random(); return ['period' => $faker->numberBetween(1, 7), 'mon' => $course->random()->id, 'tue' => $course->random()->id, 'wed' => $course->random()->id, 'thu' => $course->random()->id, 'fri' => $course->random()->id, 'sat' => $course->random()->id, 'staff_id' => $staff->id]; }); $factory->define(App\Models\Book::class, function ($faker) { return ['title' => $faker->sentence(3), 'subject_id' => App\Models\Subject::all()->random()->id, 'description' => $faker->sentence, 'author' => $faker->name, 'publisher' => $faker->sentence(3), 'uploaded_by' => App\Models\Staff::all()->random()->user_id, 'image' => $faker->imageUrl(300, 100, 'transport', true, 'Faker'), 'book_url' => $faker->imageUrl(300, 300, 'people', true, 'Faker') . ".pdf"]; }); $factory->define(App\Models\News::class, function ($faker) { return ['title' => $faker->sentence(3), 'level' => ['PUBLIC', 'STUDENT', 'FOUNDATION', 'STAFF', 'PARENT', 'SCHOOL', 'CLASS'][array_rand(['PUBLIC', 'STUDENT', 'FOUNDATION', 'STAFF', 'PARENT', 'SCHOOL', 'CLASS'])], 'image' => $faker->imageUrl(300, 100, null, true, 'Faker'), 'content' => $faker->paragraph, 'creator_id' => App\Models\User::where('user_type_id', 4)->orWhere('user_type_id', 5)->get()->random()->id]; }); $factory->define(App\Models\Talent::class, function ($faker) { return ['image' => $faker->imageUrl(300, 100, 'abstract', true, 'Faker'), 'content' => $faker->paragraph, 'posted_by' => App\Models\User::all()->random()->id]; });