In this series to tutorials, my plan is to take some real-life code and try to refactor the code as much as I can. Today, I will show you how to reduce unnecessary condition from the Laravel Model.
Unfortunately, there is no unique way to write code. Although there are some set of rules of writing code, however, programmers are free to write code in their own style, especially the logical part. We often see the code that contains a lot of `if-else` statement, even __nested if-else__.
Now, sometimes if you need to check whether the model has loaded the eager loading or not, then you need to check with `relationLoaded()`. Here is how you check this-