jeudi 12 septembre 2019

JOIN replaces the original id with the id of joined table in Laravel

I got four tables

  1. Links (id, user_id, link_data, category_id, submit_date)
  2. Users (id, username, password, status)
  3. Categories (id, name, slug)
  4. Tags (id, link_id, tags)

I want to show all link details with username, Category name & slug and tags but with join it replaces the links.id with the category.id.

$catid = Category::where('slug', '=', $slug)->firstOrFail()->id;

$linksbycategories = DB::table('links')
->where('category_id', '=',$catid)
->join('users', 'users.id', '=', 'links.user_id')
->join('categories', 'categories.id', '=', 'links.category_id')
->join('tags', 'tags.link_id', '=', 'links.id')->get();
return $linksbycategories;
//return view('category', ['linksbycategories' => $linksbycategories]);

I have 3 tags of link id 1 and the result I get is 3 times data of first link information with link id as 7 which is the category id of that link. How can I solve this.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2LNZGCm
via IFTTT

Aucun commentaire:

Enregistrer un commentaire