- Changed view extends from "admin.main" to "administrator.layout.master" across multiple files. - Updated route names in admin.php and administrator.php to reflect new structure for user, order, invoice, and other management functionalities. - Adjusted view includes to point to the new directory structure for blocks and components. - Ensured all permission checks remain intact while refactoring the views.
100 lines
2.7 KiB
PHP
100 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\AddOnRequest;
|
|
use App\Models\Addon;
|
|
use App\Repositories\Addon\AddonRepositoryInterface;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class AddonController extends Controller
|
|
{
|
|
//
|
|
public function __construct(
|
|
public AddonRepositoryInterface $addonRepository
|
|
) {}
|
|
public function index(Request $request)
|
|
{
|
|
$addOns = $this->addonRepository->filter(
|
|
[
|
|
'page' => $request->get('page', 1),
|
|
]
|
|
);
|
|
$title = 'List Add-On';
|
|
|
|
return view('administrator.pages.addon.index', compact('addOns', 'title'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$title = 'Add new addon';
|
|
return view('administrator.pages.addon.add', compact('title'));
|
|
}
|
|
|
|
public function store(AddOnRequest $request)
|
|
{
|
|
$request->validated();
|
|
|
|
DB::beginTransaction();
|
|
try {
|
|
$this->addonRepository->create($request->all());
|
|
DB::commit();
|
|
} catch (\Exception $error) {
|
|
DB::rollBack();
|
|
return back()->withErrors($error->getMessage());
|
|
}
|
|
|
|
return redirect()->route('addon.index')->with('success', 'Added successfully');
|
|
}
|
|
public function edit($id = 0)
|
|
{
|
|
|
|
$addon = $this->addonRepository->find($id);
|
|
if (! $addon) {
|
|
return back()->withErrors('Invalid request');
|
|
}
|
|
|
|
$title = 'Edit Addon';
|
|
|
|
return view('administrator.pages.addon.edit', compact('title', 'addon'));
|
|
}
|
|
public function update(int $id = 0, AddOnRequest $request)
|
|
{
|
|
$addon = $this->addonRepository->find($id);
|
|
if (! $addon) {
|
|
return back()->withErrors('Invalid request');
|
|
}
|
|
$request->validated();
|
|
|
|
DB::beginTransaction();
|
|
try {
|
|
$this->addonRepository->update($id, $request->all());
|
|
DB::commit();
|
|
} catch (\Exception $error) {
|
|
DB::rollBack();
|
|
return back()->withErrors($error->getMessage());
|
|
}
|
|
|
|
return redirect()->route('addon.index')->with('success', 'Updated successfully');
|
|
}
|
|
public function destroy($id)
|
|
{
|
|
$addon = $this->addonRepository->find($id);
|
|
if (! $addon) {
|
|
return back()->withErrors('Invalid request');
|
|
}
|
|
DB::beginTransaction();
|
|
try {
|
|
$this->addonRepository->delete($id);
|
|
DB::commit();
|
|
} catch (\Exception $error) {
|
|
DB::rollBack();
|
|
return back()->withErrors($error->getMessage());
|
|
}
|
|
|
|
return redirect()->route('addon.index')->with('success', 'Deleted successfully');
|
|
}
|
|
}
|