skip to Main Content
<?php

namespace AppHttpMiddleware;

use AppPengurus;
use Closure;
use Response;

class ApiAuth
{
    /**
     * Handle an incoming request.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        header('Access-Control-Allow-Origin: *');

        $token = $request->header('APP_KEY');
        $validateToken = Pengurus::where('token',$token)->first();

        if(!$validateToken){
            return Response::json(['message'=>'Anda Belum Login, Silahkan Login Terlebih Dahulu'],401);
        }

        return $next($request);
    }
}

———————————————————

how to fix it?
in localhost it’s works, but when i try in cpanel it’s doesn’t work.

2

Answers


  1. Hy I have got the solution
    remove _ for your key and bingo
    like, replace APP_KEY with APPKEY and bingo.
    Welcome in advance

    Login or Signup to reply.
  2. The latest version of PHP does not allow _ in the header please use

    $token = $request->header('APP-KEY')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search