Componentの作成

Componentの作成:php artisan make:component コンポーネント

 

☆活用例

【app/View/Components/コンポーネント名.php
classコンポーネント extends Component
{
    public $○○;

    public function __construct($○○)
    {
        $this->○○ = $○○;
    }

【resources/views/components/コンポーネント名.blade.php
@if(isset($○○))
<div class="border px-4 py-3 rounded relative bg-green-100 border-green-400 text-green-700">
    {{$○○}}
</div>
@endif

【resources/views/post/create.blade.php
 <x-コンポーネント :message="session('○○')" />