Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dominiquevienne/1245457ea42a1ab95738a7977cd538df to your computer and use it in GitHub Desktop.
Save dominiquevienne/1245457ea42a1ab95738a7977cd538df to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateLicensesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('licenses', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('vehicle_id');
$table->string('license_number');
// Anything you want to describe the license (country, fees, ... )
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('licenses');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateVehiclesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('vehicles', function (Blueprint $table) {
$table->id();
$table->string('vehicle_type');
$table->string('brand');
// Anything you want to describe the vehicle
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('vehicles');
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class License extends Model
{
use HasFactory;
protected $fillable = [
'license_number',
/** Anything related to a license number */
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function vehicle()
{
return $this->belongsTo(Vehicle::class);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Vehicle extends Model
{
use HasFactory;
protected $fillable = [
'vehicle_type',
'brand',
/** Everything you would need about a vehicle */
];
/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function license()
{
return $this->hasOne(License::class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment