Skip to content

Commit

Permalink
foreign keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Thombrix committed Oct 29, 2023
1 parent 4f1d172 commit 66dabe9
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 0 deletions.
10 changes: 10 additions & 0 deletions backend-laravel/app/Models/Canton.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@
class Canton extends Model
{
use HasFactory;

protected $fillable = [
'name',
'img'
];

public function villes()
{
return $this->hasOne(Canton::class);
}
}
7 changes: 7 additions & 0 deletions backend-laravel/app/Models/Cycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@

class Cycle extends Model
{

protected $fillable = [
'shuffledList',
'index',
'count'
];

use HasFactory;
}
9 changes: 9 additions & 0 deletions backend-laravel/app/Models/Langue.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@
class Langue extends Model
{
use HasFactory;

protected $fillable = [
'name'
];

public function villes()
{
return $this->belongsToMany(Ville::class);
}
}
20 changes: 20 additions & 0 deletions backend-laravel/app/Models/Ville.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,24 @@
class Ville extends Model
{
use HasFactory;

protected $fillable = [
'name',
'img',
'ecusson',
'population',
'coord',
'canton_id'
];


public function canton()
{
return $this->belongsTo(Canton::class);
}

public function langues()
{
return $this->belongsToMany(Langue::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('villes', function (Blueprint $table) {

$table->foreignId('canton_id')->constrained()->cascadeOnDelete();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('villes', function (Blueprint $table) {

$table->dropForeign(['canton_id']);
$table->dropColumn('canton_id');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('langues_villes', function (Blueprint $table) {

$table->foreignId('langue_id')->constrained()->cascadeOnDelete();
$table->foreignId('ville_id')->constrained()->cascadeOnDelete();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('langues_villes', function (Blueprint $table) {

$table->dropForeign(['langue_id']);
$table->dropColumn('langue_id');

$table->dropForeign(['ville_id']);
$table->dropColumn('ville_id');
});
}
};

0 comments on commit 66dabe9

Please sign in to comment.