fix: add hidden attributes for serialization in models and update contact method in Company model

This commit is contained in:
2025-11-06 15:54:54 +01:00
parent cd7e39eccb
commit 6eadf3a944
5 changed files with 92 additions and 1 deletions

View File

@@ -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,
];
}
}