Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Schema::create('contatto_indirizzi', function (Blueprint $table) {
- $table->id();
- $table->unsignedBigInteger('idContatto'); // Relazione con la tabella dei contatti
- $table->string('via', 255); // Via dell'indirizzo
- $table->string('civico', 3); // Numero civico
- $table->string('scala', 50)->nullable(); // Scala (opzionale)
- $table->string('interno', 50)->nullable(); // Interno (opzionale)
- $table->string('cap', 5); // CAP
- $table->unsignedBigInteger('idComune'); // Relazione con la tabella dei comuni
- $table->string('provincia', 100); // Provincia
- $table->string('regione', 100); // Regione
- $table->string('stato', 100)->nullable(); // Stato (opzionale)
- $table->timestamps();
- // Definizione delle chiavi esterne
- $table->foreign('idContatto')->references('idContatto')->on('contatto');
- $table->foreign('idComune')->references('idComune')->on('comuni');
- });
- //---------------//
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- class contattoIndirizzi extends Model
- {
- use HasFactory;
- protected $table = 'contatto_indirizzi';
- protected $primaryKey = 'id';
- protected $fillable = [
- 'idContatto',
- 'via',
- 'civico',
- 'scala',
- 'interno',
- 'cap',
- 'idComune',
- 'provincia',
- 'regione',
- 'stato'
- ];
- public function contatto()
- {
- return $this->belongsTo(Contatto::class, 'idContatto');
- }
- }
- //----------------------------//
- //----------------------------//
- <?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::create('comuni', function (Blueprint $table) {
- $table->id('idComune');
- $table->string('Codice_ISTAT')->unique();
- $table->string('nome_Comune', 100);
- $table->string('regione', 100);
- $table->string('citta', 35);
- $table->string('provincia', 100);
- $table->string('cap', 5);
- $table->timestamps();
- });
- }
- /**
- * Reverse the migrations.
- */
- public function down(): void
- {
- Schema::dropIfExists('comuni');
- }
- };
- //----------------------//
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- class Comuni extends Model
- {
- use HasFactory;
- protected $table = 'comuni';
- protected $primaryKey = 'idComune';
- protected $fillable = [
- 'Codice_ISTAT',
- 'nome_Comune',
- 'regione',
- 'citta',
- 'provincia',
- 'cap',
- ];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement