So I have done the following: I have a table called group that has longitude and latitude which is essentially a location of the group. Then I have an append which calculates the distance from the user. Group Model: What I want to do now is USE that distance from user in a where clause like below in a scope,
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
How to get all the people in table 1 without getting the people who have me as parent_id in table 2?
I’m writing this post because I have a problem with my relationships on Laravel. Here is the structure I currently have: 1st table: – id – name – … 2nd table : – parent_id – child_id knowing that …
Eloquent Laravel multiple like where and where clause
I have the below Mysql query that works. mysql: select * from operatories op left join locations al on op.location = al.location where op.opname like ‘%NP%’ or op.opname like ‘%OPEN%’ and al….
How to get sum and separate the total per Id in laravel
This is my query in my controller public function show($id) { $Days = DB::table(‘payroll_monthly_attn_project’)->where(‘payroll_monthly_id’,$id)->where(‘assign’,’PAINTING’) …
Laravel whereNull and where clause returns empty object
I’m new to laravel. I tried to fetch some records from my database which are “parent” column is “null”. But it returns always empty object. Then I got the query using toSql() …
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
Eloquent complex relationship for a chat message system in laravel
I am writing a chat system and I have the following tables: chat_conversations: id, name chat_messages: id, chat_conversation_id, message, deleted_at chat_message_user: id, chat_message_id, user_id, …
Adding custom method to Laravel model causes create() to ignore attributes
In Laravel 8, I have already had a working DocumentPdf resource – at least I was able to create the object using DocumentPdf::create($attributes). Now I want to create a custom method in the model, a one that will fill the document with $data and send it to browser. While it works for existing documents, adding the method broke create() in