Created
November 27, 2015 12:05
-
-
Save fabianmu/f76bf430ddeb066b1a88 to your computer and use it in GitHub Desktop.
laravel role based permission acl sample
This file contains 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 | |
use Illuminate\Database\Seeder; | |
use Illuminate\Support\Facades\App; | |
use App\Role; | |
use App\Permission; | |
use App\User; | |
class RoleAndPermissionSeeder extends Seeder | |
{ | |
/** | |
* Run the database seeds. | |
* | |
* @return void | |
*/ | |
public function run() | |
{ | |
// create roles | |
$manager = factory(Role::class)->create([ | |
'name' => 'manager', | |
'label' => 'Manager' | |
]); | |
// create permissions | |
$listEditors = factory(Permission::class)->create([ | |
'name' => 'listEditors', | |
'label' => 'View all Editor' | |
]); | |
$createEditor = factory(Permission::class)->create([ | |
'name' => 'createEditor', | |
'label' => 'Create an Editor' | |
]); | |
// assign permissions to roles | |
$manager->givePermissionTo($listEditors); | |
$managerUser = factory(User::class)->create([ | |
'first_name' => 'Tinker', | |
'last_name' => 'Bell', | |
'email' => '[email protected]', | |
'password' => bcrypt('password') | |
]); | |
$managerUser->assignRole('manager'); | |
} | |
} |
This file contains 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
@can('listEditors') | |
<h4>Editors:</h4> | |
<ul> | |
<li {{ Request::is('users') ? 'class="active"' : '' }}> | |
<a href="{{ action('CMS\UserController@index', ['roleName' => 'editor']) }}">All Editors</a> | |
</li> | |
@can('createEditor') | |
<li {{ Request::is('users/create') ? 'class="active"' : '' }}> | |
<a href="{{ action('CMS\UserController@create', ['roleName' => 'editor']) }}">Add an editor</a> | |
</li> | |
@endcan | |
</ul> | |
@endcan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment