How to Add Values to the Form Request After Validation in Laravel

Sometimes it’s necessary to add more values to the form request after it has been validated. These values get returned in this method even though they were not part of the request. For this, we can use the method validated() in our form request and merge the original request data with our custom data. In […]

How to filter by NULL in Eloquent Collections Laravel

Eloquent collections are one of the most powerful tools in the Laravel toolbox. They give you a fluent, convenient wrapper for complex SQL queries. You can chain together different conditions to create complex queries and then call methods on the resulting collection to fetch your data. And here comes the trap. For example, you filter […]

How to use Laravel dd() method with less code

Hello, guys! Did you know that you don’t have to wrap your Eloquent query with dd() method, and just simple can add it at the end of the query? See how simple it is. How to use dd() in Laravel What is dd() in Laravel? Dump and Die, or dd(), is a Laravel helper function […]

How to update or create elements with upsert method in Laravel

If you want to update or create multiple items at the same time, you can use the upsert method: The method’s first argument consists of the values to insert or update, while the second argument lists the column(s) that uniquely identify records within the associated table. The method’s third and final argument is an array […]

29 Best Laravel Tutorials and Resources for Beginners in 2022

Laravel is a free, open-source PHP web framework created by Taylor Otwell. It has expressive, elegant syntax and takes the pain out of development by easing everyday tasks used in most web projects, such as authentication, routing, sessions, and caching. Whether you’re just getting started with Laravel or looking for some advanced topics, this comprehensive […]

How to set timeouts when working with API in Laravel

When you’re working with third-party platform APIs that aren’t very stable, you can make use of some built-in methods on the HTTP client to do some error handling. For example, if you’re making requests to some website API, but the server is slow or there’s an issue with connectivity, you can add a timeout method […]

Adding estimated time to read an article in Laravel

If you’re wondering how to do that, the short answer is here: we are going to use one private method and Laravel Accessor. Don’t be afraid, it’s pretty simple. First off, we’re going to count seconds and minutes to read using this formula: Let’s make a whole function using that formula and put in into […]

How to pass a Model instance to Livewire in Laravel

If you want to pass a Model to your Laravel Livewire component, you can do it via public property instead of adding the code to the mount() method. Take a look at this code excerpt: By @sky_0xs

How to use default Models with relationships in Laravel

As you may know, you can skip checking if your relationship doesn’t exist in Laravel with withDefault method. But did you know that you can also assign attributes to a default Model? See the example below: