Files
Discount-Bandit/app/Http/Controllers/GetOtherRelatedLinksController.php
Cybrarist 628277ff88 add price chart
update costco crawler
prepare for plugin integration
increase file upload limit for livewire
2025-11-06 17:30:04 +04:00

44 lines
1.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Helpers\ProductHelper;
use App\Models\Link;
use App\Models\Product;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class GetOtherRelatedLinksController extends Controller
{
/**
* Handle the incoming request.
*/
public function __invoke(Request $request, Link $link)
{
$product_have_the_link = DB::table('link_product')
->where('link_id', $link->id)
->pluck('product_id');
$links = Product::withoutGlobalScopes()
->where('products.user_id', Auth::id())
->whereIn('products.id', $product_have_the_link)
->join('link_product', 'products.id', '=', 'link_product.product_id')
->pluck('link_product.link_id');
return Link::whereIn('id', $links)
->whereNot('id', $link->id)
->with([
'store',
'store.currency',
])
->get()
->map(function ($link) {
$link->url = ProductHelper::get_url($link);
return $link;
});
}
}