日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【laravel】开发过程中会遇到的问题

發(fā)布時(shí)間:2025/3/20 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【laravel】开发过程中会遇到的问题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

      • 訪問器中循環(huán)使用 curl 請(qǐng)求第三方API ,導(dǎo)致ajax 響應(yīng)狀態(tài)為 canceled
      • 1. The page has expired due to inactivity. Please refresh and try again.
      • 2. Not well formed numeric value encountered 【 laravel 5.5 升級(jí)到5.7】
      • 3. The payload is invalid
      • 4.[Laravel 定時(shí)任務(wù)](https://lvwenhan.com/laravel-advanced/481.html)
      • 5. [laravel Task Scheduling(任務(wù)調(diào)度)在windows下的使用](https://blog.csdn.net/forlightway/article/details/77943539)
      • 6. [Laravel 開發(fā)實(shí)踐建議](https://segmentfault.com/a/1190000017877953)
      • 7. 處理Guzzle異常并獲取HTTP正文
      • 8. 重定向問題
  • MySQL
    • 1. 使用groupBy 進(jìn)行分組
      • 2. 每月的訂單數(shù)目
      • 3. 查看sql語句

訪問器中循環(huán)使用 curl 請(qǐng)求第三方API ,導(dǎo)致ajax 響應(yīng)狀態(tài)為 canceled

原因: 循環(huán)請(qǐng)求curl時(shí)長太長了解決辦法: 設(shè)置 ajax timeout 時(shí)間

1. The page has expired due to inactivity. Please refresh and try again.

一是,設(shè)置的session domain 與 訪問地址要一致
參考鏈接:https://laracasts.com/discuss/channels/laravel/the-page-has-expired-due-to-inactivity-please-refresh-and-try-again
設(shè)置session domain 為 null,路由不需要中間件

# 進(jìn)入到主頁面Route::get('/home', 'HomeController@index')->name('home');

二是,如果設(shè)置了session_domain ,那么路由必須使用中間件,否則將會(huì)登錄失敗,一直跳轉(zhuǎn)到登錄頁面

Route::group(['middleware' => 'auth:web', ], function ($router) {# 進(jìn)入到主頁面$router->get('/home', 'HomeController@index')->name('home'); });

2. Not well formed numeric value encountered 【 laravel 5.5 升級(jí)到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調(diào)試接口時(shí),報(bào)錯(cuò),因?yàn)?X-XSRF-TOKEN 值錯(cuò)誤

4.Laravel 定時(shí)任務(wù)

5. laravel Task Scheduling(任務(wù)調(diào)度)在windows下的使用

6. Laravel 開發(fā)實(shí)踐建議

7. 處理Guzzle異常并獲取HTTP正文

Guzzle 6.x 每 文檔,您可能需要捕獲的異常類型是:GuzzleHttp\Exception\ClientException 對(duì)于400級(jí)錯(cuò)誤 GuzzleHttp\Exception\ServerException 500級(jí)錯(cuò)誤 GuzzleHttp\Exception\BadResponseException 對(duì)于兩者(這是他們的超類) 因此處理此類錯(cuò)誤的代碼現(xiàn)在看起來像這樣:$client = new GuzzleHttp\Client; try {$client->get('http://google.com/nosuchpage'); } catch (GuzzleHttp\Exception\ClientException $e) {$response = $e->getResponse();$responseBodyAsString = $response->getBody()->getContents(); }

8. 重定向問題

情景:
用戶沒有登錄,則在訪問 / 跳轉(zhuǎn)到登錄頁面(視圖 login.blade.php 文件)
目前知道有三種設(shè)置方法:

  • Controller
    {return view(auth.login); }
    在提交post請(qǐng)求 ,會(huì)返回 請(qǐng)求方式不允許的錯(cuò)誤
  • Controller
    {return redirect->route('login'); }
    在 IPv6 訪問 會(huì)響應(yīng)一個(gè)無限重定向頁面,但是在IPv4上沒有問題
  • 其中,1 和 2 方法使用的是Laravel 默認(rèn)的 Auth::route();
    3. routes/web.php
    Route::get('/', '\App\Http\Controllers\Auth\LoginController@showLoginForm');
    login.blade.php action='/login'

    MySQL

    1. 使用groupBy 進(jìn)行分組

    // 假設(shè)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分組

    返回結(jié)果:

    參考鏈接
    遇到問題:
    Laravel : Syntax error or access violation: 1055 Error
    解決方案

    2. 每月的訂單數(shù)目

    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); }); 《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

    總結(jié)

    以上是生活随笔為你收集整理的【laravel】开发过程中会遇到的问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。