#Middleware auth + custom in Filament Blade

12 messages · Page 1 of 1 (latest)

shy estuary
#

can i ask something differnt? i have some page
/building/id
/my/transaction
/my/booking

btw, for now, i will stay on /admin/login as login page route

i want to make a middleware for check does user have change their default password? if not they will redirect ot reset-password page, if user already change their default password, they can acccess di page

{
    public function handle(Request $request, Closure $next)
    {
        $user = Auth::user();

        if ($user && $user->is_first == 1) {
            Password::sendResetLink(['email' => $user->email]);
            return redirect('/reset-password-send')->with('status', 'Silakan cek email Anda untuk reset password.');
        }

        return $next($request);
    }
}

how do i implement this middleware in filament, i also want to check if user already login or not, if they didnt login yet, the will redirected to login page

weak swallowBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

wet raptor
#

by adding it to the ->authMiddleware() in the panel provider

shy estuary
#

why in panel provider? even if i create a custom page with blade sir?

        <img src="{{ Storage::disk('s3')->url($building->image_url) }}" alt="{{ $building->name }}"
            class="w-full h-48 object-cover rounded-md">
        <header>
            <h2 class="text-xl font-bold text-gray-900 sm:text-3xl mt-3">
                {{ $building->name }} - Floors & Rooms
            </h2>
            <p class="mt-3 text-gray-500">{!! $building->getDescriptionHtml() !!}</p>
        </header>

        <div class="mt-6">
            <h2 class="text-lg font-semibold text-gray-900">Fasilitas:</h2>
            @if ($building->facilities->isEmpty())
                <p class="text-gray-500 italic">Maaf, Fasilitas gedung ini belum ditambahkan.</p>
            @else
                <ul class="mt-2 flex flex-wrap gap-2">
                    @foreach ($building->facilities as $facility)
                        <li
                            class="inline-flex items-center px-2 py-1 me-2 text-sm font-medium text-green-800 border-green-500 border-[1.25px] bg-green-100 rounded-lg">
                            {{ $facility->name }}
                        </li>
                    @endforeach
                </ul>
            @endif
        </div>```
#

i want to add middwware for building/show.blade.php sir

wet raptor
#

You are saying you want a middleware to check if the user needs to change their password. So if you add it to the auth middleware people will be checked if they need to change their password and redirect them accordingly.

#

If you have built a custom page like you say building you can add the middleware to that resource/page only too with the middleware property

shy estuary
#

sorry, i am new in laravel, is custom page with resource/page same with create view in laravel blade?

wet raptor
#

Yes and No. It is a Livewire Page, which has a blade. But much more powerful. Custom pages can be used just like a normal laravel blade but also with livewire.

#

On a Filament Page you should be able to declare:

#
protected static string | array $routeMiddleware = [UpdateUserActivity::class];
shy estuary
#

ohh i see, the context of my question is, what about if i using laravel blade for createing my page, how to add middlware like i want?