dealhub/app/Http/Controllers/Admin/DealController.php
kusowl 0789c21100 feature(deal approval): admin can approve the deals
- admin can see the deal details in modal
- admin can approve or delete the deals
2026-01-28 18:21:48 +05:30

50 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Deal;
use Illuminate\Support\Facades\Log;
class DealController extends Controller
{
public function index()
{
return view('dashboards.admin.deals.index')
->with('deals', $this->deals());
}
public function approve(Deal $deal)
{
try {
\DB::transaction(function () use ($deal) {
$deal->active = true;
$deal->save();
});
return back()->with('success', 'Deal activated successfully.');
} catch (\Throwable $e) {
Log::error('Deal activation Failed: ', [$e->getMessage(), $e->getTrace()]);
return back()->with('error', 'Something went wrong.');
}
}
public function reject(Deal $deal){
try {
$deal->delete();
return back()->with('success', 'Deal deleted successfully.');
} catch (\Throwable $e) {
Log::error('Deal deletion Failed: ', [$e->getMessage(), $e->getTrace()]);
return back()->with('error', 'Something went wrong.');
}
}
private function deals()
{
return Deal::where('active', false)->get();
}
}