<tr id="frcqn"></tr>
<strong id="frcqn"><optgroup id="frcqn"></optgroup></strong>
<tr id="frcqn"></tr>
<tr id="frcqn"></tr>
<tr id="frcqn"></tr>
  • 0712-2888027 189-8648-0214
    微信公眾號

    孝感風信網絡科技有限公司微信公眾號

    當前位置:主頁 > 技術支持 > PHP > fruitcake/laravel-cors 解決API跨域請求實現前后端分離

    fruitcake/laravel-cors 解決API跨域請求實現前后端分離

    時間:2023-11-04來源:風信官網 點擊: 2348次

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

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

    安裝:composer require fruitcake/laravel-cors

    進行全局配置:

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

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


    發布配置文件config/cors.php:

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

    在路由屬性中添加:

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


    在服務providers中添加:

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



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

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

    欄目列表
    推薦內容
    熱點內容
    展開
    强奸乱伦之影音先锋,播放器男女免费,精品一区二区自拍偷拍,xxxxx日韩
    <tr id="frcqn"></tr>
    <strong id="frcqn"><optgroup id="frcqn"></optgroup></strong>
    <tr id="frcqn"></tr>
    <tr id="frcqn"></tr>
    <tr id="frcqn"></tr>