My laravel version : 5.2
I want to override tymondesigns/jwt-auth GetUserFromToken.php
\vendor\tymon\jwt-auth\src\Middleware\GetUserFromToken.php
class GetUserFromToken extends BaseMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, \Closure $next)
{
if (! $token = $this->auth->setRequest($request)->getToken()) {
return $this->respond('tymon.jwt.absent', 'token_not_provided', 400);
}
For example, I want to return a custom message when token is not provided.
if (! $token = $this->auth->setRequest($request)->getToken()) {
return my_custom_message;
}
since I cannot make changes directly on this file, how should I create a custom class to override vendor's GetUserFromToken.php ?
Please describe required steps in detail if possible. Thanks.
update#2
Kernel.php
protected $routeMiddleware = [
'jwt.auth' => \App\Http\override\MyGetUserFromToken::class,
I created GetUserFromToken.php in below directory. myProject\app\Http\override\MyGetUserFromToken.php
<?php
namespace App\Services\Middleware;
use Tymon\JWTAuth\Middleware\GetUserFromToken;
class MyGetUserFromToken extends GetUserFromToken
{
public function handle($request, \Closure $next)
{
if (! $token = $this->auth->setRequest($request)->getToken()) {
return my_custom_message;
}
via ethan17