1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Schema\Blueprint; |
4
|
|
|
use Illuminate\Database\Migrations\Migration; |
5
|
|
|
|
6
|
|
|
class Groups extends Migration |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Run the migrations. |
10
|
|
|
* |
11
|
|
|
* @return void |
12
|
|
|
*/ |
13
|
|
|
public function up() |
14
|
|
|
{ |
15
|
|
|
Schema::create('groups', function (Blueprint $table) { |
16
|
|
|
$table->increments('id'); |
17
|
|
|
$table->string('name',100)->unique(); |
18
|
|
|
$table->softDeletes(); |
19
|
|
|
$table->timestamps(); |
20
|
|
|
}); |
21
|
|
|
|
22
|
|
|
Schema::create('users_groups', function (Blueprint $table) { |
23
|
|
|
$table->increments('id'); |
24
|
|
|
$table->integer('user_id'); |
25
|
|
|
$table->integer('group_id'); |
26
|
|
|
$table->softDeletes(); |
27
|
|
|
$table->timestamps(); |
28
|
|
|
|
29
|
|
|
$table->index(['user_id']); |
30
|
|
|
}); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Create Default groups. |
34
|
|
|
*/ |
35
|
|
|
\DB::table('groups')->insert( |
36
|
|
|
[ |
37
|
|
|
[ |
38
|
|
|
'name' => 'Admin', |
39
|
|
|
'created_at' => \DB::raw('NOW()'), |
40
|
|
|
'updated_at' => \DB::raw('NOW()') |
41
|
|
|
] |
42
|
|
|
] |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Assign default users to admin groups. |
47
|
|
|
*/ |
48
|
|
|
$adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id; |
49
|
|
|
$adminUserId = \DB::table('users')->where('email', '[email protected]')->select('id')->first()->id; |
50
|
|
|
\DB::table('users_groups')->insert( |
51
|
|
|
[ |
52
|
|
|
'user_id' => $adminUserId, |
53
|
|
|
'group_id' => $adminGroupId, |
54
|
|
|
'created_at' => \DB::raw('NOW()'), |
55
|
|
|
'updated_at' => \DB::raw('NOW()') |
56
|
|
|
] |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Reverse the migrations. |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function down() |
66
|
|
|
{ |
67
|
|
|
Schema::dropIfExists('groups'); |
68
|
|
|
Schema::dropIfExists('users_groups'); |
69
|
|
|
} |
70
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.