clara/app/Http/Controllers/SpecialCodeController.php

119 lines
3.2 KiB
PHP
Raw Normal View History

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