129 lines
3.4 KiB
PHP
129 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Transformation\app\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Modules\Transformation\app\Http\Requests\TransformationRequest;
|
|
use Modules\Transformation\app\Repositories\TransformationRepository;
|
|
|
|
class TransformationController extends Controller
|
|
{
|
|
protected $transformationRepo;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->transformationRepo = new TransformationRepository();
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$perPage = $request->has('per-page') ? $request->input('per-page') : null;
|
|
$filter = $request->has('filter') ? $request->input('filter') : [];
|
|
$data['transformations'] = $this->transformationRepo->findAll($perPage, $filter);
|
|
|
|
return view('transformation::index', $data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
$data = [];
|
|
|
|
return view('transformation::create', $data);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(TransformationRequest $request): RedirectResponse
|
|
{
|
|
try {
|
|
$validated = $request->validated();
|
|
|
|
$this->transformationRepo->create($validated);
|
|
toastr()->success('Data created successfully.');
|
|
|
|
return redirect()->route('transformation.index');
|
|
} catch (\Throwable $th) {
|
|
report($th);
|
|
toastr()->error('Something went wrong.');
|
|
|
|
return back();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Show the specified resource.
|
|
*/
|
|
public function show($id)
|
|
{
|
|
return view('transformation::show');
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$data['transformation'] = $this->transformationRepo->findById($id);
|
|
if (!$data['transformation']) {
|
|
toastr()->error('transformation not found');
|
|
return back();
|
|
}
|
|
|
|
return view('transformation::edit', $data);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update($id, TransformationRequest $request): RedirectResponse
|
|
{
|
|
try {
|
|
$validated = $request->validated();
|
|
$transformation = $this->transformationRepo->update($id, $validated);
|
|
if (!$transformation) {
|
|
toastr()->error('transformation not found');
|
|
return back();
|
|
}
|
|
toastr()->success('Data updated successfully.');
|
|
|
|
return redirect()->route('transformation.index');
|
|
} catch (\Throwable $th) {
|
|
report($th);
|
|
toastr()->error('Oops! Something went wrong.');
|
|
|
|
return redirect()->back();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
try {
|
|
$transformation = $this->transformationRepo->delete($id);
|
|
if (!$transformation) {
|
|
toastr()->error('transformation not found');
|
|
|
|
return back();
|
|
}
|
|
toastr()->success('Data deleted successfully.');
|
|
} catch (\Throwable $th) {
|
|
report($th);
|
|
toastr()->error('Oops! Something went wrong.');
|
|
}
|
|
|
|
return redirect()->back();
|
|
}
|
|
}
|