Files
online.tbbank.gov.tm-larave…/app/Modules/Branch/Controllers/BranchController.php
2024-09-10 01:19:58 +05:00

36 lines
810 B
PHP

<?php
namespace App\Modules\Branch\Controllers;
use App\Http\Controllers\Controller;
use App\Models\Branch\Branch;
use Illuminate\Http\Request;
class BranchController extends Controller
{
/**
* LIST branches
*/
public function index(Request $request)
{
$request->validate([
'groupBy' => ['nullable', 'string', 'in:region'],
]);
$branches = Branch::query()
->where('active', true)
->get()
->map(fn ($branch) => [
'id' => $branch->id,
'name' => $branch->name,
'region' => $branch->region,
]);
if ($request->filled('groupBy')) {
$branches = $branches->groupBy('region');
}
return response()->json($branches);
}
}