Last active
August 29, 2015 14:06
-
-
Save hbsnow/96f82066783b78ca4300 to your computer and use it in GitHub Desktop.
Entrust 用のサンプル用 Seeder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class AssignedRolesSeeder extends Seeder { | |
| /** | |
| * Run the database seeds. | |
| * | |
| * @return void | |
| */ | |
| public function run() | |
| { | |
| Eloquent::unguard(); | |
| DB::table('assigned_roles')->delete(); | |
| $user = User::where('username', '=', 'admin')->first(); | |
| $admin = Role::where('name', '=', 'admin')->first(); | |
| $user->roles()->attach($admin->id); | |
| $user = User::where('username', '=', 'premium')->first(); | |
| $premium = Role::where('name', '=', 'premium')->first(); | |
| $user->roles()->attach($premium->id); | |
| $user = User::where('username', '=', 'regular')->first(); | |
| $regular = Role::where('name', '=', 'regular')->first(); | |
| $user->roles()->attach($regular->id); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class DatabaseSeeder extends Seeder { | |
| /** | |
| * Run the database seeds. | |
| * | |
| * @return void | |
| */ | |
| public function run() | |
| { | |
| Eloquent::unguard(); | |
| $this->call('UsersTableSeeder'); | |
| $this->call('RolesTableSeeder'); | |
| $this->call('PermissionsTableSeeder'); | |
| $this->call('AssignedRolesSeeder'); | |
| $this->call('PermissionRoleSeeder'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class PermissionRoleSeeder extends Seeder { | |
| /** | |
| * Run the database seeds. | |
| * | |
| * @return void | |
| */ | |
| public function run() | |
| { | |
| Eloquent::unguard(); | |
| DB::table('permission_role')->delete(); | |
| $manage_user = Permission::where('name', '=', 'manage_user')->first(); | |
| $manage_article = Permission::where('name', '=', 'manage_article')->first(); | |
| $read_premium = Permission::where('name', '=', 'read_premium')->first(); | |
| $read_regular = Permission::where('name', '=', 'read_regular')->first(); | |
| $admin = Role::where('name', '=', 'admin')->first(); | |
| $premium = Role::where('name', '=', 'premium')->first(); | |
| $regular = Role::where('name', '=', 'regular')->first(); | |
| $admin->perms()->sync(array($manage_user->id,$manage_article->id,$read_premium->id,$read_regular->id)); | |
| $premium->perms()->sync(array($read_premium->id,$read_regular->id)); | |
| $regular->perms()->sync(array($read_regular->id)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class PermissionsTableSeeder extends Seeder { | |
| /** | |
| * Run the database seeds. | |
| * | |
| * @return void | |
| */ | |
| public function run() | |
| { | |
| Eloquent::unguard(); | |
| DB::table('permissions')->delete(); | |
| $permissions = array( | |
| array( | |
| 'name' => 'manage_user', | |
| 'display_name' => 'ユーザ管理' | |
| ), | |
| array( | |
| 'name' => 'manage_article', | |
| 'display_name' => '記事管理' | |
| ), | |
| array( | |
| 'name' => 'read_premium', | |
| 'display_name' => 'プレミアム記事表示' | |
| ), | |
| array( | |
| 'name' => 'read_regular', | |
| 'display_name' => '一般記事表示' | |
| ) | |
| ); | |
| DB::table('permissions')->insert($permissions); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class RolesTableSeeder extends Seeder { | |
| /** | |
| * Run the database seeds. | |
| * | |
| * @return void | |
| */ | |
| public function run() | |
| { | |
| Eloquent::unguard(); | |
| DB::table('roles')->delete(); | |
| $roles = array( | |
| array( | |
| 'name' => 'admin' | |
| ), | |
| array( | |
| 'name' => 'premium' | |
| ), | |
| array( | |
| 'name' => 'regular' | |
| ) | |
| ); | |
| DB::table('roles')->insert($roles); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class UsersTableSeeder extends Seeder { | |
| /** | |
| * Run the database seeds. | |
| * | |
| * @return void | |
| */ | |
| public function run() | |
| { | |
| Eloquent::unguard(); | |
| DB::table('users')->delete(); | |
| $users = array( | |
| array( | |
| 'username' => 'admin', | |
| 'email' => '[email protected]', | |
| 'password' => Hash::make('admin'), | |
| 'confirmed' => 1, | |
| 'confirmation_code' => md5(microtime().Config::get('app.key')), | |
| 'created_at' => new DateTime, | |
| 'updated_at' => new DateTime, | |
| ), | |
| array( | |
| 'username' => 'premium', | |
| 'email' => '[email protected]', | |
| 'password' => Hash::make('premium'), | |
| 'confirmed' => 1, | |
| 'confirmation_code' => md5(microtime().Config::get('app.key')), | |
| 'created_at' => new DateTime, | |
| 'updated_at' => new DateTime, | |
| ), | |
| array( | |
| 'username' => 'regular', | |
| 'email' => '[email protected]', | |
| 'password' => Hash::make('regular'), | |
| 'confirmed' => 1, | |
| 'confirmation_code' => md5(microtime().Config::get('app.key')), | |
| 'created_at' => new DateTime, | |
| 'updated_at' => new DateTime, | |
| ) | |
| ); | |
| DB::table('users')->insert($users); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment