PHP code example of audunru / dynamic-cors
1. Go to this page and download the library: Download audunru/dynamic-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/ */
audunru / dynamic-cors example snippets
config("cors.allowed_origins", ["https://www.example.com"]);
namespace App\Http\Middleware;
use Closure;
use audunru\DynamicCors\Middleware\HandleCors;
class UserCors extends HandleCors
{
public function handle($request, Closure $next)
{
$user = Auth::user();
$this->allowedOrigins = array_merge(
[config('app.url')],
$user->allowedOrigins // Note: allowedOrigins does not exist by default, it's something you would have to create. Or make something completely different
);
return parent::handle($request, $next);
}
}