1,創建用戶表
php artisan make:migration create_user_table --create=user
更新表的操作( 相當於在 原有的字段上 追加新的字段 ):
php artisan make:migration update_temp_phone --create=temp_phone
創建位置在database/migration/
-----> 創建用戶信息表
php artisan make:migration create_user_info_table --create=user_info
php artisan make:migration create_topic_table --create=topic
php artisan make:migration create_role_table --create=roles
php artisan make:migration create_carousel_figure_table --create=carousel_figures
執行遷移--> php artisan migrate
再在數據庫添加測試的數據
2,創建表的模型
php artisan make:model Models\\User
php artisan make:model Models\\Admin\\Weibo
php artisan make:model Models\\Admin\\Comment
php artisan make:model Models\\UserInfo
創建位置在app/Models
3,創建用戶發表文章的表
php artisan make:migration create_user_article_table --create=articles
執行遷移--> php artisan migrate
php artisan make:model Models\\Article
4,多對多
php artisan make:migration create_role_table --create=roles
php artisan make:migration create_role_user_table --create=role_user
執行遷移--> php artisan migrate
php artisan make:model Models\\Role
5,遠層一對多
php artisan make:migration create_country_table --create=countries
執行遷移--> php artisan migrate
php artisan make:model Models\\Country
6,多態關聯
php artisan make:migration create_video_table --create=videos
執行遷移--> php artisan migrate
php artisan make:model Models\\Video
php artisan make:migration create_comment_table --create=comments
執行遷移--> php artisan migrate
App\\Models\\Video
App\\Models\\Article
php artisan make:model Models\\Comment
二,laravel中.env丟失後的做法
.env丟失後的做法:
1,複製 .env.example
2,將 .env.example 重命名為.env ==> 【 cp .env.example .env 】 注意路徑
3, cd 到安裝laravel的根目錄
E:\\wamp\\www\\framework\\Composer>cd mylaravel
4,輸入 【 php artisan key:generate 】 來生成鑰匙
E:\\wamp\\www\\framework\\Composer\\mylaravel> php artisan key:generate
Application key [base64:wLF6uuvRoxrhi2UPjh+mYMAaPnwg0PvoyqeNZhEzNrM=] set successfully.
這時生成了key,可以了
三,在laravel中以域名的方式訪問 ( wamp web+apache+mysql+php集成環境 )
1,配置Apche中的httpd.conf:
通過Windows+R vhosts 來查找Include前是否有#(默認沒有) :
www.page.dev
如果有,改為下面的:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
2,找到載入的虛擬主機的配置文件
E:\\wamp\\bin\\apache\\apache2.4.18\\conf\\extra 下的httpd.vhosts.conf
將
<virtualhost>
ServerName localhost
DocumentRoot E:/wamp/www
<directory>
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
複製一份
更改 :
ServerName後的 localhost為域名
DocumentRoot與Directory 後的地址為laravel的地址:
E:/wamp/www/framework/Composer/mylaravel/public
3,通過 記事本 管理員權限來 打開 C:\\Windows\\System32\\drivers\\etc\\hosts
複製一行# 127.0.0.1 localhost去掉#
將localhost改為你要的域名與wamp中的一致:
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 www.my_laraval.com
再重啟wamp
最後在瀏覽器中驗證,出現laravel的界面就成功了
四,laravel安裝方法
1,在PhpStorm中使用 Terminal:
composer create-project laravel/laravel mylaravel 5.5.*
mylaravel ==》 本地目錄(名字隨便)
5.5.* 或者 5.5 ==》 是版本號
2,在Windows中使用cmd安裝中國鏡像/https://pkg.phpcomposer.com/:
( 為了安裝 composer ,國外的資源加載比較慢 )
composer config -g repo.packagist composer https://packagist.phpcomposer.com
閱讀更多 輕鬆學PHP 的文章