• <b id="l3qpx"><abbr id="l3qpx"></abbr></b>
  • <th id="l3qpx"><progress id="l3qpx"></progress></th>
      <th id="l3qpx"></th>
      <dd id="l3qpx"><font id="l3qpx"></font></dd>
      <th id="l3qpx"></th>
      0712-2888027 189-8648-0214
      微信公眾號

      孝感風(fēng)信網(wǎng)絡(luò)科技有限公司微信公眾號

      當(dāng)前位置:主頁 > 技術(shù)支持 > PHP > fruitcake/laravel-cors 解決API跨域請求實現(xiàn)前后端分離

      fruitcake/laravel-cors 解決API跨域請求實現(xiàn)前后端分離

      時間:2021-11-16來源:風(fēng)信官網(wǎng) 點擊: 3436次

      在Laravel中開發(fā)API接口,經(jīng)常會遇到API跨域請求的問題,我們可以使用fruitcake/laravel-cors 擴展名解決API跨域請求,從而實現(xiàn)前后端分離。

      風(fēng)信建站專注技術(shù)開發(fā),提供PC網(wǎng)站、H5移動端、微信小程序、百度小程序、APP等多端應(yīng)用統(tǒng)一平臺管理解決方案,服務(wù)線熱:189-8648-0214(微信同號)

      安裝:composer require fruitcake/laravel-cors

      進行全局配置:

      打開app/Http/Kernel.php文件,在中間件$middleware中添加配置參數(shù)詳情如下:

      protected $middleware = [
      FruitcakeCorsHandleCors::class,
      // ...
      ];


      發(fā)布配置文件config/cors.php:

      php artisan vendor:publish --tag="cors"

      在路由屬性中添加:

      protected $routeMiddleware = [
      ...
      'cors' => FruitcakeCorsHandleCors::class,
      ]


      在服務(wù)providers中添加:

      'providers' => [
      ...
      FruitcakeCorsCorsServiceProvider::class,
      ]



      在路由中使用跨域請求中間件:

      Route::middleware('cors')->group(function (){
      Route::get('article', function(){
      return response()->json('跨域成功!',200);
      });
      });

      欄目列表
      推薦內(nèi)容
      熱點內(nèi)容
      展開
      欧美一区二区三区免费A级视频,亚洲精品中文字幕综合,动漫精品中文字幕无码第一页,1024亚洲国产综合 亚太影院 柯西贝尔-游戏赚网
    1. <b id="l3qpx"><abbr id="l3qpx"></abbr></b>
    2. <th id="l3qpx"><progress id="l3qpx"></progress></th>
        <th id="l3qpx"></th>
        <dd id="l3qpx"><font id="l3qpx"></font></dd>
        <th id="l3qpx"></th>