我使用的是Laravel 8,我已经安装了InertiaJS,但是在目录resources/views/中,我有一个名为index.blade.php的文件,我计划在InertiaJS中使用该文件。
默认情况下,InertiaJS在该目录中查找名为app.blade.php的文件。我知道写以下声明:
\Inertia\Inertia::setRootView('index');
更改rootView并允许我使用我创建的文件。这似乎是个愚蠢的问题,但据我所见,我可以做两件事。
index.blade.php重命名为app.blade.phpServiceProviders中我想知道以下几点:
InertiaJS-Laravel不允许使用命令php artisan vendor:publish发布ServiceProvider?(此命令的输出没有显示任何有关此包的发布信息)ServiceProvider,比如:php artisan make:provider InertiaServiceProvider,然后注册它?ServiceProvider中?就像在app/Http/Providers/RouteServiceProvider.php你有什么更好的建议?
我想在我的项目中寻求尽可能大的组织。谢谢你提前..。
发布于 2020-09-20 19:43:01
发布于 2021-01-16 18:37:12
更严格地说,只需像这样覆盖App\Http\Middleware\HandleInertiaRequests中的App\Http\Middleware\HandleInertiaRequests方法.
public function rootView(Request $request)
{
if ($request->route()->getPrefix() == 'admin') {
return 'layout.admin';
}
return parent::rootView($request);
}发布于 2020-12-26 09:16:18
你可以在你的控制器内飞行。
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Inertia\Inertia;
class NewsController extends Controller
{
public function index()
{
Inertia::setRootView('layouts.news');
$users = User::all();
return Inertia::render('News/Index', compact('users'));
}
}https://stackoverflow.com/questions/63926485
复制相似问题