Skip to content
Advertisement

Tag: eloquent

Laravel: Passing data into route from database

I have created a theme system and I am trying to make the theme’s route file pull pages from the database and assign a route to it, below is my theme route file. The issue I am having is an Undefined variable: theme from my ThemeSettings::all model request. Route.php (In theme) ThemeSettings Migration These settings have worked in other parts

How to get all data from a Eloquent Model with it’s relations?

My question is how to get the data from an eloquent model with its relation? Imagine 3 tables: users: companies: addresses: And the relations: Company.php User.php Address.php In this case how I can get let’s say all the companies with their related users and addresses? on Company::whereHas(‘users’)->get(); getting: Any thoughts? Thank you Answer The issue was that in the company

Returning null instead of “Call to undefined relationship” error for Laravel relationships

When I use ModelName::with(‘somerelation’)->get() with Laravel Eloquent, if the model doesn’t have this relationship I get Call to undefined relationship [somerelation] on model [AppSomeModel] error. But for polymorphic relations, I get collection of all related models and I would like to use with(‘somerelation’) and get null if relationship is not defined. Is there any way to avoid error and return

Advertisement