Laravel - Blade Templates - Applying The Layout Component

Once the layout component has been defined, we may create a Blade view that utilizes the component. In this example, we will define a simple view that displays our task list:

    
    
    
    
        @foreach ($tasks as $task)
            {{ $task }}
        @endforeach
    
	

Remember, content that is injected into a component will be supplied to the default $slot variable within our layout component. As you may have noticed, our layout also respects a $title slot if one is provided; otherwise, a default title is shown. We may inject a custom title from our task list view using the standard slot syntax discussed in the component documentation:

    
    
    
    
        
            Custom Title
        
    
        @foreach ($tasks as $task)
            {{ $task }}
        @endforeach
    
	

Now that we have defined our layout and task list views, we just need to return the task view from a route:

    
    use App\Models\Task;
    
    Route::get('/tasks', function () {
        return view('tasks', ['tasks' => Task::all()]);
    });