feat: implement API endpoint for getting all internships for admins

This commit is contained in:
Veronika Fehérvíziová
2025-10-31 20:43:01 +01:00
parent 1683155ae3
commit 1ae81221a5

View File

@@ -10,6 +10,39 @@ use Illuminate\Http\Request;
class InternshipController extends Controller
{
public function all()
{
$user = auth()->user();
if ($user->role !== 'ADMIN') {
abort(403, 'Unauthorized');
}
$internships = Internship::all()->makeHidden(['created_at', 'updated_at']);
$internships->each(function ($internship) {
$internship->user = User::find($internship->user_id)->makeHidden(['created_at', 'updated_at', 'email_verified_at']);
unset($internship->user_id);
});
$internships->each(function ($internship) {
$internship->company = Company::find($internship->company_id)->makeHidden(['created_at', 'updated_at']);
unset($internship->company_id);
});
$internships->each(function ($internship) {
$internship->contact = User::find($internship->company->contact)->makeHidden(['created_at', 'updated_at', 'email_verified_at']);
unset($internship->company->contact);
});
$internships->each(function ($internship) {
$internship->status = InternshipStatus::whereColumn('internship_id', '=', $internship->id)->get()->first()->makeHidden(['created_at', 'updated_at', 'id']);
$internship->status->modified_by = User::find($internship->status->modified_by)->makeHidden(['created_at', 'updated_at', 'email_verified_at']);
});
return response()->json($internships);
}
public function all_student()
{
$internships = Internship::where('user_id', auth()->id())->get()->makeHidden(['created_at', 'updated_at']);