I got four tables
- Links (id, user_id, link_data, category_id, submit_date)
- Users (id, username, password, status)
- Categories (id, name, slug)
- 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