diff --git a/app/Http/Controllers/Broker/BrokerDashboardController.php b/app/Http/Controllers/Broker/BrokerDashboardController.php index 752912f..89ec053 100644 --- a/app/Http/Controllers/Broker/BrokerDashboardController.php +++ b/app/Http/Controllers/Broker/BrokerDashboardController.php @@ -4,11 +4,30 @@ use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; class BrokerDashboardController extends Controller { 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(); } } diff --git a/app/Http/Controllers/BrokerDealController.php b/app/Http/Controllers/BrokerDealController.php index 9d7fbe4..2790587 100644 --- a/app/Http/Controllers/BrokerDealController.php +++ b/app/Http/Controllers/BrokerDealController.php @@ -37,6 +37,13 @@ public function store(StoreBrokerDeal $request) $data['slug'] = Str::slug($data['title']); $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::create($data); Deal::reguard(); diff --git a/app/Models/Deal.php b/app/Models/Deal.php index 44c827a..d4b666b 100644 --- a/app/Models/Deal.php +++ b/app/Models/Deal.php @@ -3,8 +3,17 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; 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'); + } } diff --git a/app/Models/DealCategory.php b/app/Models/DealCategory.php index d9705ed..ea801a8 100644 --- a/app/Models/DealCategory.php +++ b/app/Models/DealCategory.php @@ -3,8 +3,12 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; class DealCategory extends Model { - // + public function deals(): HasMany + { + return $this->hasMany(Deal::class); + } } diff --git a/app/Models/User.php b/app/Models/User.php index c165fab..cb10c1c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -5,6 +5,7 @@ // use Illuminate\Contracts\Auth\MustVerifyEmail; use App\Enums\UserTypes; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; @@ -53,4 +54,9 @@ public function isBroker(): bool { return $this->role === UserTypes::Broker->value; } + + public function deals(): HasMany + { + return $this->hasMany(Deal::class); + } } diff --git a/resources/views/components/dashboard/listing-card.blade.php b/resources/views/components/dashboard/listing-card.blade.php index c8591a3..ed282b7 100644 --- a/resources/views/components/dashboard/listing-card.blade.php +++ b/resources/views/components/dashboard/listing-card.blade.php @@ -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])

{{$title}}

- @if($status == 'Active') - - @elseif($status == 'Pending') - + @if($status == 1) + + @else + @endif

{{$category}}

diff --git a/resources/views/components/dashboard/listing.blade.php b/resources/views/components/dashboard/listing.blade.php index c6b096f..fe63db6 100644 --- a/resources/views/components/dashboard/listing.blade.php +++ b/resources/views/components/dashboard/listing.blade.php @@ -1,36 +1,20 @@ +@props(['deals' => []])
- -

My Listings

-
- + +

My Listings

+
+ @foreach($deals as $deal) - - - -
-
+ + @endforeach +
+
diff --git a/resources/views/components/dashboard/stats.blade.php b/resources/views/components/dashboard/stats.blade.php index b13fbe7..1229d79 100644 --- a/resources/views/components/dashboard/stats.blade.php +++ b/resources/views/components/dashboard/stats.blade.php @@ -1,5 +1,6 @@ +@props(['list_count' => 0])
- + diff --git a/resources/views/dashboards/broker/index.blade.php b/resources/views/dashboards/broker/index.blade.php index 83afa1d..8abd980 100644 --- a/resources/views/dashboards/broker/index.blade.php +++ b/resources/views/dashboards/broker/index.blade.php @@ -1,8 +1,8 @@
- - + +
@vite('resources/js/nav-menu.js')