ghabriel25 started a new conversation+100 XP
2d ago
Hi, @JeffreyWay. From the transcript, I find that these videos have same context (correct me if I'm wrong)
- https://laracasts.com/series/laravel-authentication-techniques/episodes/1
- https://laracasts.com/series/jeffreys-larabits/episodes/32
Is it intended to make it one free and one for subscribers only?
ghabriel25 wrote a reply+100 XP
3d ago
I think there was a video from Jeffrey about passwordless authentication
ghabriel25 wrote a reply+100 XP
3d ago
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 was awarded Best Answer+1000 XP
5d ago
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 wrote a reply+100 XP
6d ago
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 wrote a reply+100 XP
6d ago
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 wrote a reply+100 XP
6d ago
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 wrote a reply+100 XP
6d ago
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 wrote a reply+100 XP
1w ago
I learn the hard way so please use version control before your entire project accidentally deleted
ghabriel25 wrote a reply+100 XP
1w ago
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

ghabriel25 wrote a reply+100 XP
1w ago
I really apologize for that.
ghabriel25 wrote a reply+100 XP
1w ago
@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 wrote a reply+100 XP
1w ago
@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 wrote a reply+100 XP
1w ago
I manage to remove explicit method and reduce it from 320 lines to 190 lines using helper method.
private function getQueriesAndClasses(array $queries = []): array
{
if ($queries === []) {
return $queries;
}
$queriesAndClasses = [];
foreach ($queries as $query) {
if ($query instanceof Builder || $query instanceof Relation) {
$queriesAndClasses[] = [$query, $this->getClassUsing($query)];
}
}
return $queriesAndClasses;
}
private function getClassUsing(Builder|Relation $query): string
{
// Query builder: $query->getModel()
// Eloquent relation: $query->getRelated()
$method = $query instanceof Relation ? 'getRelated' : 'getModel';
$class = $query->{$method}()::class;
if (! class_exists($class)) {
throw new RuntimeException('Could not find the class related to the activity');
}
return $class;
}
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 wrote a reply+100 XP
1w ago
I think this is reasonable.
ghabriel25 wrote a reply+100 XP
1w ago
@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 started a new conversation+100 XP
1w ago
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.
class ActivityService
{
/**
* Gets the points to reach the max level.
*/
private function pointsToMaxLevel(int $userId, int $activityPoints): int
{
$userPoints = (int) UserActivity::query()
->withTrashed()
->where('user_id', $userId)
->sum('reward');
$remaining = max(0, Level::MAX_POINTS - $userPoints);
return min($activityPoints, $remaining);
}
/**
* Create post activity.
*/
public function createPostActivity(Post $post): void
{
$points = $this->pointsToMaxLevel($post->user_id, Level::POST_POINTS);
$post->activity()->createQuietly([
'user_id' => $post->user_id,
'type' => UserActivity::CREATE_POST,
'reward' => $points,
]);
}
/**
* Create comment activity.
*/
public function createCommentActivity(Comment $comment): void
{
$points = $this->pointsToMaxLevel($comment->user_id, Level::COMMENT_POINTS);
$comment->activity()->createQuietly([
'user_id' => $comment->user_id,
'type' => UserActivity::COMMENT_POST,
'reward' => $points,
]);
}
/**
* Create or update like post activity.
*/
public function createLikePostActivity(PostLike $like): void
{
$this->toggleActivity($like, UserActivity::LIKE_POST, Level::LIKE_POINTS);
}
/**
* Create or update like comment activity.
*/
public function createLikeCommentActivity(CommentLike $like): void
{
$this->toggleActivity($like, UserActivity::LIKE_COMMENT, Level::LIKE_POINTS);
}
/**
* Create or update bookmark activity.
*/
public function createBookmarkActivity(Bookmark $bookmark): void
{
$this->toggleActivity($bookmark, UserActivity::BOOKMARK_POST, Level::BOOKMARK_POINTS);
}
/**
* Create or update toggleable activity.
*/
private function toggleActivity(ToggleableActivity $action, string $type, int $point): void
{
$points = $this->pointsToMaxLevel($action->user_id, $point);
UserActivity::withoutEvents(fn () => $action->activity()
->withTrashed()
->updateOrCreate(
[
'user_id' => $action->user_id,
],
[
'type' => $type,
'reward' => $points,
'deleted_at' => null,
'created_at' => now(),
'updated_at' => now(),
]
));
}
/**
* Deletes all activities associated with a post.
*/
public function deletePostActivities(Post $post): void
{
// delete activity and notifications related to post
tap($post, $this->deletePostNotifications(...))->activity()->delete();
// delete bookmark activities related to post
$this->deleteBookmarkActivitiesUsing(
$post->bookmarks()->select('id')
);
// delete like activities related to post
$this->deleteLikePostActivitiesUsing(
$post->likes()->select('id')
);
// delete comment activities related to post
$this->deleteCommentActivitiesUsing(
$post->comments()->select('id')
);
// delete like activities related to post's comments
$this->deleteLikeCommentActivitiesUsing(
$post->likesOnComments()->select('id')
);
}
/**
* Deletes all activities associated with comment(s).
*/
public function deleteCommentActivities(Comment $comment): void
{
// delete activities and notifications related to comment
tap($comment, $this->deleteCommentNotifications(...))->activity()->delete();
// delete like activities related to comment
$this->deleteLikeCommentActivitiesUsing(
$comment->likes()->select('id')
);
// delete reply activities related to comment
$this->deleteCommentActivitiesUsing(
$comment->replies()->select('id')
);
// delete like activities and notifications related to comment's replies
$likesOnRepliesQuery = $comment->likesOnReplies()->select('id');
$this->deleteLikeCommentActivitiesUsing($likesOnRepliesQuery);
$this->deleteLikeCommentNotificationsUsing($likesOnRepliesQuery);
}
/**
* Deletes all activities associated with post like(s).
*/
public function deleteLikePostActivity(PostLike $like): void
{
tap($like, $this->deleteLikePostNotification(...))->activity()->delete();
}
/**
* Deletes all activities associated with comment like(s).
*/
public function deleteLikeCommentActivity(CommentLike $like): void
{
tap($like, $this->deleteLikeCommentNotification(...))->activity()->delete();
}
/**
* Deletes all activities associated with a user.
*/
public function deleteUserActivities(User $user): void
{
// delete user's notifications while deleting notifications related to user.
tap($user, $this->deleteUserNotifications(...))->notifications()->delete();
// delete notifications related to user's posts
$this->deletePostNotificationsUsing(
$user->posts()->select('id')
);
// delete like activities related to user's posts
$this->deleteLikePostActivitiesUsing(
$user->likesOnPosts()->select('id')
);
// delete bookmark activities related to user's posts
$this->deleteBookmarkActivitiesUsing(
$user->bookmarksOnPosts()->select('id')
);
// delete activities related to comments on user's posts
$this->deleteCommentActivitiesUsing(
$user->commentsOnPosts()->select('id')
);
// delete like activities related to comments on user's posts
$this->deleteLikeCommentActivitiesUsing(
$user->likesOnPostComments()->select('id')
);
// delete like activities related to user's comments
$this->deleteLikeCommentActivitiesUsing(
$user->likesOnComments()->select('id')
);
// delete activities related to user's mentions
$this->deleteCommentActivitiesUsing(
$user->mentions()->select('id')
);
// delete like activities related to user's mentions
$this->deleteLikeCommentActivitiesUsing(
$user->likesOnMentions()->select('id')
);
// delete activities and notifications related to replies on user's comments
$repliesOnCommentsQuery = $user->repliesOnComments()->select('id');
$this->deleteCommentActivitiesUsing($repliesOnCommentsQuery);
$this->deleteCommentNotificationsUsing($repliesOnCommentsQuery);
// delete like activities related to replies on user's comments
$this->deleteLikeCommentActivitiesUsing(
$user->likesOnReplies()->select('id')
);
}
/**
* Deletes all activities associated with comment(s) using subquery.
*/
private function deleteCommentActivitiesUsing(Builder $query): void
{
$this->deleteActivitiesUsingClass($query, Comment::class);
}
/**
* Deletes all activities associated with post like(s) using subquery.
*/
private function deleteLikePostActivitiesUsing(Builder $query): void
{
$this->deleteActivitiesUsingClass($query, PostLike::class);
}
/**
* Deletes all activities associated with comment like(s) using subquery.
*/
private function deleteLikeCommentActivitiesUsing(Builder $query): void
{
$this->deleteActivitiesUsingClass($query, CommentLike::class);
}
/**
* Deletes all activities associated with bookmark(s) using subquery.
*/
private function deleteBookmarkActivitiesUsing(Builder $query): void
{
$this->deleteActivitiesUsingClass($query, Bookmark::class);
}
/**
* Delete post notifications.
*/
private function deletePostNotifications(Post $post): void
{
$this->deleteNotificationsUsingKey($post->id, Notification::KEY_POST);
}
/**
* Delete post notifications using subquery.
*/
private function deletePostNotificationsUsing(Builder $query): void
{
$this->deleteNotificationsUsingKey($query, Notification::KEY_POST);
}
/**
* Delete comment notifications.
*/
private function deleteCommentNotifications(Comment $comment): void
{
$this->deleteNotificationsUsingKey($comment->id, Notification::KEY_COMMENT);
$this->deleteNotificationsUsingKey($comment->id, Notification::KEY_REPLY);
}
/**
* Delete comment notifications using subquery.
*/
private function deleteCommentNotificationsUsing(Builder $query): void
{
$this->deleteNotificationsUsingKey($query, Notification::KEY_COMMENT);
$this->deleteNotificationsUsingKey($query, Notification::KEY_REPLY);
}
/**
* Delete like post notifications.
*/
private function deleteLikePostNotification(PostLike $like): void
{
$this->deleteNotificationsUsingKey($like->id, Notification::KEY_POST_LIKE);
}
/**
* Delete like comment notifications.
*/
private function deleteLikeCommentNotification(CommentLike $like): void
{
$this->deleteNotificationsUsingKey($like->id, Notification::KEY_COMMENT_LIKE);
}
/**
* Delete like comment notifications using subquery.
*/
private function deleteLikeCommentNotificationsUsing(Builder $query): void
{
$this->deleteNotificationsUsingKey($query, Notification::KEY_COMMENT_LIKE);
}
/**
* Delete user notifications.
*/
private function deleteUserNotifications(User $user): void
{
$this->deleteNotificationsUsingKey($user->id, Notification::KEY_USER);
$this->deleteNotificationsUsingKey($user->id, Notification::KEY_MENTION);
}
/**
* Deletes all activities associated with a model using subquery.
*/
private function deleteActivitiesUsingClass(Builder $query, string $class): void
{
UserActivity::query()
->whereMorphedTo('subject', $class)
->whereIn('subject_id', $query)
->delete();
}
/**
* Deletes all notifications associated with a key.
*/
private function deleteNotificationsUsingKey(Builder|int $value, string $key): void
{
$method = $value instanceof Builder ? 'whereIn' : 'where';
Notification::query()
->{$method}("data->$key", $value)
->delete();
}
}
ghabriel25 wrote a reply+100 XP
1w ago
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
- Laravel From Scratch (2026 Edition)
- Mastering Permissions in Laravel
- Livewire Uncovered
- Livewire 3 From Scratch
- Everything New in Livewire 4
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 wrote a reply+100 XP
2w ago
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 wrote a reply+100 XP
2w ago
@skeith22 Is there a reason why you're using late static binding instead the real child class name?
ghabriel25 wrote a reply+100 XP
2w ago
@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 wrote a reply+100 XP
2w ago
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 wrote a reply+100 XP
2w ago
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:
- Group number DESC (highest group first)
- id ASC inside each group (normal order)
ghabriel25 wrote a reply+100 XP
3w ago
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 wrote a reply+100 XP
3w ago
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 wrote a reply+100 XP
3w ago
Hi, @respect Have you try this?
if (result.isDenied) {
action.cancel()
}
ghabriel25 wrote a reply+100 XP
3w ago
@parmanand741 Authentication was handled by fortify. You can open your config folder and see fortify.php then scroll to the very bottom.