bind the link with the view deal button show the total redirection count reflect the total redirect count immediately add arch test so that dump statements are not left out
57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\UserTypes;
|
|
use App\Models\Deal;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ExplorePageController extends Controller
|
|
{
|
|
public function __invoke()
|
|
{
|
|
return view('explore')
|
|
->with('profileLink', $this->profileLink())
|
|
->with('deals', $this->deals());
|
|
}
|
|
|
|
protected function deals()
|
|
{
|
|
return Deal::query()
|
|
->select([
|
|
'id', 'title', 'description', 'image', 'active', 'slug', 'link',
|
|
'deal_category_id', 'user_id',
|
|
])
|
|
// Select additional details
|
|
->with([
|
|
'category:id,name',
|
|
'broker' => function ($query) {
|
|
$query->select('id', 'name', 'email', 'role_type', 'role_id')
|
|
->with('type');
|
|
},
|
|
])
|
|
// Select only admin-approved deals
|
|
->withActiveDeals()
|
|
// Check if the current user interacted with the deal
|
|
->withCurrentUserInteractions()
|
|
->withLikes()
|
|
->withRedirections()
|
|
->latest()
|
|
->paginate();
|
|
}
|
|
|
|
/**
|
|
* Determines the link to the user's profile dashboard
|
|
* based on the user's role.
|
|
*
|
|
* @return string The URL for the user's dashboard.
|
|
*/
|
|
protected function profileLink()
|
|
{
|
|
$user = Auth::user();
|
|
if ($user->role === UserTypes::Broker->value) {
|
|
return route('broker.profile.show', $user);
|
|
}
|
|
}
|
|
}
|