80 lines
2.1 KiB
PHP
80 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class CareerApplication extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'phone',
|
|
'type',
|
|
'cv_path',
|
|
'nda_path',
|
|
'contract_path',
|
|
'id_photocopy_path',
|
|
'git_knowledge',
|
|
'ai_usage',
|
|
'message',
|
|
'status',
|
|
'username',
|
|
'password',
|
|
'signed_internship_form_path',
|
|
'to_be_signed_internship_form_path',
|
|
'internship_start_date',
|
|
'internship_end_date',
|
|
'internship_total_days',
|
|
'github_repo',
|
|
'certificate_code',
|
|
'transcript_markdown',
|
|
'notebook_supervisor_signed',
|
|
'notebook_supervisor_name',
|
|
'notebook_unit_signed',
|
|
'notebook_unit_name',
|
|
'notebook_approved',
|
|
];
|
|
|
|
/**
|
|
* Get the journal entries for the internship application.
|
|
*/
|
|
public function journalEntries()
|
|
{
|
|
return $this->hasMany(InternshipJournalEntry::class);
|
|
}
|
|
|
|
protected static function booted()
|
|
{
|
|
static::saving(function ($model) {
|
|
if ($model->type === 'internship') {
|
|
$model->username = $model->email;
|
|
if (!$model->certificate_code) {
|
|
do {
|
|
$code = 'TRN-' . date('Y') . '-' . strtoupper(\Illuminate\Support\Str::random(4)) . '-' . strtoupper(\Illuminate\Support\Str::random(4));
|
|
} while (static::where('certificate_code', $code)->exists());
|
|
$model->certificate_code = $code;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'password' => 'hashed',
|
|
'notebook_supervisor_signed' => 'boolean',
|
|
'notebook_unit_signed' => 'boolean',
|
|
'notebook_approved' => 'boolean',
|
|
];
|
|
}
|
|
}
|