- Tạo controller
php artisan make:controller --resource AdminCategoriesController
Lúc này controller được tạo với các function index, create, store, destroy…
- Tạo model và migration
php artisan make:model Post -m
- Chỉnh sửa table – thêm cột mà không cần phải xoá dữ liệu
Giả sử table post cần thêm cột is_admin
php artisan make:migration add_is_admin_column_to_posts --table=posts
thêm column hay xoá column trong up() và down() method của file migration được tạo là xong. Sau đó chạy
php artisan migrate
VD tạo migration cho table comment
create_comments_table
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->integer('post_id')->unsigned()->index();
$table->integer('is_active')->default(0);
$table->string('author');
$table->string('photo');
$table->string('email');
$table->text('body');
$table->timestamps();
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('comments');
}
và create_comment_replies_table
public function up()
{
Schema::create('comment_replies', function (Blueprint $table) {
$table->increments('id');
$table->integer('comment_id')->unsigned()->index();
$table->integer('is_active')->default(0);
$table->string('author');
$table->string('photo');
$table->string('email');
$table->text('body');
$table->timestamps();
$table->foreign('comment_id')->references('id')->on('comments')->onDelete('cascade');
});
}
public function down()
{
Schema::drop('comment_replies');
}
nếu cột đó không như ý có thể quay trở lại – sửa file migration và chạy lại migrate. Lệnh trở lại:
php artisan migrate:rollback
- Xoá sạch các table
php artisan migrate:reset
- Khi không có node_modules
Chạy lênh: composer update

