Level 104
Not a use case for middleware IMO. Middleware is intended to decorate requests and responses as they enter and leave your app respectively. It should be separate from your application logic.
Is it possible to add Authenticate Middleware in constructor of PHP class but not Controller?
Example:
namespace App\Http\Services;
class SomeService {
protected $token;
public function __construct() {
$this->middleware(function ($request, $next) {
$this->token = \Auth::user()->profile->token;
return $next($request);
}
}
public function some_function(){
return $this->token;
}
}
Please or to participate in this conversation.