• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 195

Backtrace:

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/views/question.php
Line: 195
Function: _error_handler

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/controllers/Questions.php
Line: 416
Function: view

File: /home/u125378470/domains/lawhelpguru.org/public_html/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

How handle CORS issue in laravel with reactjs with ports

<button aria-describedby="--stacks-s-tooltip-n8riruxn" aria-label="Bookmark" aria-pressed="false" class="js-bookmark-btn s-btn s-btn__unset c-pointer py4 js-gps-track" data-controller="s-tooltip" data-gps-track="post.click({ item: 1, priv: 0, post_type: 1 })" data-s-tooltip-placement="right" data-selected-classes="fc-yellow-600"></button><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" height="18" viewbox="0 0 19 18" width="19"></svg>

 

I am facing the CORS issue with api's from laravel to reactjs.

I am running laravel at 5555 port and reactjs is running on 3000.

I have a middleware to allow the origin of 'http://localhost:5555'. But it still gives me error.

My middleware is below.

`<?PHP

 namespace AppHttpMiddleware;

 use Closure;

 class HandleCors
 {
  /**
  * Handle an incoming request.
  *
  * @param  IlluminateHttpRequest  $request
  * @param  Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
    $allowedOrigins = ['http://localhost:5555'];
    $origin = $request->server('HTTP_ORIGIN');

    if (in_array($origin, $allowedOrigins)) {
        return $next($request)
            ->header('Access-Control-Allow-Credentials', 'true')
            ->header('Access-Control-Allow-Origin', $origin)
            ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
            ->header('Access-Control-Allow-Headers', 'Content-Type, Cache-Control'); //in case if you 
    want all (*)
    }

    return $next($request);
 }
 }`

This is the custom code I have not installed any package for CORS. How do solve this issue?