0

i have tried cors middleware and similiar laravel packages its , but cant access outside url , some body can give good solution

kernel.php

\App\Http\Middleware\Cors::class,

Cors Middlware

public function handle($request, Closure $next)


{
    header("Access-Control-Allow-Origin: *");
    //ALLOW OPTIONS METHOD
    $headers = [
        'Access-Control-Allow-Methods' => 'POST,GET,OPTIONS,PUT,DELETE',
        'Access-Control-Allow-Headers' => 'Content-Type, X-Auth-Token, Origin, Authorization',
    ];
    if ($request->getMethod() == "OPTIONS"){
        //The client-side application can set only headers allowed in Access-Control-Allow-Headers
        return response()->json('OK',200,$headers);
    }
    $response = $next($request);
    foreach ($headers as $key => $value) {
        $response->header($key, $value);
    }
    return $response;

}
  • How and where are you implementing this middleware? – Salim Sep 24 '19 at 12:59
  • Possible duplicate of [Laravel 5.1 API Enable Cors](https://stackoverflow.com/questions/33076705/laravel-5-1-api-enable-cors) – Salim Sep 24 '19 at 13:00
  • the url you shared i followed , in the last hes saying route , but why should i make route however i am accessing url which is api url , why i need route then – engr muzamil khoso Sep 24 '19 at 13:12
  • Are both domains under your control? Which one did you put the CORS headers on? – ceejayoz Sep 24 '19 at 13:13
  • yes both domains are my under control , domain is same but playing on subdomains like a.mydomain.com to b.mydomain.com i have installed cors on a.mydomain because i am hitting b.mydomain – engr muzamil khoso Sep 24 '19 at 13:19
  • If you're hitting `b.mydomain` from `a.mydomain`, you need the CORS headers on `b.mydomain`, not `a.mydomain`. – ceejayoz Sep 24 '19 at 13:49
  • i have tried its not working , add headers to method and controller same error happpens – engr muzamil khoso Sep 25 '19 at 10:13

0 Answers0