- Complete GGZ Ecademy Laravel backend application - RESTful API for learning products, members, filters - Authentication and authorization system - Database migrations and seeders - Custom CRUD generator commands - Email notification system - Integration with frontend applications
This commit is contained in:
62
app/Http/Controllers/BranchController.php
Normal file
62
app/Http/Controllers/BranchController.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\BranchService;
|
||||
use App\Http\Requests\Member\BranchStore;
|
||||
|
||||
class BranchController extends Controller
|
||||
{
|
||||
|
||||
private $branchService;
|
||||
|
||||
public function __construct(BranchService $branchService)
|
||||
{
|
||||
$this->branchService = $branchService;
|
||||
|
||||
$this->middleware('auth:sanctum');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$branches = $this->branchService->getAll();
|
||||
|
||||
return response()->json($branches, 201);
|
||||
}
|
||||
|
||||
public function store(BranchStore $request)
|
||||
{
|
||||
$isSuperAdmin = auth()->user()->hasRole('super_admin');
|
||||
$isAdmin = auth()->user()->hasRole('admin');
|
||||
$isOperator = auth()->user()->hasRole('operator');
|
||||
|
||||
if (!$isSuperAdmin && !$isAdmin && !$isOperator) {
|
||||
return response()->json(['message' => 'You have no rights to do this'], 401);
|
||||
}
|
||||
|
||||
$branch = $this->branchService->save($request->all());
|
||||
|
||||
return response()->json($branch, 201);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$branch = $this->branchService->get($id);
|
||||
|
||||
return response()->json($branch);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$isSuperAdmin = auth()->user()->hasRole('super_admin');
|
||||
$isAdmin = auth()->user()->hasRole('admin');
|
||||
$isOperator = auth()->user()->hasRole('operator');
|
||||
|
||||
if (!$isSuperAdmin && !$isAdmin && !$isOperator) {
|
||||
return response()->json(['message' => 'You have no rights to do this'], 401);
|
||||
}
|
||||
|
||||
$this->branchService->delete($id);
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user