我可以像这样使用 inertia 提供页面:
Route::inertia('/home', 'home');
要加载包含数据库数据的页面,我必须这样做:
Route::get('/terms', [LegalPageController::class, 'index']);
在控制器中:
class LegalPageController extends Controller
{
public function index()
{
$record = Terms::first();
return inertia('terms', compact('record'));
}
}
有什么办法可以将其缩短为:
Route::inertia('/home', 'home', [Controller::class, 'index']); Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你不能这样做
Route::inertia('/home', 'home', [Controller::class, 'index']);改用这个方法
#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'); }