You've already forked isop-mirror
fix: add hidden attributes for serialization in models and update contact method in Company model
This commit is contained in:
@@ -23,6 +23,16 @@ class Company extends Model
|
||||
'hiring'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the internships for the company.
|
||||
*/
|
||||
@@ -34,7 +44,7 @@ class Company extends Model
|
||||
/**
|
||||
* Get the contact person (user) for the company.
|
||||
*/
|
||||
public function contactPerson()
|
||||
public function contact()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'contact');
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
@@ -28,6 +29,16 @@ class Internship extends Model
|
||||
'report_confirmed',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
@@ -49,4 +60,32 @@ class Internship extends Model
|
||||
{
|
||||
return $this->belongsTo(Company::class, 'company_id');
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->hasOne(InternshipStatus::class, 'internship_id')->latestOfMany();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the model for JSON serialization.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'student' => $this->student,
|
||||
'company' => $this->company,
|
||||
'start' => Carbon::parse($this->start)->format('d.m.Y'),
|
||||
'end' => Carbon::parse($this->end)->format('d.m.Y'),
|
||||
'year_of_study' => $this->year_of_study,
|
||||
'semester' => $this->semester,
|
||||
'position_description' => $this->position_description,
|
||||
'agreement' => $this->agreement !== null,
|
||||
'report' => $this->report !== null,
|
||||
'report_confirmed' => $this->report_confirmed,
|
||||
'status' => $this->status,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,31 @@ class InternshipStatus extends Model
|
||||
'note',
|
||||
'modified_by'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
public function modifiedBy()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'modified_by');
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'internship_id' => $this->internship_id,
|
||||
'status' => $this->status,
|
||||
'changed' => $this->changed,
|
||||
'note' => $this->note,
|
||||
'modified_by' => $this->modifiedBy,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,14 @@ class StudentData extends Model
|
||||
'personal_email',
|
||||
'study_field',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -39,6 +39,11 @@ class User extends Authenticatable
|
||||
'password',
|
||||
'remember_token',
|
||||
'activation_token',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'email_verified_at',
|
||||
'active',
|
||||
'needs_password_change'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user