php - Get items based on object ID (Laravel) -
i trying specific items database based on id referenced on sub-object.
i have shoutout table, , each shoutout consist of multiple hashtags. have far:
public function shoutoutspecific($hashtag) { $hashtags = hashtag::wherehashtag($hashtag)->get(); $shoutouts = ''; return view('shoutout', compact('shoutouts')); }
but gives me hashtags, each hashtag references specific shoutout. , need shoutout, hashtag referencing id.
but wondering if there way shoutouts, shoutouts have specific hashtag referenced them. like:
shoutouts = shoutout::wherehashtag-referenced($hashtag)->get();
if shoutout
class has hasmany
relation as:
shoutout.php
public function hashtags() { return $this->hasmany(app\hashtag::class); }
then can try as:
shoutouts = shoutout::wherehas('hashtags', function($q) use($hashtag) { $q->wherehashtag($hashtag); })->get();
Comments
Post a Comment