ein paar test-objekte
This commit is contained in:
14
app/HasContracts.php
Normal file
14
app/HasContracts.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use App\Models\Document;
|
||||||
|
|
||||||
|
trait HasContracts
|
||||||
|
{
|
||||||
|
public function contracts()
|
||||||
|
{
|
||||||
|
return $this->morphMany(Document::class, 'contractable');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
14
app/HasDocuments.php
Normal file
14
app/HasDocuments.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use App\Models\Document;
|
||||||
|
|
||||||
|
trait HasDocuments
|
||||||
|
{
|
||||||
|
public function documents()
|
||||||
|
{
|
||||||
|
return $this->morphMany(Document::class, 'documentable');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
app/Models/Contact.php
Normal file
15
app/Models/Contact.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\HasContracts;
|
||||||
|
use App\HasDocuments;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Contact extends Model
|
||||||
|
{
|
||||||
|
use HasDocuments, HasContracts;
|
||||||
|
|
||||||
|
protected $fillable = ['name', 'type'];
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,9 +2,18 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\HasDocuments;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Contract extends Model
|
class Contract extends Model
|
||||||
{
|
{
|
||||||
//
|
use HasDocuments;
|
||||||
|
|
||||||
|
protected $fillable = ['name', 'type'];
|
||||||
|
|
||||||
|
public function contractable()
|
||||||
|
{
|
||||||
|
return $this->morphTo();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
10
app/Models/Customer.php
Normal file
10
app/Models/Customer.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Customer extends Model
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
class Document extends Model
|
class Document extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $fillable = ['name'];
|
protected $fillable = ['name', 'type'];
|
||||||
|
|
||||||
public function documentable()
|
public function documentable()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
|
|
||||||
use App\Models\Document;
|
use App\HasDocuments;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
@@ -13,6 +13,7 @@ class User extends Authenticatable
|
|||||||
{
|
{
|
||||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||||
use HasFactory, Notifiable;
|
use HasFactory, Notifiable;
|
||||||
|
use HasDocuments;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable.
|
* The attributes that are mass assignable.
|
||||||
@@ -48,8 +49,4 @@ class User extends Authenticatable
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function documents()
|
|
||||||
{
|
|
||||||
return $this->morphMany(Document::class, 'documentable');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ return new class extends Migration
|
|||||||
Schema::create('documents', function (Blueprint $table) {
|
Schema::create('documents', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
|
$table->string('type');
|
||||||
$table->morphs('documentable');
|
$table->morphs('documentable');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
@@ -13,6 +14,10 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('contracts', function (Blueprint $table) {
|
Schema::create('contracts', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
|
$table->string('type');
|
||||||
|
$table->foreignIdFor(User::class, 'responsible');
|
||||||
|
$table->morphs('contractable');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?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('contacts', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
|
$table->string('type');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('contacts');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user