1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
use App\User; |
5
|
|
|
use Spatie\Permission\Models\Permission; |
6
|
|
|
use Spatie\Permission\Models\Role; |
7
|
|
|
|
8
|
|
|
//si no esta declarada (function_exists('nom_funcio')) la declaro |
9
|
|
|
|
10
|
|
|
if(! function_exists('initialize_task_permissions')){ |
11
|
|
|
|
12
|
|
|
function initialize_task_permissions(){ |
13
|
|
|
//Permission::create(['name'=>'list-tasks']); |
14
|
|
|
//Crea només si no existeix |
15
|
|
|
Permission::firstOrCreate(['name'=>'list-tasks']); |
16
|
|
|
Permission::firstOrCreate(['name'=>'show-tasks']); |
17
|
|
|
Permission::firstOrCreate(['name'=>'store-tasks']); |
18
|
|
|
Permission::firstOrCreate(['name'=>'update-tasks']); |
19
|
|
|
Permission::firstOrCreate(['name'=>'destroy-tasks']); |
20
|
|
|
|
21
|
|
|
$role = Role::firstOrCreate(['name'=>'task-manager']); |
22
|
|
|
$role -> givePermissionTo('list-tasks'); |
23
|
|
|
$role -> givePermissionTo('show-tasks'); |
24
|
|
|
$role -> givePermissionTo('store-tasks'); |
25
|
|
|
$role -> givePermissionTo('update-tasks'); |
26
|
|
|
$role -> givePermissionTo('destroy-tasks'); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if(! function_exists('create_user')){ |
31
|
|
|
|
32
|
|
|
function create_user(){ |
33
|
|
|
factory(User::class)->create([ |
34
|
|
|
'name' => env('TASKS_USER_NAME','Quim González Colat'), |
35
|
|
|
'email' => env('TASKS_USER_EMAIL','[email protected]'), |
36
|
|
|
'password' => bcrypt(env('TASKS_USER_PASSWORD')) |
37
|
|
|
]); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if(! function_exists('first_user_as_task_manager')){ |
42
|
|
|
|
43
|
|
|
function first_user_as_task_manager(){ |
|
|
|
|
44
|
|
|
User::all()->first()->assignRole('task-manager'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
} |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.