Answer the question
In order to leave comments, you need to log in
How to inject loaded model into middleware?
Route:
Route::model('article', '\App\Article');
Route::get('articles/{article}', ['uses' => '[email protected]', 'middleware' => 'article.check']);
class ArticleCheck {
public function __construct(\App\Article $article)
{
dd($article->exists); // false
}
}
class ArticleCheck
{
public function __construct()
{
$this->article = \Route::current()->getParameter('article', new \App\Article);
}
}
Answer the question
In order to leave comments, you need to log in
I want to note that it can be downloaded post
<?php namespace App\Http\Middleware;
class AfterMiddleware implements Middleware {
public function handle($request, Closure $next)
{
$response = $next($request);
// Perform action
return $response;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question