cek
This commit is contained in:
parent
62991b4e98
commit
d9859b8db9
@ -12,8 +12,9 @@ class OfftakerController extends Controller
|
|||||||
{
|
{
|
||||||
public function index(): JsonResponse
|
public function index(): JsonResponse
|
||||||
{
|
{
|
||||||
Gate::authorize('any',['super_admin', 'petani']);
|
if (!Gate::any(['super_admin', 'petani', 'fasilitator', 'admin'])) {
|
||||||
|
abort(403, 'Unauthorized');
|
||||||
|
}
|
||||||
$listOfftaker = Offtaker::all();
|
$listOfftaker = Offtaker::all();
|
||||||
|
|
||||||
return response()->json($listOfftaker);
|
return response()->json($listOfftaker);
|
||||||
@ -21,7 +22,7 @@ public function index(): JsonResponse
|
|||||||
|
|
||||||
public function store(Request $request): JsonResponse
|
public function store(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
Gate::authorize('super_admin');
|
Gate::authorize('any',['super_admin', 'petani']);
|
||||||
|
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'user_email' => ['required', 'email', 'max:255'],
|
'user_email' => ['required', 'email', 'max:255'],
|
||||||
@ -48,14 +49,14 @@ public function store(Request $request): JsonResponse
|
|||||||
|
|
||||||
public function show(string $id): JsonResponse
|
public function show(string $id): JsonResponse
|
||||||
{
|
{
|
||||||
Gate::authorize('super_admin');
|
Gate::authorize('any',['super_admin', 'petani']);
|
||||||
$offtaker = Offtaker::findOrFail($id);
|
$offtaker = Offtaker::findOrFail($id);
|
||||||
return response()->json($offtaker);
|
return response()->json($offtaker);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(Request $request, string $id): JsonResponse
|
public function update(Request $request, string $id): JsonResponse
|
||||||
{
|
{
|
||||||
Gate::authorize('super_admin');
|
Gate::authorize('any',['super_admin', 'petani']);
|
||||||
$offtaker = Offtaker::findOrFail($id);
|
$offtaker = Offtaker::findOrFail($id);
|
||||||
|
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
@ -73,8 +74,7 @@ public function update(Request $request, string $id): JsonResponse
|
|||||||
|
|
||||||
public function destroy(string $id): JsonResponse
|
public function destroy(string $id): JsonResponse
|
||||||
{
|
{
|
||||||
Gate::authorize('super_admin');
|
Gate::authorize('any',['super_admin', 'petani']);
|
||||||
// Menggunakan Soft Delete (Eloquent otomatis handle karena ada trait SoftDeletes di model)
|
|
||||||
Offtaker::findOrFail($id)->delete();
|
Offtaker::findOrFail($id)->delete();
|
||||||
|
|
||||||
return response()->json(null, 204);
|
return response()->json(null, 204);
|
||||||
@ -85,7 +85,7 @@ public function destroy(string $id): JsonResponse
|
|||||||
*/
|
*/
|
||||||
public function batchUpsert(Request $request): JsonResponse
|
public function batchUpsert(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
Gate::authorize('super_admin');
|
Gate::authorize('any',['super_admin', 'petani']);
|
||||||
|
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'offtakers' => ['required', 'array'],
|
'offtakers' => ['required', 'array'],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user