#What is The Best way (Pattern) to create a Feature In livewire

6 messages · Page 1 of 1 (latest)

deft dagger
#

Hi I am create a feature in live wire but i don't want to use a single component for the because i will make the component really big and complex to work with

feature i need (Simplified)

i have program where the teacher can do the follow

Change Period (would change the program and all of its student)
Change a Student show the student specific stuff like hi grade his activity and module etc
you can have a lot of other action for teacher it an customized LMS

now i am using a component base approach where i have component for each action but there is some repeated code for example

when you change the student i fired and event studentChanged and the code in the most of the lisiner is same
which is get the user its activiy
also in mount method are the same to cause i need access to current program module etc

is that ok or can i avoid that if so can some one tell me how cause i dont know

vapid nacelle
deft dagger
#

@vapid nacelle
i am not the familiar with laravel action but i think
laravel action package for laravel i dont think you can use is for livewire
and when i said i fire event i meant livewire event not laravel

can you can laravel event in livewire and if you that how can i dont that

//fire event for livewire
$this->emit('studentChange' , $student)

//listiner in livewire component
protected $listeners = [
       'studentChanged',
    ];
public function studentChanged(User $student): void
{
    $this->student = $student;
    $this->getActivity($student);
}
vapid nacelle
#

Sry, I'm too beginner to know that :x Theorically, laravel Actions are just php classes that you can use everywhere, like you put a __invoke function in it that returns what you need, I don't test yet if this work when we call it with livewire, but I don't really see why It'll not

#

I don't know about listerners

deft dagger
#

ok i will check it thnx