禁止全局csrf認(rèn)證
在app/Http/Kernel.php中,$middleware表示全局中間件,而$routeMiddleware表示針對(duì)某個(gè)路由的中間件,所以只需要把csrf在$middleware中注釋掉,然后在$routeMiddleware中添加'csrf' => 'App\Http\Middleware\VerifyCsrfToken'
如果要在某個(gè)路由上使用就這樣:
Route::group(['middleware' => 'csrf'], function(){ // csrf保護(hù)的接口
Route::get('/', 'HomeController@index');
}
處理上傳文件
$file = Input::file('upload_file");// 獲取上傳文件對(duì)象
$file->isValid() // 檢驗(yàn)文件是否有效
$file->getClientOriginalName(); // 獲取文件原名
$file->getFileName(); // 獲取上傳后緩存的文件的名字
$file->getRealPath(); // 獲取緩存文件的絕對(duì)路徑
$file->getClientOriginalExtension();// 獲取上傳文件的后綴
$file->getMimeType(); // 獲取上傳文件的MIME類型
$file->getSize(); // 獲取上傳文件的大小
手動(dòng)清理配置緩存
插入數(shù)據(jù)的時(shí)候出現(xiàn)MassAssignmentException in Laravel錯(cuò)誤
需要給數(shù)據(jù)表設(shè)置可訪問的字段,在Model里面
protected $fillable = array('字段1', '字段2');
php artisan db:seed出現(xiàn)[ReflectionException] Claxx XXXTableSeeder dows not exist錯(cuò)誤
這是因?yàn)樾略黾恿宋募莄omposer沒有感知到,需要先執(zhí)行composer dump-autoload
定義/修改字段類型為timestamp時(shí)出現(xiàn)錯(cuò)誤:”Unknown column type “timestamp” requested.”
按照[How do I make doctrine support timestamp columns?]的做法,目前最簡(jiǎn)單的方式是直接用DB::statement()來寫SQL語(yǔ)句
POST數(shù)據(jù)的時(shí)候出現(xiàn)The payload is invalid
我遇到這個(gè)情況是因?yàn)樵谧鰪?fù)雜的表單提交,直接提取X-XSRF-TOKEN的值,但是由于沒有轉(zhuǎn)移,導(dǎo)致后端token揭秘失敗
保存model的時(shí)候出現(xiàn)錯(cuò)誤:Missing argument 2 for Illuminate\Database\Eloquent\Model::setAttribute()
一般是Model的幾個(gè)屬性沒有設(shè)正確,檢查這幾個(gè)值incrementing/timestamps/primarykey/fillable
隊(duì)列出現(xiàn)Cannot initialize a MULTI/EXEC transaction over aggregate connections
升級(jí)到最新版laravel吧,然后將redis的擴(kuò)展切換到phpredis,laravel5.3之前自帶的predis不支持redis的sentinel,并且有些redis操作強(qiáng)依賴于predis的事務(wù)操作,各種糾結(jié),最后都不能成功?;蛘咦约簩戭愃频闹虚g件
Class ‘Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory' not found
偶爾安裝了某些個(gè)第三方庫(kù)會(huì)出現(xiàn)這種幺蛾子,可以用這種方式解決composer require symfony/psr-http-message-bridge
更新表時(shí)出現(xiàn)AH00052: child pid 71 exit signal Segmentation fault (11)
原因可能是沒有設(shè)置主鍵而直接在該表上面更新數(shù)據(jù),導(dǎo)致ORM不知道到底該更新誰。并且Laravel不支持復(fù)合主鍵(https://github.com/laravel/framework/issues/5517,作者不支持這種做法)。這種情況,要么給該表添加唯一主鍵,要么只能用where直接更新了。
Error while reading line from server
Predis需要設(shè)置read_write_timeout=0或者-1,特別是daemon任務(wù),最好設(shè)置不超時(shí)
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class log does not exist' in /Users/freek/dev/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php
出現(xiàn)于5.2版本中,原因是.env文件中的配置的值,中間存在空格,如果中間有空格,需要將值用雙引號(hào)包起來
Class env does not exist / Class request does not exist
通常出現(xiàn)在框架還未加載完成就報(bào)錯(cuò),但是在處理錯(cuò)誤的時(shí)候卻使用了env()/request()這個(gè)功能,導(dǎo)致沒有打印真實(shí)的錯(cuò)誤。處理方式,一是不要使用app()->environment('...'),而是檢查.env文件中是否有錯(cuò)誤,例如包含空格的值,必須用雙引號(hào)包圍。我在自定義ExceptionHandler中遇到過幾次
The given data failed to pass validation
認(rèn)證出錯(cuò)卻不知道具體錯(cuò)在哪里并且狀態(tài)碼是500,如果有用Dingo API,那么注意Request不要繼承use Illuminate\Foundation\Http\FormRequest而應(yīng)該是use Dingo\Api\Http\FormRequest
Call to undefined method setHidden
注意command的主邏輯不是fire而應(yīng)該是handle
啟動(dòng)時(shí)報(bào)錯(cuò)Unknown: failed to open stream: No such file or directory in Unknown on line 0
可能是錯(cuò)誤地刪除了server.php文件,可以直接自己寫一個(gè):
/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell taylor@laravel.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
composer install時(shí)報(bào)錯(cuò): Please provide a valid cache path
需要手動(dòng)創(chuàng)建緩存目錄,在storage/framwork下面新建sessions、views、cache文件夾即可
總結(jié)
到此這篇關(guān)于Laravel相關(guān)的一些故障解決的文章就介紹到這了,更多相關(guān)Laravel故障解決內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- Laravel統(tǒng)一錯(cuò)誤處理為JSON的方法介紹
- composer安裝的方法步驟(圖文)
- Laravel 解決composer相關(guān)操作提示php相關(guān)異常的問題
- laravel 實(shí)現(xiàn)向公共模板中傳值 (view composer)
- 淺談laravel 5.6 安裝 windows上使用composer的安裝過程
- Laravel快速入門之composer介紹及安裝詳細(xì)圖文步驟