Skip to main content

Search Results for "eloquent tips"

We found 20 results for "eloquent tips".

Tutorial 3 min read Free

In Eloquent We Trust, or don't assume find() always finds something

This short lesson will be both about Laravel and about general software development. One of the most often and common mistakes made by developers is not checking input data. And then not only you get random errors of something "not found", but sometimes much worse - expose your system to vulnerabilities and attacks. So let's discuss that with examples from Eloquent world.

Tutorial 2 min read Free

Why use $appends with Accessors in Eloquent?

Eloquent has a convenient feature called Accessors - you can define your own custom fields on top of existing in the database table. But then there's an Eloquent property $appends - should we use it or not? And what's the difference?

Tutorial 2 min read Free

Stop checking if record exists: Eloquent methods OrCreate and OrNew

Another "hidden gem" of Laravel which is surprisingly rarely used or even known, though it's mentioned in the official Eloquent documentation. Imagine that you have a record, and you need to check if that record already exists in the database - to prevent duplicate, you wouldn't save it second time. There's an elegant way to perform it in Eloquent.