-
Notifications
You must be signed in to change notification settings - Fork 0
/
laravel_command.txt
83 lines (55 loc) · 3.17 KB
/
laravel_command.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(1) Add new Table
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 Create a migration file using cli command:_------>php artisan make:migration add_table --table=table_name
2 after column create and migrate
(2) Add new Column to existing table
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 Create a migration file using cli command:_------>php artisan make:migration add_paid_to_users_table --table=table_name
2 A file will be created in the migrations folder, open it in an editor.
Add to the function up():
~~~~~~~~~~~~~~~~~~~~~~~~~
Schema::table('users', function (Blueprint $table) {
// Create new column
// You probably want to make the new column nullable
//status is previous column to paid column
$table->integer('paid')->nullable()->after('status');
}
3 Add to the function down(), this will run in case migration fails for some reasons:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$table->dropColumn('paid');
4 Run migration using cli command:---------->php artisan migrate
(3)Modyfing Column
***rename column
~~~~~~~~~~~~~~~~
1 install docrine using this command ---->composer require doctrine/dbal
2 Create a migration file using cli command:_------>php artisan make:migration add_paid_to_users_table --table=table_name
3 Add to the function up():
~~~~~~~~~~~~~~~~~~~~~~~~~
Schema::table('users', function (Blueprint $table) {
// rename column
$table->renameColumn('previous_name','rename_name');
}
4 Add to the function down(), this will run in case migration fails for some reasons:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$table->renameColumn('previous_name','rename_name');
5 Run migration using cli command:---------->php artisan migrate
***change type or attributes of a column
~~~~~~~~~~~~~~~~~~~~~~~~~
1 if dont install docrine ,must install docrine using this command ---->composer require doctrine/dbal
2 Create a migration file using cli command:_------>php artisan make:migration add_paid_to_users_table --table=table_name
3 Add to the function up():
~~~~~~~~~~~~~~~~~~~~~~~~~
Schema::table('users', function (Blueprint $table) {
//change type of attributes of column
//below line change type or attributes your own
//last add ->change() method
$table->string('column_name')->(modyfiers your own)->change();
}
4 Add to the function down(), this will run in case migration fails for some reasons:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//hear add rollback state (before change state)
$table->integer('collumn_name')->change();
5 Run migration using cli command:---------->php artisan migrate
php artisan route:cache
make seeders
php artisan make:seeder UserSeeder