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,141 @@
<?php
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Modules\Client\Repositories\ClientInterface;
use Modules\Content\Interfaces\ContentInterface;
use Modules\Content\Models\Content;
use Modules\Meeting\Models\Event;
use Modules\Meeting\Models\Meeting;
use Modules\Meeting\Repositories\EventInterface;
use Modules\Meeting\Repositories\MeetingInterface;
use Modules\Product\Interfaces\ProductInterface;
class CalendarController extends Controller
{
private $event;
private $content;
private $meeting;
private $employee;
private $client;
private $product;
public function __construct(
EventInterface $event,
MeetingInterface $meeting,
ContentInterface $content,
ProductInterface $product,
ClientInterface $client
) {
$this->event = $event;
$this->meeting = $meeting;
$this->content = $content;
$this->client = $client;
$this->product = $product;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Calendar';
$data['events'] = $this->event->findAll();
$data['meetings'] = $this->meeting->findAll();
$data['contents'] = $this->content->findAllUpcomingScheduledContent();
$data['productOptions'] = $this->product->pluck();
$data['clientList'] = $this->client->pluck();
return view('admin::calendar.index', $data);
}
public function calendarByAjax(Request $request)
{
$filters['start_date'] = $request->start;
$filters['end_date'] = $request->end;
$filters['product_id'] = $request->product_id;
$list = [];
$events = Event::when($filters, function ($query) use ($filters) {
if (isset($filters["start_date"])) {
$query->whereDate("start_date", ">=", $filters["start_date"]);
}
if (isset($filters["end_date"])) {
$query->whereDate("end_date", "<=", $filters["end_date"]);
$query->orWhereNull("end_date");
}
})->get();
foreach ($events as $event) {
$list[] = [
"id" => $event->id,
"title" => $event->title,
"type" => 'event',
"start" => $event->start_date,
"end" => $event->end_date,
"className" => "bg-primary",
"desc" => $event->description,
"location" => $event->location,
'allDay' => true,
];
}
$contents = Content::where('status', '!=', 11)
->when($filters, function ($query) use ($filters) {
if (isset($filters["start_date"])) {
$query->whereDate("release_date", ">=", $filters["start_date"]);
}
if (isset($filters["end_date"])) {
$query->where(function ($q) use ($filters) {
$q->whereDate("release_date", "<=", $filters["end_date"])
->orWhereNull("release_date");
});
}
if (isset($filters["product_id"])) {
$query->where("product_id", $filters["product_id"]);
}
})
->with(['product.client'])
->get();
foreach ($contents as $content) {
$list[] = [
"id" => $content->id,
"title" => $content->title,
"type" => 'content schedule',
"start" => Carbon::parse($content->getRawOriginal('release_date') . ' ' . $content->getRawOriginal('release_time')),
"end" => null,
"className" => "bg-success",
"location" => null,
"desc" => $content->product?->client?->name,
'allDay' => false,
];
}
$meetings = Meeting::when($filters, function ($query) use ($filters) {
if (isset($filters["start_date"])) {
$query->whereDate("date", ">=", $filters["start_date"]);
}
})->get();
foreach ($meetings as $meeting) {
$list[] = [
"id" => $meeting->id,
"title" => $meeting->title,
"type" => 'meeting',
"start" => Carbon::parse($meeting->getRawOriginal('date') . ' ' . $meeting->getRawOriginal('start_time')),
"location" => $meeting->location,
"desc" => $meeting->description,
"className" => "bg-warning",
'allDay' => false,
];
}
return $list;
}
}

View File

