PHP code example of elevationdigital / laravel-cors

1. Go to this page and download the library: Download elevationdigital/laravel-cors library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

elevationdigital / laravel-cors example snippets


protected $middleware = [
    // ...
    \Fruitcake\Cors\HandleCors::class,
];
 
'paths' => ['api/*'],



return [

    /*
     * You can enable CORS for 1 or multiple paths.
     * Example: ['api/*']
     */
    'paths' => [],

    /*
    * Matches the request method. `[*]` allows all methods.
    */
    'allowed_methods' => ['*'],

    /*
     * Matches the request origin. `[*]` allows all origins.
     */
    'allowed_origins' => ['*'],

    /*
     * Matches the request origin with, similar to `Request::is()`
     */
    'allowed_origins_patterns' => [],

    /*
     * Sets the Access-Control-Allow-Headers response header. `[*]` allows all headers.
     */
    'allowed_headers' => ['*'],

    /*
     * Sets the Access-Control-Expose-Headers response header.
     */
    'exposed_headers' => false,

    /*
     * Sets the Access-Control-Max-Age response header.
     */
    'max_age' => false,

    /*
     * Sets the Access-Control-Allow-Credentials header.
     */
    'supports_credentials' => false,
];


$app->register(\Fruitcake\Cors\CorsServiceProvider::class);

$app->middleware([
    // ...
    \Fruitcake\Cors\HandleCors::class,
]);

protected $except = [
    'api/*'
];
sh
php artisan vendor:publish --tag="cors"