I'm getting error when I wrap a resource route to my custom middleware
My middleware:
<?php
namespace App\Http\Middleware;
use Closure;
use Auth;
class Officer
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::check() && Auth::user()->role == 'title_officer') {
return $next($request);
}
// elseif (Auth::check() && Auth::user()->role == 'agent') {
// return redirect('/agent');
// }
// else {
// return redirect('/customer');
// }
}
}
The resource route using the middleware:
Route::resource('new-order', 'BackendController')->middleware('officer');
I'm getting error:
(Trying to get property 'headers' of non-object).
How to fix it ?