S.no | Contents-topics |
---|---|
1 | What are components |
2 | How to setup components |
3 | How to use components |
4 | Pass data to components |
Components are the one of the best feature that comes with laravel , components are define as the reusable peice of code that is being used in laravel blde fiile or we may say that laravel views. As the name defines components means to be a component of a page , for eg in a html file there are several different components like header , sidebar , footer and sometimes our header and footers are same but CSS and scripts file are different according to ech page so on that time we use component.
With an example , we inializing some scripts by using component as component are the piece of code , you may use components in the form of google analytics , some kind of loading scripts ,
Taking an HTML example from Deveoper-Corner , starting from the artisan command for footer as component
Copy for creating footerCopy
Inside resources/views/components/footer.blade.php you can see footer.blade.php has been created and also in app/View/Component/footer.php
That blade file reffers to views in blade and php file is used for binding up the objects and send them to the component in laravel you don't have to send data every time from backend. You have to just send data for the first time in app/View/Component/footer.php and then just inialiaze this component wherever you want.
Basic blade fiile code: Copy
As you can see in the footer of this html file component is used as <x-footer></x-footer> in blade file and resources/views/components/footer.blade.php contains the basic footer code like this script code.
Footer code: Copy
As shown {{$name}} variable is call from app/view/Component/footer.php to resources/views/components/footer.blade.php to binding up the variables
app/view/Component/footer.php.code: Copy
Basically we use this footer.php to binding up the objects and call them separately in component because by using thhis this you don;t need to call the same variable in each controller and then in view file So this the basic example of components in laravel ...
0 Comments (Please let us know your query)