<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ModelloVeicolo extends Model
{
    use HasFactory;

public $timestamps = false;
    protected $table = 'fcf_reports_modello_veicolo';

    protected $fillable = [
        'name'
    ];

    public function marca()
    {
        $rel = \App\Models\MarcaModelloVeicolo::where('modello_id', $this->id)->first();
        if ($rel)
        {
            if ($rel->marca_id > 0)
            {
                try
                {
                    return \App\Models\MarcaVeicolo::where('id', $rel->marca_id)->first() ? \App\Models\MarcaVeicolo::where('id', $rel->marca_id)->first()->name : "";
                }
                catch (Exception $ex)
                {
                    return "";
                }
            }
            else
                return "";
        }
        else
            return "";
    }


}
