【发布时间】:2021-05-21 08:41:00
【问题描述】:
我正在使用 Laravel 8 和 Jetstream(惯性堆栈)。
我想通过视图作曲家将数据传递给我的 Inertia 组件。
我该怎么做?
我什至试过这个但不起作用:
View::composer('*', ProfileComposer::class);
如果您想了解更多信息,请点击此处:
<?php
namespace App\Providers;
use App\Http\View\Composers\ProfileComposer;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class ViewServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
View::composer('*', ProfileComposer::class);
}
}
这里还有另一部分:
<?php
namespace App\Http\View\Composers;
use App\Models\Center;
use App\Models\Field;
use Illuminate\View\View;
class ProfileComposer
{
/**
* Bind data to the view.
*
* @param \Illuminate\View\View $view
* @return void
*/
public function compose(View $view)
{
$view->with('centers', Center::all('id', 'name'))
->with('fields', Field::all('id', 'name'));
}
}
【问题讨论】:
标签: laravel laravel-8 inertiajs