database/seeds/PermissionsTableSeeder.php
/**
     * Run the database seeds.
     *
     * @return void
     */
Run the database seeds.
@return void
Run the database seeds . @return void
public function run()
    {
        $products_permission = array(
            "products.index",
            "products.edit",
            "products.show",
            "products.create",
            "products.destroy"
        );
        $products_description = array(
            "Ver lista de productos",
            "Editar lista de productos",
            "Mostrar lista de productos",
            "Crear productos",
            "Borrar productos",
        );
        $users_permission = array(
            "users.index",
            "users.edit",
            "users.show",
            "users.create",
            "users.destroy"
        );
        $users_description = array(
            "Ver lista de usuarios",
            "Editar lista de usuarios",
            "Mostrar lista de usuarios",
            "Crear usuarios",
            "Borrar usuarios",
        );
        $roles_permission = array(
            "roles.index",
            "roles.edit",
            "roles.show",
            "roles.create",
            "roles.destroy"
        );
        $roles_description = array(
            "Ver lista de roles",
            "Editar lista de roles",
            "Mostrar lista de roles",
            "Crear roles",
            "Borrar roles",
        );
        for ($i=0;$i<=count($products_permission)-1;$i++){
            Permission::create(['name' => $products_permission[$i]]);
            Permission::where('name', 'like','%'.$products_permission[$i].'%')
                ->update(['description' => $products_description[$i]]);
        }
        for ($i=0;$i<=count($users_permission)-1;$i++){
            Permission::create(['name' => $users_permission[$i]]);
            Permission::where('name', 'like','%'.$users_permission[$i].'%')
                ->update(['description' => $users_description[$i]]);
        }
        for ($i=0;$i<=count($roles_permission)-1;$i++){
            Permission::create(['name' => $roles_permission[$i]]);
            Permission::where('name', 'like','%'.$roles_permission[$i].'%')
              ->update(['description' => $roles_description[$i]]);
        }
        $admin = Role::create(['name' => 'SuperAdmin']);
        $admin->givePermissionTo(Permission::where('guard_name', 'web')->get());
        $guest = Role::create(['name' => 'Guest']);
        $guest->givePermissionTo([
            'products.index',
            'users.index',
            'users.edit',
        ]);
        $user = User::find(1); 
        $user->assignRole('SuperAdmin');
        foreach (User::where('id', '>',1)->cursor() as $guest) {
            $guest->assignRole('Guest');
        }
        foreach (Permission::where('name', 'like','%users%')->cursor() as $tag) {
            $tag->update(['tag' => 'users']);
        }
        foreach (Permission::where('name', 'like','%products%')->cursor() as $tag) {
            $tag->update(['tag' => 'products']);
        }
        foreach (Permission::where('name', 'like','%roles%')->cursor() as $tag) {
            $tag->update(['tag' => 'roles']);
        }
    }
public function run ( ) { $ products_permission = array ( " products.index " , " products.edit " , " products.show " , " products.create " , " products.destroy " ) ; $ products_description = array ( " Ver lista de productos " , " Editar lista de productos " , " Mostrar lista de productos " , " Crear productos " , " Borrar productos " , ) ; $ users_permission = array ( " users.index " , " users.edit " , " users.show " , " users.create " , " users.destroy " ) ; $ users_description = array ( " Ver lista de usuarios " , " Editar lista de usuarios " , " Mostrar lista de usuarios " , " Crear usuarios " , " Borrar usuarios " , ) ; $ roles_permission = array ( " roles.index " , " roles.edit " , " roles.show " , " roles.create " , " roles.destroy " ) ; $ roles_description = array ( " Ver lista de roles " , " Editar lista de roles " , " Mostrar lista de roles " , " Crear roles " , " Borrar roles " , ) ; for ( $ i = 0 ; $ i <= count ( $ products_permission ) - 1 ; $ i ++ ) { Permission :: create ( [ 'name' => $ products_permission [ $ i ] ] ) ; Permission :: where ( 'name' , 'like' , '%' . $ products_permission [ $ i ] . '%' ) -> update ( [ 'description' => $ products_description [ $ i ] ] ) ; } for ( $ i = 0 ; $ i <= count ( $ users_permission ) - 1 ; $ i ++ ) { Permission :: create ( [ 'name' => $ users_permission [ $ i ] ] ) ; Permission :: where ( 'name' , 'like' , '%' . $ users_permission [ $ i ] . '%' ) -> update ( [ 'description' => $ users_description [ $ i ] ] ) ; } for ( $ i = 0 ; $ i <= count ( $ roles_permission ) - 1 ; $ i ++ ) { Permission :: create ( [ 'name' => $ roles_permission [ $ i ] ] ) ; Permission :: where ( 'name' , 'like' , '%' . $ roles_permission [ $ i ] . '%' ) -> update ( [ 'description' => $ roles_description [ $ i ] ] ) ; } $ admin = Role :: create ( [ 'name' => 'SuperAdmin' ] ) ; $ admin -> givePermissionTo ( Permission :: where ( 'guard_name' , 'web' ) -> get ( ) ) ; $ guest = Role :: create ( [ 'name' => 'Guest' ] ) ; $ guest -> givePermissionTo ( [ 'products.index' , 'users.index' , 'users.edit' , ] ) ; $ user = User :: find ( 1 ) ; $ user -> assignRole ( 'SuperAdmin' ) ; foreach ( User :: where ( 'id' , '>' , 1 ) -> cursor ( ) as $ guest ) { $ guest -> assignRole ( 'Guest' ) ; } foreach ( Permission :: where ( 'name' , 'like' , '%users%' ) -> cursor ( ) as $ tag ) { $ tag -> update ( [ 'tag' => 'users' ] ) ; } foreach ( Permission :: where ( 'name' , 'like' , '%products%' ) -> cursor ( ) as $ tag ) { $ tag -> update ( [ 'tag' => 'products' ] ) ; } foreach ( Permission :: where ( 'name' , 'like' , '%roles%' ) -> cursor ( ) as $ tag ) { $ tag -> update ( [ 'tag' => 'roles' ] ) ; } }
Run the database seeds.
Run the database seeds .
//Productos //Users //Roles //creamos el permiso y la descripcion productos //creamos el permiso y la descripcion usuarios //creamos el permiso y la descripcion roles //Admin //Asignaos full permisos al super admin //Guest //User Admin //Italo Morales //User Guest //Asig tags user //Asig tags products //Asig tags roles