【laravel】开发过程中会遇到的问题
文章目錄
- 訪問器中循環使用 curl 請求第三方API ,導致ajax 響應狀態為 canceled
- 1. The page has expired due to inactivity. Please refresh and try again.
- 2. Not well formed numeric value encountered 【 laravel 5.5 升級到5.7】
- 3. The payload is invalid
- 4.[Laravel 定時任務](https://lvwenhan.com/laravel-advanced/481.html)
- 5. [laravel Task Scheduling(任務調度)在windows下的使用](https://blog.csdn.net/forlightway/article/details/77943539)
- 6. [Laravel 開發實踐建議](https://segmentfault.com/a/1190000017877953)
- 7. 處理Guzzle異常并獲取HTTP正文
- 8. 重定向問題
- MySQL
- 1. 使用groupBy 進行分組
- 2. 每月的訂單數目
- 3. 查看sql語句
訪問器中循環使用 curl 請求第三方API ,導致ajax 響應狀態為 canceled
原因: 循環請求curl時長太長了解決辦法: 設置 ajax timeout 時間1. The page has expired due to inactivity. Please refresh and try again.
一是,設置的session domain 與 訪問地址要一致
參考鏈接:https://laracasts.com/discuss/channels/laravel/the-page-has-expired-due-to-inactivity-please-refresh-and-try-again
設置session domain 為 null,路由不需要中間件
二是,如果設置了session_domain ,那么路由必須使用中間件,否則將會登錄失敗,一直跳轉到登錄頁面
Route::group(['middleware' => 'auth:web', ], function ($router) {# 進入到主頁面$router->get('/home', 'HomeController@index')->name('home'); });2. Not well formed numeric value encountered 【 laravel 5.5 升級到5.7】
https://laracasts.com/discuss/channels/general-discussion/dd-not-well-formed-numeric-value-encountered?page=1
https://symfony.com/doc/current/components/var_dumper.html
3. The payload is invalid
使用postman調試接口時,報錯,因為 X-XSRF-TOKEN 值錯誤
4.Laravel 定時任務
5. laravel Task Scheduling(任務調度)在windows下的使用
6. Laravel 開發實踐建議
7. 處理Guzzle異常并獲取HTTP正文
Guzzle 6.x 每 文檔,您可能需要捕獲的異常類型是:GuzzleHttp\Exception\ClientException 對于400級錯誤 GuzzleHttp\Exception\ServerException 500級錯誤 GuzzleHttp\Exception\BadResponseException 對于兩者(這是他們的超類) 因此處理此類錯誤的代碼現在看起來像這樣:$client = new GuzzleHttp\Client; try {$client->get('http://google.com/nosuchpage'); } catch (GuzzleHttp\Exception\ClientException $e) {$response = $e->getResponse();$responseBodyAsString = $response->getBody()->getContents(); }8. 重定向問題
情景:
用戶沒有登錄,則在訪問 / 跳轉到登錄頁面(視圖 login.blade.php 文件)
目前知道有三種設置方法:
{return view(auth.login); }
在提交post請求 ,會返回 請求方式不允許的錯誤
{return redirect->route('login'); }
在 IPv6 訪問 會響應一個無限重定向頁面,但是在IPv4上沒有問題
其中,1 和 2 方法使用的是Laravel 默認的 Auth::route();
3. routes/web.php
Route::get('/', '\App\Http\Controllers\Auth\LoginController@showLoginForm');
login.blade.php action='/login'
MySQL
1. 使用groupBy 進行分組
// 假設model名是News;status啟用是1;language選擇cn;type: sale,test $data = News::select(array('id', 'title', 'type'))->where('status', '1')->where('language', 'cn')->orderBy('id')->get()->groupBy('type')->toArray(); // 可按type分組返回結果:
參考鏈接
遇到問題:
Laravel : Syntax error or access violation: 1055 Error
解決方案
2. 每月的訂單數目
Order::select('channel_id',DB::raw("sum(case when month(sendtime)=1 then 1 else 0 end) as 一月,sum(case when month(sendtime)=2 then 1 else 0 end) as 二月,sum(case when month(sendtime)=3 then 1 else 0 end) as 三月,sum(case when month(sendtime)=4 then 1 else 0 end) as 四月,sum(case when month(sendtime)=5 then 1 else 0 end) as 五月,sum(case when month(sendtime)=6 then 1 else 0 end) as 六月,sum(case when month(sendtime)=7 then 1 else 0 end) as 七月,sum(case when month(sendtime)=8 then 1 else 0 end) as 八月,sum(case when month(sendtime)=9 then 1 else 0 end) as 九月,sum(case when month(sendtime)=10 then 1 else 0 end) as 十月,sum(case when month(sendtime)=11 then 1 else 0 end) as 十一月,sum(case when month(sendtime)=12 then 1 else 0 end) as 十二月"))->withOnly('channel', ['username', 'companyname'])->SearchByFlag(Order::ORDER_STATUS_CONFIRM)->SearchByDemandType(Demands::DEMANDS_TYPE_SALE)->whereYear('sendtime', '2019')->groupBy('channel_id')->get();3. 查看sql語句
DB::listen(function($slq){ var_dump($sql->sql); }); 《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的【laravel】开发过程中会遇到的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【grafana】API 遇到的问题
- 下一篇: 【laravel】docker 部署la