visit
php artisan make:component Alert
The above command will do two things create a view template for the component on also create a file on Where I wrote my wishlist HTML in the blade file and some PHP code in the PHP file.Once your component has been generated, it may be rendered using its
name:<x-alert/>
.We can also pass variables in the component via attributes that are prefixed with :
<x-alert :message="$message"/>
You have to define the component’s required data in its class constructor (In Provided PHP FILE). All public properties on a component will automatically be made available to the component’s view. It is not necessary to pass the data to the view from the component’s render method. But if you use the component in a loop, then you have to pass data in the render method as well see below.And in the component’s blade file, we can access variables using blade expression.{{$message}}.
Well, that's mostly it. I can reuse
<x-alert/>
anywhere on my views also if I start a new project, I can just copy my components and use them that way.I am still looking for a way that I can store them, say, on a package management system then hit a command that will generate all my saved components. Maybe even choose the ones that I want at that particular time. Know of such a solution? Please let me know in the comments section.Before you go… Thanks for reading the article! If you enjoyed it, please don’t forget to show your appreciation by clicking 👏 below!
If you have any questions or comments, contact me:Mail: Twitter: github: