You need to call an embedded function in the livewire controller from the laravel web route handler.
Previously to call a function from the controllers laravel did it from the following way
Route::get('/name', 'NameController@NameFunction');
But now I need to call a function from a livewire controller and I can't figure out which is the right way.
I had the same problem, my class is called 'create.php', I hope this helps you:
I had the Livewire component in the Livewire folder inside another folder called Product, in your case it would just be Livewire\create:class
When you render a view with Livewire, the rendering of the view becomes stateful and becomes controlled by the component that called it
render
. The view can continue to interact with the component's class by invoking public methods that it makes available.If your controller was:
And the sight had in a place
Pressing the button would invoke the method
updateMessage
, without you having to trigger a request via ajax or fetch or process its response.Invoking this method will in turn update the public property
$message
, thereby refreshing the view segment.While both method invocation and content refreshing are handled internally with ajax calls, these are internal to Livewire and outside of your control.
The only traditional request the component gets to know about is the one it originally receives in the method
mount
, which would be analogous to what the method__construct
receives in a traditional Blade component.In laravel livewire routes lead to components . Then each component executes its method
render()
.For example, the route below
/post
leads to the called componentPosts
which will execute its methodrender
.post.php
Since the render method is executed, what you will get is that by going to the route you will
/post
be redirected to the called viewlivewire.show-posts
.After that, in said view you can call other methods within its component, such as the destroy method . You can read about it here .
At the moment the answer I see is to create a specific component for that route (= this solution seems bad to me because we would have hundreds of components doing a specific function although that may be its principle) Anyway, in my case I have an activity model, the which I manage with an administrator user, but with another participating user I want to enter it and perform a set of actions, it is clear that here the Model is the same but the actions are different, writing this it occurs to me to control access to parts of the views through the classic @if(Auth::user()->isAdmin) and thus I solve the issue of having more than one component pointed to the same Model, that is, you can play with global variables too.