Laravel
Laravel: whereBelongsTo
New in Laravel v8.64. Use the whereBelongsTo method, which will automatically determine the proper relationship and foreign key for the given model.
tips/ 87 published
Small Laravel and PHP snippets, one idea each. The ones I reach for often enough to write down.
Laravel
New in Laravel v8.64. Use the whereBelongsTo method, which will automatically determine the proper relationship and foreign key for the given model.
Laravel
Eager Loading Specific Columns. You may not always need every column from the relationships you are retrieving. For this reason, Eloquent allows you to specify which columns of the relationship you would like to retrieve:
Laravel
The Password rule object allows you to easily customize the password complexity requirements for your application, such as specifying that passwords require at least one letter, number, symbol, or characters with mixed casing.
Laravel
If your callback function repeating multiple times in elequent query, assign callback into a variable to shorten the elequent query.
Laravel
The @class directive conditionally compiles a CSS class string. The directive accepts an array of classes where the array key contains the class or classes you wish to add, while the value is a boolean expression.
Laravel
Laravel tip of the day: You may combine loops and includes into one line with Blade's @each directive.
Laravel
The firstOrCreate method will attempt to locate a database record using the given column/value pairs. If the model can't be found in the database, a record will be inserted with the attributes resulting from merging the first array argument with the optional second array argument.
Laravel
You may also call the find method with an array of primary keys, which will return a collection of the matching records.
Laravel
The firstOr method will return the first result matching the query or, if no results are found, execute the given closure. The value returned by the closure will be considered the result of the firstOr method.
Laravel
If you want to ensure that your Route parameter is a number, you can add a regex rule directly in the routes. For more detail: https://laraveldaily.com/laravel-route-filtering-with-regular-expressions/ https://laravel.com/docs/8.x/routingparameters-regular-expression-constraints
Laravel
Local scopes allow you to define common sets of query constraints that you may easily re-use throughout your application
Laravel
tip of the day: You can ignore one where condition by using the FirstWhere method.
Showing 12 of 87