If you suggest using a controller, yes it makes sense.
Route::get('/', [MyController::class, 'index'])->name('index');
class MyController
{
public function index()
{
$data = // from some query
return view('pages.my-page.index', compact('data'));
}
}
If you need to retrieve the same data from different places in your code, you can export the query into a service.
class DataService
{
public function getData()
{
$data = // from some query
return $data;
}
}
And use the service in the controller, in Volt, ...
class MyController
{
public $dataService;
public function __construct()
{
$this->dataService = new DataService;
}
public function index()
{
$data = $this->dataService->getData();
return view('pages.my-page.index', compact('data'));
}
}