98 questions
Best practices
0 votes
1 replies
33 views
Ignore parent Model Scope in a Child model
I have two models with global scopes. #[ScopedBy(UserScope::class)] class User {} #[ScopedBy(ViewerScope::class)] class Viewer extends User {} The scope just checks if class instance has is_viewer ==...
2 votes
2 answers
177 views
How to handle eloquent.deleted Event for all Models right?
I want to run an action after any model got deleted, but currently it seems like I do something wrong.. I already get the Model before I delete it, so the event should get fired. As I do already some ...
0 votes
1 answer
61 views
How to get the last entry of a Laravel model which is not NULL on a certain column (Laravel 11)
I would like to get back within a with() the last entry of a modal which is not null on a certain column. I know that it is possible to simply get the last entry with the following function in the ...
2 votes
1 answer
1k views
Implementing One-to-Many Relationship in Laravel Eloquent
I'm working on a Laravel project and I'm trying to set up a one-to-many relationship between two models How can I create a new user and associate multiple posts with that user using Eloquent? How do ...
0 votes
1 answer
82 views
Should i write migrations every time i want to create table in Laravel?
So basicly i have started working with laravel. And to this moment i have been writing migrations and defining the fields there. And after that i should create a model related to it and define the ...
0 votes
0 answers
44 views
Laravel Relationship complex with passing dynamic value [duplicate]
I have a complex query such as $drivers = Drivers::where('somecondition', $request->condition) ->with([ 'license' => function($query) { $query->where('is_active', 1)...
-2 votes
1 answer
103 views
Includin many models in the routes `web.php` file practice
I have many routes, and for a single page (my homepage) I need to sample almost all of my models. I do it like that: use App\Models\Aa; use App\Models\Bb; use App\Models\Cc; // and so on ... Route::...
-1 votes
1 answer
347 views
Route Model binding in Laravel
I have a Laravel app and a model Category. It has a relation to itself called parent Category.php public function parent(): BelongsTo { return $this->belongsTo(self::class, 'parent_uuid', 'uuid'...