Questions tagged [laravel-relations]

165 questions
0
votes
0 answers

Laravel Image Library relationship

let me describe the scenario first: We need an Image model which holds all images of that project, like, Country has `single` image and `multiple images` for gallery, Store has `single` image, logo and `multiple images` for gallery, ... and so…
0
votes
1 answer

Select specific column only from Laravel 5.2 Relation query not working

So I have a query that I only want to get specific columns in a relation but is not working. I'm using Laravel 5.2 by the way. Here's what I have: $job = Job::query()->whereId($job_id) ->with([ 'jobType' => function (Relation…
Eem Jee
  • 1,239
  • 5
  • 30
  • 64
0
votes
1 answer

How to display a breadcrumb from root the category to the product's category in laravel 7

Goal: On my product's detail page I want to display a breadcrumb of all the parent categories that my product has. For example, if there is a product that is assigned a category_id pointing to a SubSubCategory; I want the breadcrumb to be: Root…
Jose
  • 81
  • 8
0
votes
1 answer

Morph To Many Laravel relationship

Question.php public function votes() { return $this->morphToMany('App\User' , 'votable'); } User.php public function voteQuestions() { return $this->morphedByMany('App\Answer', 'votable'); } This shows up: Call to undefined method…
-1
votes
1 answer

Convert row SQL query to Laravel Eloquent Query

I need this query to be Laravel eloquent, and also, how can I join the above tables in one single eloquent relational query? I have tried many examples to solve this query if any ideas on how to solve this please describe me in response.enter link…
-1
votes
1 answer

sum data from multiple relation in multiple relation in laravel

I have a User model, who hasMany categories and category hasMany posts and post hasOne Product Now I want to sum all of the product->price of Auth::user() how can i do that withSum or withCount function. in Laravel
Rajib Bin Alam
  • 353
  • 1
  • 4
  • 16
-1
votes
2 answers

Laravel 7: Finding a relation between two dates

I'm trying to get the jobs relation between two dates by using the whereHas method however I keep getting an Integrity constraint violation and am not sure what is causing this issue. I've tried using the with and where method, but they all return…
Salman
  • 1,109
  • 3
  • 25
  • 55
-1
votes
1 answer

Elegant way to create M:N relationships between the same models in Laravel?

I am trying to define a model relationship that I believe is extremely ordinary, but I just could not find any elegant way to do it in Laravel. I'm talking about a same-model m:n relationship. Let's say you want to define a friends…
-1
votes
1 answer

Query model fields with relationship

I have two models, User and Enumerator. I want to search certain columns in enumerator model and it's relationship in the user model. Here is what i have; Enumerator unique_id User first_name I want to write a query that'll fetch both unique_id…
Patrick Obafemi
  • 908
  • 2
  • 20
  • 42
-2
votes
2 answers

Laravel One To One Relationship With Custom Foreign Key NOT WORKING

I'm working with Laravel v10 and I have a users table and each user has also another record at the members table. So in order to set up the One To One Relationship between these two Models: User Model: public function member() { return…
Pouya
  • 114
  • 1
  • 8
  • 36
-2
votes
3 answers

Laravel Eloquent : Select random rows on relation based

I want to pick questions randomly but category dependent. For example, if the test is given with 10 questions and the total category is 5, the test flow should take 2 questions randomly from each category. Is there a way to select it through random…
OutForCode
  • 381
  • 9
  • 26
-2
votes
1 answer

How Does Laravel 8 Polymorphic Relationship

Laravel Hospital Management System Table Relation With Prescription, Presscription_medicine and Medicine Table. the concept is presscription_medicine table's store more medicine by reference one prescription id, and each presscription_medicine…
-2
votes
1 answer

Property [user] does not exist on this collection instance

i'm developping a social app using React in the frontend and laravel in the backend. I'm trying to receive all posts with their likes,users,comments. I have these relation ships: 1/ User model has many posts and Post model belongs to a user. 2/ Post…
-2
votes
1 answer

Get column from grandchild table in laravel

I have 3 tables Table A, Table B and Table C Table 1 has many Table B and Table B has many Table C I am using this query TableA::where(whereclause)->with(TableB.TableC) Now i want to select some column from table c in controller is there any way…
Jack
  • 1
-2
votes
1 answer

Laravel - How to sum child data and pass it to parent @foreach

i'm new to laravel. So in this case i'm trying to sum child data and pass it to parent nominal column inside parent index @foreach, the thing is idk how to declare the parent id inside controller here's my parent index which i want to show the sum…
kzehaya
  • 1
  • 1
  • 4
1 2 3
10
11