2023-04-14 02:14:37 +00:00
|
|
|
<?php
|
|
|
|
|
2023-05-15 11:15:36 +00:00
|
|
|
namespace Modules\CetakLabel\Http\Controllers;
|
2023-04-14 02:14:37 +00:00
|
|
|
|
2023-05-15 11:15:36 +00:00
|
|
|
use App\Http\Controllers\Controller;
|
2023-05-05 00:54:31 +00:00
|
|
|
use Exception;
|
2023-05-15 11:15:36 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Modules\CetakLabel\DataTables\SpecialCodeDataTable;
|
|
|
|
use Modules\CetakLabel\Entities\SpecialCode;
|
|
|
|
use Modules\CetakLabel\Http\Requests\SpecialCode\StoreSpecialCodeRequest;
|
|
|
|
use Modules\CetakLabel\Http\Requests\SpecialCode\UpdateSpecialCodeRequest;
|
2023-04-14 02:14:37 +00:00
|
|
|
|
2023-05-15 11:15:36 +00:00
|
|
|
class SpecialCodeController extends Controller
|
2023-04-14 02:14:37 +00:00
|
|
|
{
|
2023-05-05 00:54:31 +00:00
|
|
|
public $user;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware(function ($request, $next) {
|
|
|
|
$this->user = Auth::guard('web')->user();
|
|
|
|
return $next($request);
|
|
|
|
});
|
|
|
|
}
|
2023-04-14 02:14:37 +00:00
|
|
|
|
2023-05-05 00:54:31 +00:00
|
|
|
/**
|
2023-05-15 11:15:36 +00:00
|
|
|
* Display a listing of the resource.
|
2023-05-05 00:54:31 +00:00
|
|
|
*/
|
2023-05-15 11:15:36 +00:00
|
|
|
public function index(SpecialCodeDataTable $dataTable)
|
2023-05-05 00:54:31 +00:00
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('masters.read')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
|
|
|
}
|
|
|
|
|
2023-05-15 11:15:36 +00:00
|
|
|
return $dataTable->render('cetaklabel::masters.special-code.index');
|
2023-04-14 02:14:37 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 00:54:31 +00:00
|
|
|
/**
|
2023-05-15 11:15:36 +00:00
|
|
|
* Store a newly created resource in storage.
|
2023-05-05 00:54:31 +00:00
|
|
|
*/
|
2023-05-15 11:15:36 +00:00
|
|
|
public function store(StoreSpecialCodeRequest $request)
|
2023-05-05 00:54:31 +00:00
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('masters.create')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to create any master data !');
|
|
|
|
}
|
2023-04-14 02:14:37 +00:00
|
|
|
|
2023-05-15 11:15:36 +00:00
|
|
|
|
2023-05-05 00:54:31 +00:00
|
|
|
// Validate the request...
|
|
|
|
$validated = $request->validated();
|
|
|
|
|
2023-05-15 11:15:36 +00:00
|
|
|
// Store the Special Code...
|
2023-05-05 00:54:31 +00:00
|
|
|
if ($validated) {
|
|
|
|
try {
|
2023-05-15 11:15:36 +00:00
|
|
|
SpecialCode::create($validated);
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Special Code created successfully.']);
|
2023-05-05 00:54:31 +00:00
|
|
|
} catch (Exception $e) {
|
2023-05-15 11:15:36 +00:00
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Special Code created failed.']);
|
2023-05-05 00:54:31 +00:00
|
|
|
}
|
2023-05-15 11:15:36 +00:00
|
|
|
|
|
|
|
return;
|
2023-05-05 00:54:31 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 11:15:36 +00:00
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Special Code created failed.']);
|
2023-05-05 00:54:31 +00:00
|
|
|
}
|
2023-04-14 02:14:37 +00:00
|
|
|
|
2023-05-05 00:54:31 +00:00
|
|
|
/**
|
2023-05-15 11:15:36 +00:00
|
|
|
* Show the form for creating a new resource.
|
2023-05-05 00:54:31 +00:00
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('masters.create')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to create any master data !');
|
|
|
|
}
|
2023-04-14 02:14:37 +00:00
|
|
|
|
2023-05-15 11:15:36 +00:00
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*/
|
|
|
|
public function show(SpecialCode $special_code)
|
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('masters.read')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
abort(404);
|
2023-04-14 02:14:37 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 00:54:31 +00:00
|
|
|
/**
|
2023-05-15 11:15:36 +00:00
|
|
|
* Show the form for editing the specified resource.
|
2023-05-05 00:54:31 +00:00
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('masters.update')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to update any master data !');
|
|
|
|
}
|
2023-04-14 02:14:37 +00:00
|
|
|
|
2023-05-15 11:15:36 +00:00
|
|
|
$special_code = SpecialCode::find($id);
|
|
|
|
echo json_encode($special_code);
|
2023-05-05 00:54:31 +00:00
|
|
|
}
|
2023-04-14 02:14:37 +00:00
|
|
|
|
2023-05-05 00:54:31 +00:00
|
|
|
/**
|
2023-05-15 11:15:36 +00:00
|
|
|
* Update the specified resource in storage.
|
2023-05-05 00:54:31 +00:00
|
|
|
*/
|
2023-05-15 11:15:36 +00:00
|
|
|
public function update(UpdateSpecialCodeRequest $request, SpecialCode $special_code)
|
2023-05-05 00:54:31 +00:00
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('masters.update')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to update any master data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate the request...
|
|
|
|
$validated = $request->validated();
|
|
|
|
|
2023-05-15 11:15:36 +00:00
|
|
|
// Update the Directorat...
|
2023-05-05 00:54:31 +00:00
|
|
|
if ($validated) {
|
|
|
|
try {
|
2023-05-15 11:15:36 +00:00
|
|
|
$special_code->update($validated);
|
|
|
|
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Special Code updated successfully.']);
|
2023-05-05 00:54:31 +00:00
|
|
|
} catch (Exception $e) {
|
2023-05-15 11:15:36 +00:00
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Special Code updated failed.']);
|
2023-05-05 00:54:31 +00:00
|
|
|
}
|
2023-05-15 11:15:36 +00:00
|
|
|
|
|
|
|
return;
|
2023-04-14 02:14:37 +00:00
|
|
|
}
|
2023-05-05 00:54:31 +00:00
|
|
|
|
2023-05-15 11:15:36 +00:00
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Special Code updated failed.']);
|
2023-04-14 02:14:37 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 00:54:31 +00:00
|
|
|
/**
|
2023-05-15 11:15:36 +00:00
|
|
|
* Remove the specified resource from storage.
|
2023-05-05 00:54:31 +00:00
|
|
|
*/
|
2023-05-15 11:15:36 +00:00
|
|
|
public function destroy(SpecialCode $special_code)
|
2023-05-05 00:54:31 +00:00
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('masters.delete')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to delete any master data !');
|
|
|
|
}
|
2023-04-14 02:14:37 +00:00
|
|
|
|
2023-05-15 11:15:36 +00:00
|
|
|
$special_code->delete();
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Special Code deleted successfully.']);
|
2023-05-05 00:54:31 +00:00
|
|
|
}
|
2023-04-14 02:14:37 +00:00
|
|
|
}
|