Created
January 29, 2022 16:13
-
-
Save dominiquevienne/1245457ea42a1ab95738a7977cd538df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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