Questions tagged [eloquent-relationship]

Official documentation: https://laravel.com/docs/7.x/eloquent-relationships

944 questions
0
votes
1 answer

Laravel Eloquent relationship belongsTo returns current table instead of the joined table

I am trying to this data through this code Auth::user()->personnel->currentAssignment->role->is_allowed but I am getther null value because the suppose role value return assignment, instead of role data. This is working fine…
0
votes
0 answers

One-to-many relationship between two different connections in laravel

I need to make the relationship between two connections. A user can have many different clients and databases. class User extends Authenticatable { protected $connection = 'mysql'; } class Client extends Model { protected $connection =…
MSilva
  • 1
0
votes
1 answer

how to makes beautiful output view laravel when using hasmanythrough relationship

i'm using hasManyThrough eloquent relatoinship laravel, when i'm foreach data in view i got a mess output. this is my output. https://ibb.co/jymR7GQ Member model public function rents() { return…
0
votes
4 answers

getting error when applied WHERE clause on a model(parent) and then gets its related model(child) data in eloquent

I have a User model which is a parent and Project model which is a child. I created a one-to-many relationship between these two like below. User Model: class User extends Authenticatable { use Notifiable; /** * The…
habib
  • 89
  • 1
  • 10
0
votes
1 answer

Including relationships in eloquent resource collection optionally

I want load relationship optionally on collection api end point The end point will be something like http://127.0.0.1:8000/api/posts/?include=comments includes comments with posts and I can add more using comma,…
0
votes
1 answer

How to query three tables in laravel eloquent

I am building an event website with laravel, my problem is that I want to query the event table in the DB and also organizers table and ticket table, the event table will provide the id which I will use to query the rest of the tables (tickets and…
Eloike David
  • 175
  • 4
  • 15
0
votes
2 answers

I am trying to get the columns from an array but can be able to get it in laravel

I am trying to fetch the columns from another table through the id but whenever I do I get this error if I use foreach in the view Property [id] does not exist on this collection instance. (View:…
0
votes
1 answer

Unit testing model relationships in Laravel

In my app I have a many-to-many relationship between users and organisations, User public function organisations() { return $this->belongsToMany('App\Organisation')->withPivot(['owner']); } Organisation public function users() { return…
Udders
  • 6,914
  • 24
  • 102
  • 194
0
votes
1 answer

eloquent relationship not working returning Trying to get property of non-object (Edited)

Product name/title table column not eching with My eloquent relationship used in the code @if(is_null($order->orderid)) No Product @else {{$order->products- >title}} @endif @foreach($orders as $order)
0
votes
1 answer

How to paginate the query results when using Laravel eloquent relationships

I have the following query which retrieves the child configuration records (confch) associated with the parent configuration (confp) and it works fine. $data["items"] = Confp::find(decrypt($type))->Confch; I just need to paginate the…
M Reza Saberi
  • 7,134
  • 9
  • 47
  • 76
0
votes
2 answers

Evaluate existence of relationship as true or false - Laravel Relationships

I'm trying to create a policy like the following: public function view(User $user, PersonalStatement $personalStatement) { return $user->applicant->id == $personalStatement->applicant_id || $user->mentor->exists(); } I then test it with a…
Adnan
  • 3,129
  • 6
  • 31
  • 36
0
votes
3 answers

Confused with Laravel's hasOne Eloquent Relationships

I have a new Laravel 5.8 application. I started playing with the Eloquent ORM and its relationships. There is a problem right away that I encountered. I have the following tables. (this is just an example, for testing reasons, not going to be an…
Radical_Activity
  • 2,618
  • 10
  • 38
  • 70
0
votes
1 answer

Eloquent hasMany with hasMany and a join in the middle

I have this database structure orders ====► order_items ====► order_item_meta ║ | ║ | ▼ ▼ order_meta products The relations are orders hasMany order_items which hasManyThrough…
justadev
  • 1,168
  • 1
  • 17
  • 32
0
votes
2 answers

Select specific column value from multiple relational table using where condition in Laravel ORM

I have two tables named contacts and clients. Both tables have group_id as foreign_key. Now, I want to get phonecolumn value from both tables when user $request->groupid will found a group from groupstable. I am trying something like this. But…
Rashed Hasan
  • 3,721
  • 11
  • 40
  • 82
0
votes
1 answer

Get relationship data from withPivot on many-to-many pivot table

TL/DR: I've got a many-to-many relationship between two models using withPivot and and using. I want to get the related data from the withPivot value from a foreign key. I am working with a multi tenancy project, which has a master database and…
n8udd
  • 657
  • 1
  • 9
  • 30