Update source into github
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?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('admin.addon.index', compact('addOns', 'title'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$title = 'Add new addon';
|
||||
return view('admin.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('admin.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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user