Fetch Listings by Tags

Fetch by tags

  • single
  • multiple
  • static (manual - nurse)
  • dynamic (auto-generated - $tag1)
Union VS Intersect
  1. withTagsUnion()
  2. withTagsIntersect()


<?php
$tag1 = trim($listing->keyField('job_post_1'));
?>

<!-- Listings by Custom Tags -->
<h1 style="background:coral; color: white;">Listings by Custom Tags</h1>

<?= template()->include('frontend/custom/jobs/partials/recommended-listings', [
'recommendedListings' => App\Models\Listing::withTagsIntersect([$tag1], 5)
]) ?>
#
In the above case
job_post_1 = manager
so,
$tag1 = trim($listing->keyField('job_post_1'));
$tag1 = manager
so,
'recommendedListings' => App\Models\Listing::withTagsIntersect([$tag1], 5) = auto
=
'recommendedListings' => App\Models\Listing::withTagsIntersect([manager], 5) = manual

Multiple Tag Example

<!-- Listings by Custom Tags -->
<h1 style="background:coral; color: white;">Listings by Custom Tags</h1>
<?= template()->include('frontend/custom/jobs/partials/recommended-listings', [
'recommendedListings' => App\Models\Listing::withTagsIntersect(['bank-jobs', 'featured'], 5)
]) ?>

Same can also be written as

<!-- Listings by Custom Tags -->
<h1 style="background:coral; color: white;">Listings by Custom Tags</h1>
<?= template()->include('frontend/custom/jobs/partials/recommended-listings', [
'recommendedListings' => App\Models\Listing::withTagsIntersect([$tag1, 'featured'], 5)
]) ?>

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.