RuiAlmeida
RuiAlmeida
FFilament
Created by RuiAlmeida on 9/16/2024 in #❓┊help
How to pass data to an EditAction
No description
10 replies
FFilament
Created by RuiAlmeida on 9/16/2024 in #❓┊help
How to pass data to an EditAction
<?php

namespace App\Livewire;
use....

class MenuComponent extends Component implements HasForms, HasActions
{
use InteractsWithForms;
use InteractsWithActions;

public $weeks;
public Week $week;

public ?ButteryMenu $butteryMenu;


public function mount($week = null): void
{

$this->week = $week ?? Week::where('menu_type', 'Buttery')->first();
$this->weeks = Week::where('menu_type', 'Buttery')->get();
$this->form->fill();
}

public function changeWeek($weekId)
{
$this->week = Week::find($weekId);
}

private array $sittingOrder = ['Breakfast', 'Brunch', 'Lunch', 'Dinner'];
private array $courseOrder = ['Starter', 'Mains', 'Sides', 'Dessert'];


public function editAction(): Action
{
return
Action::make('edit')
->fillForm(fn($livewire): array => [
....
'title' => $livewire->ownerRecord->title,

])
->form(ButteryMenuResource::getFormSchema())
->action(function (array $data, array $arguments): void {
$record = ButteryMenu::find($arguments['record']->id);
$record->update($data);
$this->dispatch('buttery-menu-saved');
});
}
public function createAction(): Action
{
return Action::make('create')...
}

public function getGroupedMenusProperty(): array
{
$menus = $this->week->butteryMenu;
return $this->groupAndSortMenus($menus)->all();
}

private function groupAndSortMenus(Collection $menus): Collection
{
return $menus->groupBy(......)->sortKeys();
}

public function render()
{
return view('livewire.menu-component')
->with('groupedMenus', $this->groupedMenus)
->with('weeks', $this->weeks)
->layout('menu');
}
}
<?php

namespace App\Livewire;
use....

class MenuComponent extends Component implements HasForms, HasActions
{
use InteractsWithForms;
use InteractsWithActions;

public $weeks;
public Week $week;

public ?ButteryMenu $butteryMenu;


public function mount($week = null): void
{

$this->week = $week ?? Week::where('menu_type', 'Buttery')->first();
$this->weeks = Week::where('menu_type', 'Buttery')->get();
$this->form->fill();
}

public function changeWeek($weekId)
{
$this->week = Week::find($weekId);
}

private array $sittingOrder = ['Breakfast', 'Brunch', 'Lunch', 'Dinner'];
private array $courseOrder = ['Starter', 'Mains', 'Sides', 'Dessert'];


public function editAction(): Action
{
return
Action::make('edit')
->fillForm(fn($livewire): array => [
....
'title' => $livewire->ownerRecord->title,

])
->form(ButteryMenuResource::getFormSchema())
->action(function (array $data, array $arguments): void {
$record = ButteryMenu::find($arguments['record']->id);
$record->update($data);
$this->dispatch('buttery-menu-saved');
});
}
public function createAction(): Action
{
return Action::make('create')...
}

public function getGroupedMenusProperty(): array
{
$menus = $this->week->butteryMenu;
return $this->groupAndSortMenus($menus)->all();
}

private function groupAndSortMenus(Collection $menus): Collection
{
return $menus->groupBy(......)->sortKeys();
}

public function render()
{
return view('livewire.menu-component')
->with('groupedMenus', $this->groupedMenus)
->with('weeks', $this->weeks)
->layout('menu');
}
}
10 replies
FFilament
Created by RuiAlmeida on 9/16/2024 in #❓┊help
How to pass data to an EditAction
Property [$ownerRecord] not found on component: [menu-component] Do you know somewhere it shows how to passs data from the compoenent to the form of that Modal? ;
10 replies
FFilament
Created by RuiAlmeida on 9/16/2024 in #❓┊help
How to pass data to an EditAction
It's complaining that the $record is null. is this the correct way to pass that to the action? {{ ($this->editAction)(['record' => $menu]) }} or is there any other way maybe with wire:click
10 replies
FFilament
Created by RuiAlmeida on 9/15/2024 in #❓┊help
Opening modal from Livewire Component
ohhh.... Perfect, thank you 🙂 Obrigado !
6 replies
FFilament
Created by RuiAlmeida on 9/15/2024 in #❓┊help
Opening modal from Livewire Component
Hi, thanks for the reply, yes I was using a normal Filament with the panel etc, but i was trying to show in a non-filament page one modal from a resource. But i guess we dont have the styles etc. Maybe the best approuach would be to create a custom page and a livewire compoenent?
6 replies