kevin 284d228dc5 feat(vehicle): add vehicle+convoy feature with API, models, repos, UI
Adds model, repo, controller, and request classes for Vehicle and Convoy.
Registers routes for vehicles and convoys, updates client store.
Adds front‑end files to list, add, edit vehicles.
Cleans up console logging from client store.
2026-04-15 17:27:40 +03:00

98 lines
2.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Employee extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'first_name',
'last_name',
'user_id',
'email',
'phone',
'job_title',
'hire_date',
'active',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'active' => 'boolean',
'hire_date' => 'date',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/**
* Get the thanatopractitioner associated with the employee.
*/
public function thanatopractitioner(): HasOne
{
return $this->hasOne(Thanatopractitioner::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function vehicles(): HasMany
{
return $this->hasMany(Vehicle::class, 'primary_user_id');
}
/**
* Get the full name of the employee.
*/
public function getFullNameAttribute(): string
{
return $this->first_name . ' ' . $this->last_name;
}
/**
* Scope a query to only include active employees.
*/
public function scopeActive($query)
{
return $query->where('active', true);
}
/**
* Scope a query to only include inactive employees.
*/
public function scopeInactive($query)
{
return $query->where('active', false);
}
/**
* Scope a query to search employees.
*/
public function scopeSearch($query, string $term)
{
return $query->where(function ($q) use ($term) {
$q->where('first_name', 'like', '%' . $term . '%')
->orWhere('last_name', 'like', '%' . $term . '%')
->orWhere('email', 'like', '%' . $term . '%')
->orWhere('job_title', 'like', '%' . $term . '%');
});
}
}