本文整理汇总了PHP中Role::truncate方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::truncate方法的具体用法?PHP Role::truncate怎么用?PHP Role::truncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role::truncate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
/**
* Truncate Tables
*/
Permission::truncate();
Role::truncate();
User::truncate();
DB::table('assigned_roles')->truncate();
DB::table('permission_role')->truncate();
/**
* Seed Datas
*/
$permissions = [['name' => 'Role:list', 'display_name' => 'List Roles', 'group_name' => 'Role'], ['name' => 'Role:show', 'display_name' => 'Show Role', 'group_name' => 'Role'], ['name' => 'Role:create', 'display_name' => 'Create New Role', 'group_name' => 'Role'], ['name' => 'Role:edit', 'display_name' => 'Edit Existing Role', 'group_name' => 'Role'], ['name' => 'Role:delete', 'display_name' => 'Delete Existing Role', 'group_name' => 'Role'], ['name' => 'Permission:list', 'display_name' => 'List Permissions', 'group_name' => 'Permission'], ['name' => 'Permission:show', 'display_name' => 'Show Permission', 'group_name' => 'Permission'], ['name' => 'Permission:create', 'display_name' => 'Create New Permission', 'group_name' => 'Permission'], ['name' => 'Permission:edit', 'display_name' => 'Edit Existing Permission', 'group_name' => 'Permission'], ['name' => 'Permission:delete', 'display_name' => 'Delete Existing Permission', 'group_name' => 'Permission'], ['name' => 'User:list', 'display_name' => 'List Users', 'group_name' => 'Users'], ['name' => 'User:show', 'display_name' => 'Show User', 'group_name' => 'Users'], ['name' => 'User:create', 'display_name' => 'Create New User', 'group_name' => 'Users'], ['name' => 'User:edit', 'display_name' => 'Edit Existing User', 'group_name' => 'Users'], ['name' => 'User:delete', 'display_name' => 'Delete Existing User', 'group_name' => 'Users'], ['name' => 'User:set_confirmation', 'display_name' => 'Set Existing User\'s Confirmed Status', 'group_name' => 'Users'], ['name' => 'User:set_password', 'display_name' => 'Set Existing User\'s Password', 'group_name' => 'Users']];
$roles = [['name' => 'Admin'], ['name' => 'Role Admin'], ['name' => 'Permission Admin'], ['name' => 'User Admin'], ['name' => 'User'], ['name' => 'Upload Admin']];
$users = [['first_name' => 'System', 'last_name' => 'Administrator', 'username' => 'admin', 'email' => 'admin@example.com', 'password' => 'admin', 'password_confirmation' => 'admin', 'confirmed' => 1], ['first_name' => 'System', 'last_name' => 'User', 'username' => 'user', 'email' => 'user@example.com', 'password' => 'user', 'password_confirmation' => 'user', 'confirmed' => 1]];
$user_roles = [1 => [1], 2 => [6]];
/**
* Insert Into DB
*/
foreach ($permissions as $data) {
Permission::create($data);
}
foreach ($roles as $data) {
Role::create($data);
}
foreach ($users as $data) {
$user = User::create($data);
if (isset($user_roles[$user->id])) {
$user->roles()->sync($user_roles[$user->id]);
}
}
}
示例2: tearDown
public function tearDown()
{
Mockery::close();
User::truncate();
Book::truncate();
Item::truncate();
Role::truncate();
Client::truncate();
Group::truncate();
Photo::truncate();
}
示例3: run
public function run()
{
$faker = Faker::create();
Role::truncate();
Role::create(['name' => 'Admin']);
Role::create(['name' => 'Moderator']);
Role::create(['name' => 'User']);
DB::table('role_user')->truncate();
// $john = User::find(1);
//
// $john->roles()->attach(1);
}
示例4: run
public function run()
{
Role::truncate();
$adminRole = new Role();
$adminRole->name = 'admin';
$adminRole->save();
$resellerRole = new Role();
$resellerRole->name = 'reseller';
$resellerRole->save();
$clientRole = new Role();
$clientRole->name = 'user';
$clientRole->save();
$subscriberRole = new Role();
$subscriberRole->name = 'subscriber';
$subscriberRole->save();
$user = User::where('username', '=', 'admin')->first();
$user->attachRole($adminRole);
$user = User::where('username', '=', 'user')->first();
$user->attachRole($clientRole);
$user = User::where('username', '=', 'user2')->first();
$user->attachRole($clientRole);
}
示例5: generateRoles
public function generateRoles()
{
Role::truncate();
Role::create(array('name' => 'admin'));
Role::create(array('name' => 'member'));
}