feat(broker dashboard): show created deals on dashboard with count
- add relationships - refactor component for displaying values
This commit is contained in:
parent
f43f92f365
commit
e2fabcd8b6
@ -4,11 +4,30 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class BrokerDashboardController extends Controller
|
class BrokerDashboardController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return view ('dashboards.broker.index');
|
return view('dashboards.broker.index')
|
||||||
|
->with('deals', $this->deals());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function deals()
|
||||||
|
{
|
||||||
|
return Auth::user()
|
||||||
|
->deals()
|
||||||
|
->select([
|
||||||
|
'title',
|
||||||
|
'description',
|
||||||
|
'image',
|
||||||
|
'active',
|
||||||
|
'slug',
|
||||||
|
'deal_category_id',
|
||||||
|
])
|
||||||
|
->with('category:id,name')
|
||||||
|
->latest()
|
||||||
|
->paginate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,6 +37,13 @@ public function store(StoreBrokerDeal $request)
|
|||||||
$data['slug'] = Str::slug($data['title']);
|
$data['slug'] = Str::slug($data['title']);
|
||||||
$data['user_id'] = $request->user()->id;
|
$data['user_id'] = $request->user()->id;
|
||||||
|
|
||||||
|
$path = '';
|
||||||
|
if($request->hasFile('image')){
|
||||||
|
$image = $request->file('image');
|
||||||
|
$path = $image->storeAs('images/deals', $data['slug'] . '.' . $image->extension(), 'public');
|
||||||
|
}
|
||||||
|
$data['image'] = $path;
|
||||||
|
|
||||||
Deal::unguard();
|
Deal::unguard();
|
||||||
Deal::create($data);
|
Deal::create($data);
|
||||||
Deal::reguard();
|
Deal::reguard();
|
||||||
|
|||||||
@ -3,8 +3,17 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
class Deal extends Model
|
class Deal extends Model
|
||||||
{
|
{
|
||||||
//
|
public function User(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function category(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(DealCategory::class, 'deal_category_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,12 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
class DealCategory extends Model
|
class DealCategory extends Model
|
||||||
{
|
{
|
||||||
//
|
public function deals(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Deal::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
use App\Enums\UserTypes;
|
use App\Enums\UserTypes;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
|
||||||
@ -53,4 +54,9 @@ public function isBroker(): bool
|
|||||||
{
|
{
|
||||||
return $this->role === UserTypes::Broker->value;
|
return $this->role === UserTypes::Broker->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deals(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Deal::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
@props(['image' => '', 'title' => '', 'category' => '', 'impressions' => 0, 'likes' => 0, 'clicks' => 0, 'status' => ''])
|
@props(['image' => '', 'title' => '', 'category' => '', 'impressions' => 0, 'likes' => 0, 'clicks' => 0, 'status' => false])
|
||||||
<x-ui.image-card :image="$image">
|
<x-ui.image-card :image="$image">
|
||||||
<div class="bg-white pt-8 px-4 space-y-4">
|
<div class="bg-white pt-8 px-4 space-y-4">
|
||||||
<div class="flex justify-between items-baseline">
|
<div class="flex justify-between items-baseline">
|
||||||
<p class="font-bold text-lg">{{$title}}</p>
|
<p class="font-bold text-lg">{{$title}}</p>
|
||||||
@if($status == 'Active')
|
@if($status == 1)
|
||||||
<x-ui.badge :title="$status"/>
|
<x-ui.badge title="Active"/>
|
||||||
@elseif($status == 'Pending')
|
@else
|
||||||
<x-ui.badge :title="$status" variant="ghost"/>
|
<x-ui.badge title="Pending" variant="ghost"/>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<p class="text-accent-600">{{$category}}</p>
|
<p class="text-accent-600">{{$category}}</p>
|
||||||
|
|||||||
@ -1,36 +1,20 @@
|
|||||||
|
@props(['deals' => []])
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<x-dashboard.card class="bg-white">
|
<x-dashboard.card class="bg-white">
|
||||||
<p class="font-bold mb-6">My Listings</p>
|
<p class="font-bold mb-6">My Listings</p>
|
||||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
|
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
|
||||||
<x-dashboard.listing-card
|
@foreach($deals as $deal)
|
||||||
:image="asset('storage/images/pexels-irrabagon-35425432.jpg')"
|
|
||||||
title="Luxury Apartment Downtown"
|
|
||||||
category="Real Estate"
|
|
||||||
status="Active"
|
|
||||||
impressions="1245"
|
|
||||||
likes="89"
|
|
||||||
class="156"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<x-dashboard.listing-card
|
<x-dashboard.listing-card
|
||||||
:image="asset('storage/images/vitaly-gariev-NODOn-Mrams-unsplash.jpg')"
|
:image="asset('storage/'.$deal->image)"
|
||||||
title="Best Italian Resturant"
|
:title="$deal->title"
|
||||||
category="Real Estate"
|
:category="$deal->category->name"
|
||||||
status="Active"
|
:status="$deal->active"
|
||||||
impressions="1245"
|
|
||||||
likes="89"
|
|
||||||
class="156"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<x-dashboard.listing-card
|
|
||||||
:image="asset('storage/images/vijay-kumar-pZcEo5TlxJc-unsplash.jpg')"
|
|
||||||
title="Luxury Apartment Downtown"
|
|
||||||
category="Real Estate"
|
|
||||||
status="Pending"
|
|
||||||
impressions="1245"
|
impressions="1245"
|
||||||
likes="89"
|
likes="89"
|
||||||
class="156"
|
class="156"
|
||||||
/>
|
/>
|
||||||
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
</x-dashboard.card>
|
</x-dashboard.card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
|
@props(['list_count' => 0])
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 wrapper gap-8">
|
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 wrapper gap-8">
|
||||||
<x-dashboard.stats-card title="My Listings" score="24">
|
<x-dashboard.stats-card title="My Listings" :score="$list_count">
|
||||||
<x-icon-square variant="blue">
|
<x-icon-square variant="blue">
|
||||||
<x-heroicon-o-document-text class="w-8" />
|
<x-heroicon-o-document-text class="w-8" />
|
||||||
</x-icon-square>
|
</x-icon-square>
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
<x-layout title="Broker Dashboard">
|
<x-layout title="Broker Dashboard">
|
||||||
<section class="flex flex-col space-y-8 bg-[#F9FAFB]">
|
<section class="flex flex-col space-y-8 bg-[#F9FAFB]">
|
||||||
<x-dashboard.navbar/>
|
<x-dashboard.navbar/>
|
||||||
<x-dashboard.stats/>
|
<x-dashboard.stats :list_count="$deals->count()"/>
|
||||||
<x-dashboard.listing />
|
<x-dashboard.listing :deals="$deals"/>
|
||||||
</section>
|
</section>
|
||||||
@vite('resources/js/nav-menu.js')
|
@vite('resources/js/nav-menu.js')
|
||||||
</x-layout>
|
</x-layout>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user