How-to articles, tricks, and solutions about ELOQUENT
To update multiple records in the Eloquent ORM (Object-Relational Mapping) in Laravel, you can use the update() method on the query builder or on a model instance.
To alias a table in a Laravel Eloquent query, you can use the as method on a DB facade.
You can use the destroy() method in Laravel Eloquent to delete multiple records.
In Laravel, you can use the withTrashed() method to retrieve all the rows, including the soft deleted ones, from a table.
In Laravel, you can use the save method provided by Eloquent to insert a new record and retrieve the last insert ID.
You can use the whereIn method on a query builder instance to create an "IN" clause for a given column and values.
In Laravel, you can use the refresh method on a model instance to reload the model's attributes from the database.
In Laravel 5.1, you can use the selectRaw method to select the year and month from the created_at attribute of a database table.
In Laravel's Eloquent ORM, you can use the inRandomOrder method to retrieve a random row from the database.
The pluck method is used to retrieve a list of a single column from a database table.
In Laravel, you can use the exists method on a relationship to check if it has any related models.
Here's an example that demonstrates the difference between using attach() and sync() in Laravel Eloquent:
To perform an inner join with multiple conditions using Laravel's Eloquent ORM, you can use the join method on a query builder instance.
In Laravel, you can use the leftJoin method on a query builder instance to perform a left join, and then use the whereNull method to only include records where a column from the right-hand table is null:
You can use the sum method on an Eloquent relation to get the sum of a column's values.