Answer the question
In order to leave comments, you need to log in
How to update the database before the controllers start working?
When entering, let's say, any page, I need to check the database for overdue tasks and, if there are any, update some fields. You need to do this before you start running controllers and displaying views. I tried to use middleware, but then a problem popped up: a variable was taken from my GET request
function index(Skill $skill)
{
...
}
Answer the question
In order to leave comments, you need to log in
Try to create your own service provider that will be responsible for checking tasks and updating fields, register it before RouteServiceProvider. Then the updates would have to happen before getting the model for the controller.
in Controller make a constructor
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function __construct()
{
$this->middleware(function ($request, $next) {
return $next($request);
});
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question