You've already forked isop-mirror
feat: implement API endpoint for getting all internships for admins
This commit is contained in:
@@ -10,6 +10,39 @@ use Illuminate\Http\Request;
|
|||||||
|
|
||||||
class InternshipController extends Controller
|
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()
|
public function all_student()
|
||||||
{
|
{
|
||||||
$internships = Internship::where('user_id', auth()->id())->get()->makeHidden(['created_at', 'updated_at']);
|
$internships = Internship::where('user_id', auth()->id())->get()->makeHidden(['created_at', 'updated_at']);
|
||||||
|
|||||||
Reference in New Issue
Block a user