David Nguyeneplus.dev·Oct 11, 2023Laravel Eloquent HasManyThrough relationships with unlimited levelsThis extended version of HasManyThrough allows relationships with unlimited intermediate models.It supports many-to-many and polymorphicrelationships and all their possible combinations. It also supports some third-party packages. Supports Laravel 5....Discuss·29 readsLaraveleloquent
David Nguyeneplus.dev·Oct 11, 2023Laravel Eloquent TipsThis is a short list of the amazing hidden Laravel eloquent 30 tips that make the code go on smoothly. This is a short list of the amazing hidden Laravel eloquent 30 tips that make the code go on smoothly. 1 – Invisible Database Columns The invisible...DiscussLaraveleloquent
Ghanshyam DigitalforGhanshyam Digitalblog.ghanshyamdigital.com·Jan 30, 2023Building a Self-Referencing Model in Laravel: A Step-by-Step Guide1. Introduction Self-referencing models, also known as recursive relationships, are a powerful tool in Laravel's Eloquent ORM (Object-Relational Mapping) system. They allow a model to have a relationship with itself, which can be useful for data stru...Discuss·6 likes·2.6K readsLaravel
Jasper Teyjaspertey.com·Jan 10, 2023Another way to prepend table names to columns in Eloquent queriesWhen writing complex queries in Eloquent, you will more than likely encounter scenarios forcing you to prefix column references with the table name to handle SQL ambiguity, especially when joins are involved. Consider the following ways you might've ...Discuss·86 readsLaravel
Yunus Shaikhyunus.in·Jan 1, 2023How to get a single record from hasMany Relation in Laravel in the most efficient way.$users = User::query()->addSelect([ 'last_ordered_at' => Order::select("created_at") ->whereColumn('user_id', 'users.id') ->latest() ->take(1), ])->orderBy('name')->paginate(); Cons...Discuss·2 likes·90 readsLaravel
Tjtajid.hashnode.dev·Mar 19, 2022Nullable Uniques on Eloquent ModelWe could setup a composite unique index for two more fields through $table->unique(['company_id', 'email']), to make sure that each email address is used only by user in a company utilizing database unique constraints. The problem arise when we need ...Discuss·76 readsLaravel
Olguncodewitholgun.com·Feb 20, 2022Laravel Eloquent Tutorial - Get only the fields (aka columns) we need from relation.Laravel is a great framework to work with, and I use it every day for my 9-5 job. One of the greatest power of Laravel is, it has an ORM (Object Relational Mapping) as default called Eloquent. I am not going to talk about what is Eloquent ORM, but I ...Discuss·12 likes·743 readsLaravel
Hasan MNhasanmn.dev·Oct 16, 2021Automatically Update `created_by` and `updated_by` in Laravel Using Bootable TraitsIf you use timestamps feature in Laravel, then you got the free feature of auto-update on created_at and update_at columns when the model is created or updated. Now, what if you want the same thing for you own customs created_by and updated_by column...Discuss·262 readsLaravel
Vishnu Damwalameshworld.hashnode.dev·Sep 17, 2021How to update a record without updating timestamp in LaravelWhile working on an application, you might encounter a situation, where you don't need to update the default timestamp field updated_at or any custom column defined by you during development. Such as user profile visit count or page visit count where...Discuss·177 readsLaravel
Emil Moeemilmoe.hashnode.dev·Sep 1, 2021Laravel Translatable AttributesIn order to fluently support multilingual, I created this trait for Laravel. My ambition was to make it as seamlessly integrated as possible and to follow the semantics of Laravel. You may also choose to install it with composer: composer require clo...Discuss·536 readsLaravel