以此記錄學習laravel的一些問題
問題:laravel轉移文件夾到另外一pc或者環境后訪問出現500
設置權限為777
問題: 設置路由后頁面總是404 not found
解決:需要在apache 配置文件里添加對laravel文件夾的訪問
<Directory "D:\WAMP\laravel\public"> Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit #此處必須為all none不行 AllowOverride All # # Controls who can get stuff from this server. # #Require all granted #Allow Order not supported Allow from all Require all granted </Directory>
問題:Laravel 5.1中Form組建不能安裝
解決辦法:
先在composer.json的require中加入"laravelcollective/html": "~5.1"
然后composer update
然后config/app.php中加入
providers部分
Collective\Html\HtmlServiceProvider::class,
aliases部分
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
問題: Laravel 5.1不能發郵件
解決:
1. 設置mail.php后刪除了evn(), evn表示讀取.evn的變量
用dd(Config::get('mail'));
2. 輸出配置來查看, 更新一次就要清一次cache
php artisan cache:clear
php artisan config:cache
3. 設置成ssl驗證
我的配置:
array:9 [▼ "driver" => "smtp" "host" => "smtp.163.com" "port" => 465 "from" => array:2 [▼ "address" => "EMAIL@163.com" "name" => "DC" ] "encryption" => "ssl" "username" => "EMAIL@163.com" "password" => "PASSWORD" "sendmail" => "/usr/sbin/sendmail -bs" "pretend" => false ]
發現最近自己解決問題時候總是太急, 結果忽視了應該注意到的地方, 比如輸出配置一直也沒好好看, 后來仔細看才發現username, password是空導致的問題...
"聰明人用笨辦法", 還真是, 更何況咱還不聰明...
有時候慢未必就會慢.
問題: 怎么手動清理配置緩存
解決: 命令行可以用php artisan config:cache
手動可以寫個路由, 然后
use Artisan;
public function clearConfigCache() {
Artisan::call('config:cache');
}
問題:Laravel安裝后訪問錯誤, 或訪問route后view失效,顯示了空白頁面
解決:
chgrp -R www-data /var/www/laravel //用戶組根據自己的來定義
chmod -R 775 /var/www/laravel/app/storage
外鍵約束字段必須是int 10 和 UNSIGNED 屬性
如果遇到各種莫名奇怪的問題, 清緩存先!!
問題:composer 不能安裝
with這條命令:
php -r "readfile('https://getcomposer.org/installer');" | php
先進入https://getcomposer.org/installer會下載到一個文件名為installer的文件
然后運行php -r "readfile('/www/xx/installer');" | php來讀取下載好的文件
然后會生成一個composer.phar的文件, 在此文件的目錄中運行:
php composer.phar
來執行composer相關命令, 如 php composer.phar update
如果php不在環境變量里, 則需要寫完整bin路徑/opt/php/bin php來替代php
ex:
/opt/lampp/bin/php artisan config:cache
問題:ajax請求時出現token missing錯誤
HTML中設置
<meta name="csrf-token" content="{{ csrf_token() }}" />
ajax代碼前設置
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
不錯的參考資料:
手冊: http://cheats.jesse-obrien.ca/
https://github.com/jp7internet/laravel-apz
https://github.com/yccphp/laravel-5-blog
http://9iphp.com/web/laravel
https://phphub.org/topics/804
http://segmentfault.com/a/1190000002505703#articleHeader6
https://phphub.org/topics/537
http://changziming.com/blog/post-167.html
權限解決方案Entrust http://www.poloo.org/?p=1057
http://ofcss.com/2015/03/13/laravel-5-custom-error-pages.html
里面有學習視頻link http://www.slideshare.net/shengyou/laravel-43453376