Skip to main content

Overview

The Vehiculo model represents vehicles in the VIP2CARS system. It stores vehicle details such as license plate, make, model, and year, and maintains the relationship with the vehicle’s owner (Cliente).

Database Configuration

table
string
default:"vehiculos"
Database table name
primaryKey
string
default:"id_vehiculo"
Primary key column name

Fillable Attributes

The following attributes can be mass-assigned:
placa
string
required
Vehicle’s license plate number
marca
string
required
Vehicle’s brand/manufacturer (e.g., Toyota, Ford, Honda)
modelo
string
required
Vehicle’s model name
anio_fabricacion
numeric
required
Year of manufacture (4-digit format)
id_cliente
integer
required
Foreign key referencing the owner (Cliente)

Relationships

cliente()

Defines a many-to-one relationship with the Cliente model. Each vehicle belongs to one client. Relationship Type: belongsTo Related Model: App\Models\Cliente Foreign Key: id_cliente Owner Key: id_cliente
public function cliente()
{
    return $this->belongsTo(Cliente::class, 'id_cliente', 'id_cliente');
}

Usage Examples

use App\Models\Vehiculo;

$vehiculo = Vehiculo::create([
    'placa' => 'ABC-123',
    'marca' => 'Toyota',
    'modelo' => 'Corolla',
    'anio_fabricacion' => 2023,
    'id_cliente' => 1,
]);

Model Source

Location: app/Models/Vehiculo.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Vehiculo extends Model
{
    protected $table = 'vehiculos';
    protected $primaryKey = 'id_vehiculo';

    protected $fillable = [
        'placa',
        'marca',
        'modelo',
        'anio_fabricacion',
        'id_cliente',
    ];

    public function cliente()
    {
        return $this->belongsTo(Cliente::class, 'id_cliente', 'id_cliente');
    }
}

Build docs developers (and LLMs) love