feat: add internship retrieval and display functionality

This commit is contained in:
2025-10-23 14:16:13 +02:00
parent 2693e0a755
commit 94a5776cbc
5 changed files with 174 additions and 3 deletions

View File

@@ -2,11 +2,36 @@
namespace App\Http\Controllers;
use App\Models\Company;
use App\Models\Internship;
use App\Models\InternshipStatus;
use App\Models\User;
use Illuminate\Http\Request;
class InternshipController extends Controller
{
public function all()
{
$internships = Internship::where('user_id', auth()->id())->get()->makeHidden(['created_at', 'updated_at']);
$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);
}
/**
* Display a listing of the resource.
*/

View File

@@ -1,6 +1,7 @@
<?php
use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\InternshipController;
use App\Models\Company;
use App\Models\StudentData;
use Illuminate\Http\Request;
@@ -20,4 +21,6 @@ Route::middleware(['auth:sanctum'])->get('/user', function (Request $request) {
Route::post('/password-reset', [RegisteredUserController::class, 'reset_password'])
->middleware(['guest', 'throttle:6,1'])
->name('password.reset');
->name('password.reset');
Route::get('/internships', [InternshipController::class, 'all'])->middleware(['auth'])->name("api.internships");