// in root layout /layouts/app.blade.php
<livewire:notifications />
// two routes using standard Livewire components
Route::get('/goals', ListGoals::class);
Route::get('/goals/{goal}', ViewGoal::class);
// List Goals component and the create action look like
class ListGoals extends Component implements HasForms, HasActions
{
use InteractsWithActions;
use InteractsWithForms;
#[Computed]
public function goals(): Collection
{
return auth()->user()->goals;
}
public function createAction(): CreateAction
{
return CreateAction::make()
->model(Goal::class)
->form(GoalForm::schema())
->mutateFormDataUsing(function (array $data) {
$data['user_id'] = auth()->id();
return $data;
});
}
// ...
}
// in root layout /layouts/app.blade.php
<livewire:notifications />
// two routes using standard Livewire components
Route::get('/goals', ListGoals::class);
Route::get('/goals/{goal}', ViewGoal::class);
// List Goals component and the create action look like
class ListGoals extends Component implements HasForms, HasActions
{
use InteractsWithActions;
use InteractsWithForms;
#[Computed]
public function goals(): Collection
{
return auth()->user()->goals;
}
public function createAction(): CreateAction
{
return CreateAction::make()
->model(Goal::class)
->form(GoalForm::schema())
->mutateFormDataUsing(function (array $data) {
$data['user_id'] = auth()->id();
return $data;
});
}
// ...
}