This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use App\Models\Validation\ValidationByNameInterface;
|
||||
use App\Models\Company;
|
||||
@@ -24,6 +25,11 @@ class City extends Model implements ValidationByNameInterface
|
||||
return $this->belongsToMany(Company::class, 'cities_companies', 'city_id', 'company_id');
|
||||
}
|
||||
|
||||
public function userAddresses(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserAddress::class);
|
||||
}
|
||||
|
||||
public function getCompanyIds(): array
|
||||
{
|
||||
return $this->companies()->pluck('company_id')->toArray();
|
||||
|
||||
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use App\Models\Validation\ValidationByNameInterface;
|
||||
|
||||
@@ -39,4 +40,9 @@ class User extends Authenticatable implements ValidationByNameInterface
|
||||
{
|
||||
return $name != '';
|
||||
}
|
||||
|
||||
public function userAddresses(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserAddress::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserAddress extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'type',
|
||||
'street',
|
||||
'house',
|
||||
'flat',
|
||||
'stage',
|
||||
'note',
|
||||
'city_id',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function city(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(City::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\UserAddress>
|
||||
*/
|
||||
class UserAddressFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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('user_addresses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('title', 100);
|
||||
$table->smallInteger('type')->default(0);
|
||||
$table->string('street', 255);
|
||||
$table->string('house', 10)->nullable();
|
||||
$table->string('flat', 10)->nullable();
|
||||
$table->string('stage', 10)->nullable();
|
||||
$table->string('note', 100);
|
||||
|
||||
$table->unsignedBiginteger('city_id')->unsigned();
|
||||
$table->unsignedBiginteger('user_id')->unsigned();
|
||||
|
||||
$table->foreign('city_id')->references('id')
|
||||
->on('cities')->onDelete('cascade');
|
||||
|
||||
$table->foreign('user_id')->references('id')
|
||||
->on('users')->onDelete('cascade');
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('user_addresses');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class UserAddressSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user