Install Folio in Breezed Laravel App

Latarips
Latarips

Laravel Folio is a package that simplifies routing in Laravel applications. It is based on the concept of pages, which are Blade files containing all the logic for the page. Folio also includes support for Livewire, enabling the creation of reactive user interfaces without the need for JavaScript.

In this tip, we will see how to install Folio within a Laravel application that already uses Breeze.

composer require laravel/folio

Now, by way of example, we are going to convert the file located in ./resources/views/dashboard.blade.php to resources/views/pages/dashboard.blade.php

Once this is done, we can delete the route created by Breeze from the file ./routes/web.php

/** Remove this lines */
Route::view('dashboard', 'dashboard')
    ->middleware(['auth', 'verified'])
    ->name('dashboard');

Then, we modify the resources/views/pages/dashboard.blade.php page to the following.

<?php

use function Laravel\Folio\name;
use function Laravel\Folio\{middleware};
 
name('dashboard');
middleware(['auth', 'verified']);

?>

<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
            {{ __('Dashboard') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 text-gray-900 dark:text-gray-100">
                    {{ __("You're logged in!") }}
                </div>
            </div>
        </div>
    </div>
</x-app-layout>

Now, we can clear the route cache.

php artisan route:cache

We can check the routes managed by Folio using the following command:

php artisan folio:list

Output:

command propmt image

Yes, I like cats… 😺

With these simple steps, you can already get an idea of the power and simplicity that this official Laravel package gives us.

dashboard result

#breeze #Folio