-
app/Models/Office.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; class Office extends Model { use HasFactory, SoftDeletes; const APPROVAL_PENDING = 1; const APPROVAL_APPROVED = 2; protected $casts = [ // 'approval_status' => 'integer', // ]; // }
-
app/Http/Controllers/OfficeController.php
Open in GitHubuse App\Http\Resources\OfficeResource; use App\Models\Office; use Illuminate\Http\Resources\Json\JsonResource; class OfficeController extends Controller { public function index(): JsonResource { $offices = Office::query() ->when(request('user_id') && auth()->user() && request('user_id') == auth()->id(), fn($builder) => $builder, fn($builder) => $builder->where('approval_status', Office::APPROVAL_APPROVED)->where('hidden', false) ) // ->paginate(20); return OfficeResource::collection( $offices ); }