Skip to content
Advertisement

Laravel LiveWire 2 : Do we have to make a new class or we can do like traditional Controller

So, it’s my first LiveWire learning Project.

Just to the point, I’m making a Livewire Component called User using php artisan make:livewire user

and then this is what I got

First User.php

JavaScript

And so, I want to make a create user at different pages. NOTES: Ive already use turbolinks for the SPA, and when I create like the traditional Laravel Controller like

Web.php

JavaScript

User.php (livewire component)

JavaScript

It doesn’t give me the parent templates (It doesn’t run into layouts.app and go to contents, it just show blank pages), I’ve tried to extends it with layouts.app and the section

layouts/app.blade.php

JavaScript

My question:

can we do like standart laravel controller with public function create inside user component OR we have to make a new component called UserCreate? Thanks!

Advertisement

Answer

You can handle this by different ways, depend of you. One can be have an UserForm component to handle the create/edit forms, and in User’s create component call to render the UserForm component to create new one.

JavaScript

in web.php

JavaScript

and UserForm component

JavaScript

instead use redirect you can use modals and render UserForm inside a modal you have in User component. As I told you, this can be do it by different ways

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement