-
app/Http/Resources/ClassroomResource.php
Open in GitHubuse Illuminate\Http\Resources\Json\JsonResource; class ClassroomResource extends JsonResource { public function toArray($request) { return [ 'id' => $this->id, 'name' => $this->name, 'slug' => $this->slug, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'subjects' => SubjectResource::collection($this->whenLoaded('subjects')), ]; } }
-
app/Http/Controllers/Admin/AdminClassController.php
Open in GitHubuse App\Http\Controllers\RespondsWithHttpStatusController; use App\Http\Resources\ClassroomResource; use Illuminate\Http\Request; class AdminClassController extends RespondsWithHttpStatusController { public function index(Request $request) { $classrooms = QueryBuilder::for(Classroom::class) ->withTrashed() ->defaultSort('-created_at') ->allowedSorts(['name','status']) ->allowedFilters(['name']) ->jsonPaginate() ->appends($request->query()); return $this->respond([ 'classrooms' => ClassroomResource::collection($classrooms)->response()->getData(true) ]); } // }