一、項目安裝
用composer控制,安裝laravel。
php composer.phar create-project laravel/laravel 項目名
如果報錯
[Symfony\Component\Process\Exception\RuntimeException]
The Process class relies on proc_open, which is not available on your PHP installation.
打開php.ini,並搜索disable_functions指令,找到proc_open並刪除即可。
國內可使用全量鏡像:https://pkg.phpcomposer.com/
修改項目:composer.json文件,添加以下代碼。
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}
}
composer作用是控制項目依賴包。
二、數據庫控制-migration
解決團隊合作下數據庫結構不統一問題。
直接用sql寫的話,看起來雜亂,報錯一般在數據庫端,而且每次新建都要drop數據表。
使用migration ,一般新建目錄為database/migration,默認建3個文件對應3張表。
php artisan make:migration create_table_表名稱
兩個方法:Up,Down.
UP方法:
schema::create('表名',function(Blueprint $table)
{
// $table->unsignedInteger('id')->autoIncrement();
$table->increments('id');
$table->string('school')->nullable();
$table->text('article')->nullable();
$table->string('user_name',12)->unique();
});
對應Down方法:
schema::drop('表名')
命令行執行Up方法內容
php artisan migrate
數據庫裡會自建一個migration表,主要是記錄回滾。
命令行回滾Down方法
php artisan migrate:rollback
測試創建表內容
php artisan migrate --pretend
以上執行中報錯級別在程序層面報錯。
閱讀更多 學點乾貨 的文章