0

The problem is that i have 3 database tables

  • 1st table of users with user_id
  • 2nd table is attribute with attribute_id and attribute_name
  • And 3rd one is Rating table having user_id and attribute_id

i want to get attribute_name from 2nd table using attribute_id after click on the specific user? Is it possible? If answer is Yes then please give me a suggestion how yo do this? thanks sir in advance?

  • Here i'm upload the image that after i click on specific user for edit display its record from user table and attribute_id from attribute table using many to many relation and problem is that we get attribute_name of specific id from Rating table using the attribute_id?? Is It Possible?

Its Edit form and below submit button get id from attribute table but we want to display attribute_name from rating table

Its Edit form and below submit button get id from attribute table but we want to display attribute_name from rating table

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
  • pls look in another questions. https://stackoverflow.com/questions/10269809/mysql-join-query – Igor Monteiro Nov 23 '17 at 19:24
  • Can you post the models and the blade code? – Laerte Nov 23 '17 at 19:24
  • User Model : public function Rating(){ return $this->hasMany(Rating::class); } Rating Model: public function User(){ return $this->belongsTo(User::class); } – Muhammad Danish Nov 23 '17 at 19:30
  • @DanishButt Please update your original question with the code. Also, fix your spelling mistakes and editing as your question is not very readable. – elena Nov 23 '17 at 19:43

2 Answers2

0

Users model:

public function rating()
{
    return $this->belongsTo(Rating::class);
}

Rating model:

public function attribute()
{
    return $this->hasMany(Attribute::class, 'attribute_id');
}

Then call it in controller:

dd(Users::with('rating.attribute')->where('user_id', 1));
Aleksey Solomakha
  • 113
  • 1
  • 1
  • 9
0

Query::

$records = DB::table('attributes')->join('ratings','attributes.id','=','ratings.attribute_id')->where('user_id',$id)->get();
return view('employee.edit',compact('records'));

Your EDIT VIEW PAGE

@foreach($records as $record)
<h4>Attributes ==>{{$record->attribute}}</h4>
@endforeach