Livewire Route Binding: No Need for Laravel Controller
HTML-код
- Опубликовано: 5 янв 2021
- The traditional way to use the Livewire component is to include it inside of a Blade View. But what if you can bypass all the Laravel Controller/View and add a route directly to Livewire Component? Let me show you how.
- - - - -
Try our Laravel QuickAdminPanel: bit.ly/quickadminpanel
Enroll in my Laravel courses: laraveldaily.teachable.com Хобби
Livewire is the best thing that happened to Laravel - and thanks for your new IDE Theme! Looooooks way much better!
This is so nice and elegant. I hoped this existed, but did not know how. Thanks Povilas. Great to the point content again in just 4 minutes.
I love your channel, I don't miss any video. You are doing an amazing job!
Thank you! I'm new to laravel and livewire and I was struggling to understand this.. now I see it's very simple.
Thanks, your video is more helpful than Livewire official screencasts and docs
Just what I was looking for, direct and functional, thanks
perfect explaination exactly when I needed it, thanks
This was awesome man, thank you!
It's simple and usefull 👌👌
Please continue making livewire short videos and make cool and pro things like filters, sorts, likebuttons, many-step forms, cache and more 👍🌹
Well, a lot of that will be covered in my upcoming livewirekit.com :) But yes, a lot is planned on the channel, too.
Thank you so much , do we have any way to save livewire component name in database and load it in blade template from database ?
Thx.
Hello sir, please upload an video of upload any size file by chunking in laravel.
How to create separate routes like laravel in livewire and how to manage large number of fields with many textarea in livewire
Hi, thank for this video, can you please show us how to do SPA without turbolinks in livewire. I know we can use some kind of variables by which we can do if else to show different components, but is there any better way to do it, like jumping from home page to about us page and so one without page refreshes?
Personally, I wouldn't create a full SPA with Livewire, that is not its purpose.
@@PovilasKorop Thank you sir! I got your point.
Hi Povilas, what if I want to make conditional the binding data in route like yours example Route::get('post/{post?}')...How handle that in the component mount() method?
From the official docs:
Route::get('/post/{id}', ShowPost::class);
class ShowPost extends Component
{
public $post;
public function mount($id)
{
$this->post = Post::find($id);
}
...
}
So probably conditional would work the same way, try it out, try mount($id = null) or something.
Read more: laravel-livewire.com/docs/2.x/rendering-components#page-components
please help :
when we ask no one helps and now i have a problem, so please help me
i want to show posts of specific category when click on it :
this is my function in button with name of category and its work well :
{{ $post->category->name }}
but what to do in in this function ( categoryposts )
public function categoryposts ()
{
}
and the render function too:
public function render()
{
}
How about Livewire 3?
I have tried but the form submit refreshed.
Awesome.Livewire should be the default way of writing Laravel apps if you are not making SPA
and a question that: How I can show posts that their category_id is as this post
i tried this but got error:
public Post $post;
$posts = Post::with('categories')->where('category_id', $this->post->categories()->id)->get();
public function render()
{
$posts = Post::with('categories')->where('category_id', $this->post)->get();
return view('livewire.post.bycategory', compact('posts'))->layout('layouts.app');
}
2:39 love it, only thing that annoys me is intelephense throwing errors (looks like your is as well).
So i`ve been struggling for around 2 weeks on ``how to emit real time notification between users when A follow B`` .. can u make a tutorial about tihs?
Real-time notifications are about much more than just Livewire. It's like a live-chat, using something like Laravel Echo and/or Socket.io/Pusher. So read the docs for those technologies, also you may read an article from my colleague: modestasv.com/chat-with-laravel-pusher-and-socket-io-at-your-command/
could you please make example livewire with google maps
for example in form make a marker for city or country and bind the lat and lng values to livewire componet and make update and store operation for that model
Haven't done it myself, and it would be tricky to bind Livewire back-end with JavaScript lat/lng values. But adding to the to-do list, will try.
What do we do if we have Route:resource() model binding?
You can't do it for Route::resource(), from what I know.
It's useful thank you btw can you do page loading gif with livewire ?
What do you mean by "page loading gif"? You mean showing some kind of loading indicator while loading? Then you should put somewhere: laravel-livewire.com/docs/2.x/loading-states
@@PovilasKorop yeah i mean like full screen loading overlay when i refresh the page or go to another page. i did saw that documentation i can do that in some particular element but i still don't have any idea how to do that on entire page without clicking anything sorry for my bad english
can i use livewire route with name
Yes
@@LaravelDaily thank you
I usually use mine this way by grouping
```Route::group(['namespace' => '\App\Http\Livewire\Posts'], function () {
Route::get('posts/{post}', Show::class);
});```
This is default Livewire functionality, why would you create a controller then a livewire component to include in the controller?. Livewire doesnt add any overhead when using it the same way as a controller
Caleb post on twitter says that he didnt even use one controller for over a year, just create a livewire component and that will be your "controller" with crud and everything else, no need for controllers anymore unless in very limited cases, thats how i develop my apps, and my routes file was severely reduced un number of lines when using livewire.
In fact , using controllers and then mixing/including small livewire components is really a mess, can't imagine building a so heavily fragmented app that way, looking all over the place.
Yes, and no. Yes, if you use full-page Livewire components and your whole page is dynamic, then you're right. But my personal belief is that Livewire is great for small dynamic elements of the page, so the components should be almost like @include whenever needed.
@@PovilasKorop full page components do not cause any overhead, for very small apps they can be included, also a page doesnt need to be dynamic at all, its just about consistency throughout the application, as soon as there is more logic and features , including these components become a mess all over the place for apps like CRMs , CMSes, anything bigger than a contact form
@@Tux0xFF I would say it's a personal preference of whatever you're comfortable with. A good example is Jetstream - the app is fully Laravel, and only some form elements are with Livewire for a better UX.
Livewire is not defined
Does anyone knows how to make streaming music and make download restriction for all types of user using laravel? Please give me some ideas on this topic. Thanks in advance.
Hello, please consider buying external microphone. Since you switched to Macbook, your videos contains background sound from fans. Your videos are great, but this makes them a little less enjoyable. Thanks
It's so ironic, that when I switched from Macbook 2015 to the latest and greatest Macbook Pro 2020, with the idea that it will be faster to render videos and will help me to work with videos, now it's actually WORSE than the old one, and now I'm forced to spend couple hundred more for an external microphone, and also $50 on the adapter from Thunderbolt to USB. But I guess I have no choice.
Very nice 😍💋 💝💖♥️❤️