50 lines
1.2 KiB
PHP
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();
|
|
}
|
|
}
|