Posts

Setting up laravel and filament

Samstag, 29. März 2025, 10:25 Uhr | roberto@vasquez-angel.de |

Install php:

> /bin/bash -c "$(curl -fsSL https://php.new/install/linux/8.4)"

Create a new laravel app:

> laravel new example-app

┌ Which starter kit would you like to install? ────────────────┐
│ Livewire                                                     │
└──────────────────────────────────────────────────────────────┘

┌ Which authentication provider do you prefer? ────────────────┐
│ Laravel's built-in authentication                            │
└──────────────────────────────────────────────────────────────┘

┌ Would you like to use Laravel Volt? ─────────────────────────┐
│ Yes                                                          │
└──────────────────────────────────────────────────────────────┘

┌ Which testing framework do you prefer? ──────────────────────┐
│ Pest                                                         │
└──────────────────────────────────────────────────────────────┘

┌ Would you like to run npm install and npm run build? ────────┐
│ Yes                                                          │
└──────────────────────────────────────────────────────────────┘

> cd example-app
> composer run dev

Add filament:

> composer require filament/filament:"^3.3" -W
> php artisan filament:install --panels

┌ What is the ID? ─────────────────────────────────────────────┐
│ admin                                                        │
└──────────────────────────────────────────────────────────────┘

Create a new user:

> php artisan make:filament-user

┌ Name ────────────────────────────────────────────────────────┐
│ admin                                                        │
└──────────────────────────────────────────────────────────────┘

┌ Email address ───────────────────────────────────────────────┐
│ rva@beegoodit.de                                             │
└──────────────────────────────────────────────────────────────┘

┌ Password ────────────────────────────────────────────────────┐
│ ••••••••                                                     │
└──────────────────────────────────────────────────────────────┘

INFO  Success! rva@beegoodit.de may now log in at http://localhost/admin/login.

Deploying:

  • add a Dockerfile
  • add a supervisord.conf
  • add nginx/laraval.conf

env vars:

APP_DEBUG=true
APP_ENV=production
APP_KEY=<create one with 'openssl rand -hex 16'>
APP_URL=<your-app-url>
DB_CONNECTION=mariadb
DB_URL=<your-db-url>

Setup the db and create your first user:

> php artisan migrate
> php artisan make:filament-user

Mark the user as verified:

> php artisan tinker
tinker> \App\Models\User::where('email', 'rva@beegoodit.de')->first()->markEmailAsVerified();

configure https to styles not loading:

# app/Providers/AppServiceProvider.php
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\URL;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        if (config('app.env') === 'production') {
            URL::forceScheme('https');
        }
    }
}

Configure access to the admin panel:

# app/Models/User.php
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;

class User extends Authenticatable implements FilamentUser
    /**
     * Authorize access to the Filament admin panel.
     */
    public function canAccessPanel(Panel $panel): bool
    {
        return str_ends_with($this->email, '@beegoodit.de') && $this->hasVerifiedEmail();
    }
}