@@ -0,0 +1,83 @@
<?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\Repositories\CityRepository;
class CityController extends Controller
{
private $cityRepository;
public function __construct(CityRepository $cityRepository)
{
$this->cityRepository = $cityRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'City List';
$data['cityLists'] = $this->cityRepository->findAll();
return view('admin::cities.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create City';
$data['editable'] = false;
return view('admin::cities.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$this->cityRepository->create($request->all());
return redirect()->route('city.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('admin::cities.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit City';
$data['editable'] = true;
$data['city'] = $this->cityRepository->getCityById($id);
return view('admin::cities.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$this->cityRepository->update($id, $request->all());
return redirect()->route('city.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
//
}
}

View File

@@ -0,0 +1,102 @@
<?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\Country;
use Modules\Admin\Repositories\CountryInterface;
use Yajra\DataTables\Facades\DataTables;
class CountryController extends Controller
{
private $country;
public function __construct(CountryInterface $country)
{
$this->country = $country;
}
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$data['title'] = 'Country List';
$data['countries'] = $this->country->findAll();
if ($request->ajax()) {
$model = Country::query();
return DataTables::eloquent($model)
->setRowId('{{$id}}')
->setRowClass('{{"text-center align-middle"}}')
->addColumn('action', 'admin::countries.datatables.action-btn')
->rawColumns(['action'])
->toJson();
}
return view('admin::countries.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Country';
$data['editable'] = false;
return view('admin::countries.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$this->country->create($request->all());
return redirect()->route('country.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('admin::countries.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Country';
$data['editable'] = true;
$data['country'] = $this->country->getCountryById($id);
return view('admin::countries.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$this->country->update($id, $request->except(['_method', '_token']));
return redirect()->route('country.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->country->delete($id);
return response()->json(['status' => 200, 'message' => 'Country has been deleted!'], 200);
} catch (\Throwable $th) {
return response()->json(['status' => 500, 'message' => 'Country to delete!', 'error' => $th->getMessage()], 500);
}
}
}

View File

@@ -0,0 +1,112 @@
<?php
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Admin\Models\Department;
use Modules\Admin\Repositories\DepartmentRepository;
use Modules\Employee\Repositories\EmployeeRepository;
class DepartmentController extends Controller
{
private $departmentRepository;
private $employeeRepository;
public function __construct(DepartmentRepository $departmentRepository,
EmployeeRepository $employeeRepository) {
$this->departmentRepository = $departmentRepository;
$this->employeeRepository = $employeeRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
// toastr()
// ->info('Welcome back')
// ->success('Data has been saved successfully!')
// ->warning('Are you sure you want to proceed ?');
$data['title'] = 'Department List';
$data['departmentLists'] = $this->departmentRepository->findAll();
return view('admin::departments.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
// toastr('Department has been created!', 'success');
$data['title'] = 'Create Department';
$data['editable'] = false;
$data['employeeLists'] = $this->employeeRepository->pluck();
return view('admin::departments.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
// try {
$this->departmentRepository->create($request->all());
// toastr()->success('Department has been created!');
// } catch (\Throwable $th) {
// toastr()->error($th->getMessage());
// }
// toastr('Department has been created!', 'success');
// return back();
return redirect()->route('department.index')->with('sucess', 'adw');
}
/**
* Show the specified resource.
*/
public function show(Department $department)
{
$data['department'] = $department;
return view('admin::departments.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Department';
$data['editable'] = true;
$data['employeeLists'] = $this->employeeRepository->pluck();
$data['department'] = $this->departmentRepository->getDepartmentById($id);
return view('admin::departments.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request,Department $department): RedirectResponse
{
// dd($request->all())
try {
$department->update($request->except(['_token', '_method']));
// $this->departmentRepository->update($id, $request->except(['_token', '_method']));
toastr()->success('Department has been updated!');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('department.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$this->departmentRepository->delete($id);
toastr()->success('Department Deleted Succesfully');
return response()->json(['status' => true, 'message' => 'Department Delete Succesfully']);
}
}

View File

@@ -0,0 +1,100 @@
<?php
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Admin\Repositories\DesignationRepository;
use Modules\Admin\Services\AdminService;
class DesignationController extends Controller
{
private $designationRepository;
private $adminService;
public function __construct(DesignationRepository $designationRepository, AdminService $adminService)
{
$this->designationRepository = $designationRepository;
$this->adminService = $adminService;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Designation List';
$data['designationLists'] = $this->designationRepository->findAll();
return view('admin::designations.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Designation';
$data['editable'] = false;
$data['departmentList'] = $this->adminService->pluckDepartments();
return view('admin::designations.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$data = $request->except(['_method', '_token']);
$this->designationRepository->create($data);
flash()->addSuccess('Department Data Created!');
return redirect()->route('designation.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('admin::designations.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Designation';
$data['editable'] = true;
$data['designation'] = $this->designationRepository->getDesignationById($id);
$data['departmentList'] = $this->adminService->pluckDepartments();
return view('admin::designations.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$data = $request->except(['_method', '_token']);
$desgination = $this->designationRepository->getDesignationById($id);
$desgination->update($data);
flash()->addSuccess('Department Data Updated!');
return redirect()->route('designation.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$this->designationRepository->delete($id);
flash()->addSuccess('Designation Deleted Succesfully');
return response()->json(['status' => true, 'message' => 'Designation Delete Succesfully']);
}
}

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

View File

@@ -0,0 +1,113 @@
<?php
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Admin\Repositories\DropdownInterface;
use Modules\Admin\Repositories\FieldInterface;
class DropdownController extends Controller
{
private $fieldRepository;
private $dropdownRepository;
public function __construct(FieldInterface $fieldRepository,
DropdownInterface $dropdownRepository) {
$this->fieldRepository = $fieldRepository;
$this->dropdownRepository = $dropdownRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['editable'] = false;
$data['title'] = 'Dropdown List';
$data['fields'] = $this->fieldRepository->findAll();
$data['fieldLists'] = $data['fields']->pluck('title', 'id');
return view('admin::dropdown.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('admin::create');
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
try {
// $inputData['status'] = $request->status ?? 10;
$this->dropdownRepository->create($inputData);
toastr()->success('Dropdown Created Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('dropdown.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('admin::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$editable = true;
$dropdownModel = $this->dropdownRepository->getDropdownById($id);
$fieldLists = $this->fieldRepository->getList();
return response()->json([
'view' => view('admin::dropdown.edit', compact('dropdownModel', 'fieldLists', 'editable'))->render(),
'status' => true,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
try {
$inputData['status'] = $request->status ?? 10;
$this->dropdownRepository->update($id, $inputData);
toastr()->success('Dropdown Update Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('dropdown.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->dropdownRepository->delete($id);
toastr()->success('Dropdown Deleted Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json([
'status' => true,
]);
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Admin\Repositories\DropdownInterface;
use Modules\Admin\Repositories\FieldInterface;
class FieldController extends Controller
{
private $fieldRepository;
private $dropdownRepository;
public function __construct(FieldInterface $fieldRepository,
DropdownInterface $dropdownRepository) {
$this->fieldRepository = $fieldRepository;
$this->dropdownRepository = $dropdownRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
return view('admin::index');
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('admin::create');
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
try {
$this->fieldRepository->create($inputData);
toastr()->success('Field Created Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('dropdown.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('admin::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
return view('admin::edit');
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
//
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class FileController extends Controller
{
/**
* Display a listing of the resource.
*/
public function upload()
{
if (request()->hasFile('upload')) {
$file = request()->file('upload');
$path = 'uploads/ckeditor';
$imagePath = uploadImage($file, $path);
$CKEditorFuncNum = request()->input('CKEditorFuncNum');
$url = asset('storage/' . $imagePath);
$response = "<script>window.parent.CKEDITOR.tools.callFunction($CKEditorFuncNum, '$url')</script>";
echo $response;
}
}
}

View File

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

View File

@@ -0,0 +1,45 @@
<?php
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$data['notifications'] = auth()->user()->notifications;
return view('notification.index', $data);
}
public function markAsRead(Request $request)
{
$filterData = $request->all();
try {
$notification = auth()->user()->notifications()->where('id', $filterData['id'])->first();
if ($notification) {
$notification->markAsRead();
}
return redirect()->back()->withSuccess('Mark As Read');
} catch (\Throwable $th) {
return redirect()->back()->withError('Something Went Wrong!');
}
}
public function markAllAsRead(Request $request)
{
try {
foreach (auth()->user()->unreadNotifications as $notification) {
$notification->markAsRead();
}
return redirect()->back()->withSuccess('Mark All As Read');
} catch (\Throwable $th) {
//throw $th;
return redirect()->back()->withError('Something Went Wrong!');
}
}
}

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);
}
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace Modules\Admin\Http\Controllers;
use Cache;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\Admin\Models\Setting;
use Modules\Admin\Repositories\SettingInterface;
class SettingController extends Controller
{
private $setting;
/**
* Display a listing of the resource.
*/
public function __construct(SettingInterface $setting)
{
$this->setting = $setting;
}
public function index()
{
$data['title'] = "Edit Setting";
$data['editable'] = true;
$data['setting'] = $this->setting->findAll();
return view('admin::settings.edit', $data);
}
public function store(Request $request): RedirectResponse
{
try {
$input = $request->except([
'_method',
'_token',
]);
if ($request->hasFile('logo_pic')) {
$input['logo_pic'] = uploadImage($request->logo_pic);
}
foreach ($input as $key => $item) {
$finalInput = [
'key' => $key,
'value' => $item,
];
Setting::updateOrInsert(['key' => $key], $finalInput);
}
Cache::has('setting') ? Cache::forget('setting') : '';
return redirect()->route('setting.index')->with('success', 'Setting Updated');
} catch (\Throwable $th) {
return redirect()->back()->withError($th->getMessage());
}
}
public function destroy($id)
{
$this->setting->delete($id);
return response()->json(['status' => true]);
}
}