The Hesburgh Stamp

This is a true story how the Rev. Father Theodore Hesburgh saved my father’s life while attending Notre Dame University in the early 1950’s. My father is Gerald Morgan but everyone knows him as…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




10 Laravel 7 Eloquent Tricks

Laravel Eloquent ORM provides a whole lot of useful functionality that allows you to work with your database tables and relationships using an eloquent expressive syntax.

So, In here are some of the features which you might often reach out for ease of use and cleaner code in your laravel project.

Here’s an example of finding a post with id.

Or, you can even find multiple records at once by passing array of ids as second argument.

Even specify id with the fields to select as the second argument.

In this method, you can specify what to do on different model events such as creating, updating, deleting etc by passing a closure function.

These are only few of the default properties of an eloquent model you often would reach out. You can change the values according to your needs.

you can retrieve the number of results from a relationship without actually loading them you may use the withCount method.

Define a relation comments():

Then, you can use like this:

Add a comment

Related posts:

Great reads for kids to read for FREE! on 2020

Equalland Where Everyone Equally Matters: educates about diversity and inclusion. It addresses different skin colors, physical appearances and impairments, different faiths, while it also teaches…

A Journey of Writing and Finding Myself on Medium

I joined Medium in 2020. It’s been more than a year on this platform. Before, I joined Medium I was going through the hard times of my life. That was the moment when I discovered that writing is the…

To Be a Practice

Principles are important, but principles alone are not enough. We also need ways of achieving principles in practical situations and that’s what practices are for. When a practice fulfills these…