How to call Controller using Route::inertia() facade?
P粉344355715
P粉344355715 2024-03-28 10:41:42
0
1
574

I can serve the page using inertia like this:

Route::inertia('/home', 'home');

To load a page containing database data I have to do this:

Route::get('/terms', [LegalPageController::class, 'index']);

In controller:

class LegalPageController extends Controller
{
    public function index()
    {
        $record = Terms::first();

        return inertia('terms', compact('record'));
    }
}

Is there any way to shorten it to:

Route::inertia('/home', 'home', [Controller::class, 'index']);

P粉344355715
P粉344355715

reply all(1)
P粉293341969

You can’t do this

Route::inertia('/home', 'home', [Controller::class, 'index']);

Use this method instead

#routes/web.php
Route::get('home', [Controller::class, 'index']);


#App\Http\COntrollers\Controller.php
namespace App\Http\Controllers

class Controller extends Controller {
    # ...
   Inertia::render('home');
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template