Add Uccello to a Laravel project
It is possible to add Uccello to an existing Laravel project (version >= 5.6).
Since Uccello has its own authentication interface, remember to backup the following files and readjust them if necessary:
resources/views/auth/login.blade.php
resources/views/auth/register.blade.php
resources/views/auth/passwords/email.blade.php
resources/views/auth/passwords/reset.blade.php
1. Install the Uccello library
You can install the uccello/uccello dependency with composer.
composer require uccello/uccelloIf you are using a version of Laravel lower than 5.5, you will need to add the following code in the config/app.php file:
'providers' => [
    ...
    /*
     * Package Service Providers...
     */
    Uccello\Core\Providers\AppServiceProvider::class,
    Uccello\Core\Providers\RouteServiceProvider::class,
    ...
],
...
'aliases' => [
    ...
    'Uccello' => Uccello\Core\Facades\Uccello::class,
],Then execute the following command to extract all the files necessary for Uccello to work properly:
For Laravel >= 6.*, it is necessary to install laravel/ui for adding auth management:
Laravel 6.x :composer require laravel/ui:1.*
Laravel 7.x :composer require laravel/ui:2.*
Laravel 8.x :composer require laravel/ui:3.*
php artisan make:auth # For Laravel < 6.x
php artisan ui:auth # For Laravel >= 6.x
php artisan uccello:install2. Add the middlewares
Open the file app/Http/Kernel.php and add the following code to add the middlewares used by Uccello :
protected $routeMiddleware = [
  ...
  'uccello.permissions' => \Uccello\Core\Http\Middleware\CheckPermissions::class,
  'uccello.settings' => \Uccello\Core\Http\Middleware\CheckSettingsPanel::class,
];3. Configure the routes
Add the following code to the routes/web.php file to automatically generate the route for to access Uccello.
...
Route::get('/uccello', function() {
    $domain = uccello()->useMultiDomains() ? uccello()->getLastOrDefaultDomain()->slug : null;
    $route = ucroute('uccello.home', $domain);
    return redirect($route);
});This automatically detects whether the notion of multi domains is used or not and redirects the user to the last domain he visited.
4. Configure the environment
Once the project is created you can configure the .env file as explained in Laravel's official documentation.
APP_URL=http://localhost:8000
...
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=uccello
DB_USERNAME=homestead
DB_PASSWORD=secretThis is an example. Put your own data into the .env file.
If you do not want to use the notion of multi domains, you can add the following line into the .env file:
...
UCCELLO_MULTI_DOMAINS=false5. Execute migrations
Once the database is configured, it is now possible to execute migrations to create the database structure used by Uccello.
php artisan migrate6. Create an user
To easily create a new user, execute the following command:
php artisan uccello:user7. Activate connection log
You can see last connections of a user in his detail page. To activate this functionality edit the file located at app/Http/Controllers/Auth/LoginController.php and the following code:
use Carbon\Carbon;
use Uccello\Core\Models\Connection;
class LoginController extends Controller
{
  // ...
  
  /**
    * The user has been authenticated.
    *
    * @param  \Illuminate\Http\Request  $request
    * @param  mixed  $user
    * @return mixed
    */
    protected function authenticated(Request $request, $user)
    {
        Connection::create([
            'user_id' => $user->id,
            'datetime' => Carbon::now(),
        ]);
    }
}8. It's ready!
If you would like to use PHP's built-in development server to serve your application, this command will start a local development server:
php artisan serveNow you can go to the home page of your site: http://localhost:8000. Once redirected to the login page, you can authenticate yourself with the credentials created at the step 6.
Last updated
Was this helpful?