Add UserAddress model.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
66b8373da3
commit
4430b04f11
@ -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
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
Loading…
Reference in new issue