first change

This commit is contained in:
2025-07-27 17:40:56 +05:45
commit f8b9a6725b
3152 changed files with 229528 additions and 0 deletions

View File

@@ -0,0 +1,120 @@
<?php
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\Admin\Models\Province;
use Modules\Admin\Repositories\CountryInterface;
use Modules\Admin\Repositories\ProvinceInterface;
use Yajra\DataTables\Facades\DataTables;
class ProvinceController extends Controller
{
private $province;
private $country;
public function __construct(ProvinceInterface $province, CountryInterface $country)
{
$this->province = $province;
$this->country = $country;
}
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$data['title'] = 'Province List';
if ($request->ajax()) {
$model = Province::query();
return DataTables::eloquent($model)
->setRowId('{{$id}}')
->setRowClass('{{"text-center align-middle"}}')
->addColumn('country', function(Province $province){
return $province?->country?->name;
})
->addColumn('action', 'admin::provinces.datatables.action-btn')
->rawColumns(['country','action'])
->toJson();
}
return view('admin::provinces.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Province';
$data['editable'] = false;
$data['countryLists'] = $this->country->pluck();
return view('admin::provinces.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
try {
$this->province->create($request->all());
return redirect()->route('province.index')->with('sucess', 'Province has been created!');
} catch (\Throwable $th) {
return redirect()->back()->withError($th->getMessage());
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('admin::provinces.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Province';
$data['editable'] = true;
$data['province'] = $this->province->getProvinceById($id);
$data['countryLists'] = $this->country->pluck();
return view('admin::provinces.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
try {
$this->province->update($id, $request->except(['_method', '_token']) );
return redirect()->route('province.index')->with('success','Province has been updated!');
} catch (\Throwable $th) {
return redirect()->back()->withError($th->getMessage());
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->province->delete($id);
return response()->json(['status' => 200, 'message' => 'Province has been deleted!'], 200);
} catch (\Throwable $th) {
return response()->json(['status' => 500, 'message' => 'Province to delete!', 'error' => $th->getMessage()], 500);
}
}
}