Repository: https://github.com/codewithdary/components-in-laravel-9
Documentation: https://laravel.com/docs/10.x/blade#components
Source: /g/xampp8/htdocs/laravel/ForTesting_Purposes/laravel-for-testing - Branch = layout
Readme instruction in the github repo.$ php artisan model:show [TABLE NAME]
Create Blade Component$ php artisan make:component Header
Created:
app/view/Components/Header.php
resources/views/components/header.blade.php
Add HTML to new component
Open header.blade.php:code resources/views/components/header.blade.php
Add: <div>hello from header.blade.php</div>
Call Component
Open welcome.blade.php and call the header blate template:code resources/views/welcome.blade.php
Add: <x-header />
Passing Data to Component
Open Header.phpcode app/view/Components/Header.php
Add $title:
Open welcome.blade.php to pass the value to title:code resources/views/welcome.blade.php
Change To:
Open header.blade.php:code resources/views/components/header.blade.php
Change To:
$ php artisan make:component Blog/BlogItem
$ code App/View/Components/Blog/BlogItem.php
This creates a Folder in App/View/Components/Blog/BlogItem.php
https://youtu.be/7E76PPoIVW4?si=1rthfNRfaIl8zIWb&t=679
ADD:BlogItem.php
Blog Blade Template
code resources/views/components/blog/blog-item.blade.php
code resources/views/welcome.blade.php
open in browser: /welcome
components inside components
create a new component Tag/TagItem
Add TagItem to BlogItem
<x-tag.tag-item :tag="$tag->name" />
https://youtu.be/7E76PPoIVW4?si=ncG3r72fOCAOivi8&t=886
https://youtu.be/7E76PPoIVW4?t=906&si=f9FwC41YntwcSopI
Laravel creates a slot variabled which you can use in your components, all you need to do is add the html inside the component tags.
welcome.php
header.blade.php
In this example, we will pass an additional class property to the component:
welcome.php
header.blade.php
Inspect CSS:
<h1 class="underliner text-danger">Page Title</h1>
https://youtu.be/7E76PPoIVW4?si=jc4U_A57kBvrpudf&t=1451
$ php artisan make:component Forms/PrimaryButton
welcome.blade.php
primary-button.blade.php
$ touch resources/views/components/forms/text-input.blade.php
welcome.blade.php
text-input.blade.php
Textarea InLine Component
The --inline option only creates a component class and does not create a view component
$ php artisan make:component Forms/Textarea --inline
$ code app/view/Components/Forms/Textarea.php
welcome.blade.php
app/view/Component/Forms/textarea.php
Done