Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ghabriel25's avatar

ghabriel25 started a new conversation+100 XP

2d ago

Might be same content but one is free other is for subscribers?

Hi, @JeffreyWay. From the transcript, I find that these videos have same context (correct me if I'm wrong)

Is it intended to make it one free and one for subscribers only?

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

3d ago

verify mail

I think there was a video from Jeffrey about passwordless authentication

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

3d ago

Microsoft Clarity fragments sessions on every `wire:navigate` - has anyone solved this?

On the documentation

For optimal user tracking, the Identify API should be called for each page of the website.

However in Livewire, scripts in <head> only evaluated on initial load. Try use data-navigate-track attribute on your scripts or use data-spa="auto"

References:

ghabriel25's avatar

ghabriel25 was awarded Best Answer+1000 XP

5d ago

how to listen globally to livewire updating hook from AppServiceProvider.php in livewire 4

This

public function register()
{
    app('livewire')->componentHook(PropertySecurityHook::class);
}

I have been using custom class as component hook since L4 launch and it works as expected

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

6d ago

how to listen globally to livewire updating hook from AppServiceProvider.php in livewire 4

This

public function register()
{
    app('livewire')->componentHook(PropertySecurityHook::class);
}

I have been using custom class as component hook since L4 launch and it works as expected

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

6d ago

Laravel Excel package validation help request

Note that you're providing wrong field name. Its out_g not Green bean

$validator->errors()->add('out_g', ...);

Its the package itself that wrongly use strtok which returns string or false, but the Failure class constructor requires the row to be int (type hinted)

public function __construct(int $row, string $attribute, array $errors, array $values = [])
{
    $this->row       = $row;
    $this->attribute = $attribute;
    $this->errors    = $errors;
    $this->values    = $values;
}
} catch (IlluminateValidationException $e) {
    $failures = [];
    foreach ($e->errors() as $attribute => $messages) {
        $row = strtok($attribute, '.'); // return string or false
        $attributeName = strtok('');
        $attributeName = $attributes['*.' . $attributeName] ?? $attributeName;

        $failures[] = new Failure(
            $row, // this should be int
            $attributeName,
            str_replace($attribute, $attributeName, $messages),
            $rows[$row] ?? []
        );
    }

It will throw an error if its not numeric

function showAge(int $age) {
    echo $age;
}

showAge('12'); // output 12 or error if using declare(strict_types = 1);
showAge('abc'); // error
ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

6d ago

how to listen globally to livewire updating hook from AppServiceProvider.php in livewire 4

You can create dedicated class that extends Livewire\ComponentHook then register it inside service provider. Thats why Livewire provide a way to register custom hook.

Use these lifecycle hook inside your component hook class to implement what you're trying to do.

You can learn from livewire component hook itself, for example https://github.com/livewire/livewire/blob/main/src/Features/SupportLifecycleHooks/SupportLifecycleHooks.php

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

6d ago

how to listen globally to livewire updating hook from AppServiceProvider.php in livewire 4

The questions are

  • why would you need it inside service provider?
  • any context about what you're trying to achieve?

With those answered, I'm pretty sure someone can help you.

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

1w ago

I accidentally deleted a Controller. How to recover?

I learn the hard way so please use version control before your entire project accidentally deleted

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

1w ago

I accidentally deleted a Controller. How to recover?

If you're using vscode, there is timeline local history that can be used to retrieve lost file. This only if you're not clearing any temporary file in your OS

Image

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

1w ago

Database Replication

I really apologize for that.

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

1w ago

how to listen globally to livewire updating hook from AppServiceProvider.php in livewire 4

@imrandevbd There is no hook method in LivewireManager class https://github.com/livewire/livewire/blob/3.x/src%2FLivewireManager.php

Intercepting commit comes from javascript section https://livewire.laravel.com/docs/3.x/javascript#intercepting-commits

You really believe AI that much that you dont even bother to check its response.

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

1w ago

Database Replication

@eskiesirius Dont believe his reply without checking first. His reply mostly copy paste from AI generated.

There is no sticky option in Laravel database config https://github.com/laravel/framework/blob/13.x/config%2Fdatabase.php

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

1w ago

Fat service class

I manage to remove explicit method and reduce it from 320 lines to 190 lines using helper method.

One of service method becomes

public function deletePostActivities(Post $post): void
{
    // delete activity and notifications related to post
    tap($post, $this->deletePostNotifications(...))->activity()->delete();

    $queriesAndClasses = $this->getQueriesAndClasses([
        $post->bookmarks()->select('id'),
        $post->likes()->select('id'),
        $post->comments()->select('id'),
        $post->likesOnComments()->select('id'),
    ]);

    if ($queriesAndClasses !== []) {
        foreach ($queriesAndClasses as $queryAndClass) {
            $this->deleteActivitiesUsingClass(...$queryAndClass);
        }
    }
}
ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

1w ago

Fat service class

I think this is reasonable.

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

1w ago

Add meta to JSON:API resource relationships

@imrandevbd Please dont bring your AI generated answer here without checking first.

There is no Relation class inside Illuminate\Http\Resources\JsonApi https://github.com/laravel/framework/tree/13.x/src%2FIlluminate%2FHttp%2FResources%2FJsonApi

ghabriel25's avatar

ghabriel25 started a new conversation+100 XP

1w ago

Fat service class

Please give your honest review about my service class. This class only called from model observer, wrapped within database transaction and handle

  • creating and deleting user activities
  • deleting notifications related to activities
Model Type Softdelete
UserActivity Polymorphic ✔️
Notification Polymorphic

Trying to consolidate it with dedicated class but dont know where to start, which part should be refactor.

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

1w ago

Adding optional fields to user registration

Don't take your first step too high, if you're new to Laravel and Livewire I suggest learn from the basic. Here the videos that will help you understand how Laravel and Livewire works

I'd say, without understanding the basic you'll for sure having hard times debugging what wrong, why it doesn't work.

Some people choose to ask AI, sure it sometimes help you find the way to solve the problem but you're missing the important point where you are as developer should understand whats going on without relying AI to find the root cause.

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

2w ago

Toast question

Hi @rogermanich You can take trait + lifecyle hook approach like this

https://gist.github.com/ghabriel25/6f33b8f8d8ea7306681761267c1d9ea4

Note you can create dedicated livewire component for this and put it in your layout

// in your layout
<livewire:toast />
Route::post('/lab', function () {
    return back()
        ->with('flux:success',  'Record saved successfully!');
})->name('lab')->middleware('auth');

...

trait WithToast
{
    public function renderedWithToast(): void
    {
        // check if there are flash session
        // use Flux::toast to show it
        // specify variant based on session key
        // For example
        if (Session::has('flux:success')) {
            Flux::toast(text: Session::pull('flux:success'), variant: 'success');
        }
    }
}

then you can use this trait in your component. Also, you can create a trait specially for the toast session key, so that it becomes one source.

trait WithSessionKey
{
    public const string TOAST_SUCCESS = 'flux:success';
}

...

class LabController extends Controller
{
    use WithSessionKey;

    public function update()
    {
       ...

       return back()
           ->with(self::TOAST_SUCCESS,  'Record saved successfully!');
    }
}
ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

2w ago

I wanted to query nested data until level 2 on a single model

@skeith22 Is there a reason why you're using late static binding instead the real child class name?

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

2w ago

why wire wire-elements/livewire-strict package not working in livewire v4

@respect Looking at it's codebase, I think you should be able to create your own component hook which extends Livewire component hook especially update method and simply throw an exception if the property name that being updated was not locked.

Or you could post an issue there to support current Livewire 4

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

2w ago

How do we handle this repetition?

Just use #[CurrentUser] attribute as dependency injection, it will automatically resolve current authenticated user. For example

use App\Models\User;
use Illuminate\Container\Attributes\CurrentUser;

public function profile(#[CurrentUser] User $user)
{
    return view('pages.profile.index', [
        'user' => $user
    ]);
}

If its to show another user using route model binding, then just type hinting the User class

use App\Http\Controllers\UserController;
use App\Models\User;

// Route definition...
Route::get('/users/{user}', [UserController::class, 'show']);

// Controller method definition...
public function show(User $user)
{
    return view('user.profile', ['user' => $user]);
}

Lastly, I recommend watching https://laracasts.com/series/laravel-from-scratch-2026

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

2w ago

Querying DB

If each row is just an incrementing id, you can order by a group number in descending order, then by id ascending.

$completed = CompletedWeekend::query()
    ->orderByRaw('FLOOR((id - 1) / 4) DESC')
    ->orderBy('id')
    ->get();

The query groups every 4 records together using this logic:

FLOOR((id - 1) / 4) → This creates a "group number"

  • IDs 1–4 → Group 0
  • IDs 5–8 → Group 1
  • IDs 9–12 → Group 2
  • IDs 13–16→ Group 3
  • IDs 17–20→ Group 4 and so on...

Then it sorts by:

  1. Group number DESC (highest group first)
  2. id ASC inside each group (normal order)
ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

3w ago

At what point do you stop patching CSS and just rebuild properly?

If its me. I'll create one style (e.g button) and apply it per page and see which one should be treated difference. This takes some time and often too overhelming.

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

3w ago

At what point do you stop patching CSS and just rebuild properly?

I always using separate css file for each component such section, sidebar, button, card, header etc and use class based just like @tray2 mentioned. This way, I know where to patch if something break.

ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

3w ago

how to show delete confirmation and make request continmue

Hi, @respect Have you try this?

if (result.isDenied) {
	action.cancel()
}
ghabriel25's avatar

ghabriel25 wrote a reply+100 XP

3w ago

Laravel 13 with Livewire Starter Kit project

@parmanand741 Authentication was handled by fortify. You can open your config folder and see fortify.php then scroll to the very bottom.