Eloquent Foreign Keys: 3 Syntax Ways to Define Them
When defining a database relationship, you can use the `foreignId()` or `foreignIdFor()` methods to add a foreign key. Let's take a look at the examples.
In-depth Laravel tutorials covering advanced topics, real-world examples, and best practices.
When defining a database relationship, you can use the `foreignId()` or `foreignIdFor()` methods to add a foreign key. Let's take a look at the examples.
Adding foreign keys can sometimes be tricky. You might get an error message or see that it doesn't work as expected. There are 3 common mistakes that we see developers make when adding foreign keys to their databases.
In Filament simple resources, you can edit the record in a modal window. Did you know there's a way to show that modal not in the center of the screen, but sliding out from the right side? In this short tutorial, I will show you how.
In Laravel, we have a method called whereHas that takes the parent Model only if it has a relationship matching a condition. But there's also withWhereHas, what does it do?
PHP Traits are a powerful feature that allows you to reuse code in multiple classes without repeating yourself. In this tutorial, I will show 4 examples of how you can use Traits in your Eloquent models.
The performance of our applications is one of the top things we should care about. Inefficient Eloquent or DB queries are probably no.1 reason for bad performance. In this tutorial, I will show you the top 3 mistakes developers make when it comes to Eloquent performance, and how to fix them.
When working with large datasets that are complex to get or rarely change, we can use caching to reduce the load on our database. For this, we will use the Cache class. In the examples, we will try to optimize the database call that takes 10 000 records from it.
While working with models - we often need to do something with the data before/after saving it in the database: change the format, trim whitespaces, trim HTML tags, and so on.
In this tutorial, we will create a simple search from three Models and will use Laravel Collections to combine them into one collection to show results in the front-end.
By default, Livewire doesn’t allow to use of Form Request classes for validation. But, as with many things, there is a workaround.