create user documents
This commit is contained in:
@@ -16,12 +16,14 @@ class DocumentationController extends Controller
|
||||
public function index(Request $request): array
|
||||
{
|
||||
return DataTableFacade::run(
|
||||
User::query()->with('documentations'),
|
||||
User::query()->with('documents'),
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
allowedSelects: [
|
||||
'user.id', 'user.username'
|
||||
'users.id', 'users.first_name', 'users.last_name', 'users.national_id',
|
||||
'users.phone_number', 'users.postal_code', 'users.city_id', 'users.province_id',
|
||||
'users.province_name', 'users.city_name', 'users.address', 'documents.title', 'documents.url'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\CityFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class City extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\CityFactory> */
|
||||
/** @use HasFactory<CityFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
|
||||
@@ -2,11 +2,29 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\DocumentFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Document extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\DocumentFactory> */
|
||||
/** @use HasFactory<DocumentFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function documentable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
protected function url(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn($value) => Storage::disk('public')->url($value)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
15
backend/app/Models/Expert.php
Normal file
15
backend/app/Models/Expert.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\ExpertFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Expert extends Model
|
||||
{
|
||||
/** @use HasFactory<ExpertFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\ProvinceFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Province extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ProvinceFactory> */
|
||||
/** @use HasFactory<ProvinceFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Passport\HasApiTokens;
|
||||
@@ -19,4 +20,9 @@ class User extends Authenticatable
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable, HasApiTokens;
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function documents(): MorphToMany
|
||||
{
|
||||
return $this->morphToMany(Document::class, 'documentable');
|
||||
}
|
||||
}
|
||||
|
||||
24
backend/database/factories/ExpertFactory.php
Normal file
24
backend/database/factories/ExpertFactory.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Expert;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Expert>
|
||||
*/
|
||||
class ExpertFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@ return new class extends Migration
|
||||
$table->string('province_name')->nullable();
|
||||
$table->foreignId('city_id')->nullable()->constrained('cities');
|
||||
$table->string('city_name')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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('experts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('username');
|
||||
$table->string('first_name')->nullable();
|
||||
$table->string('last_name')->nullable();
|
||||
$table->string('email')->unique();
|
||||
$table->string('password');
|
||||
$table->string('national_id')->nullable();
|
||||
$table->string('phone_number')->nullable();
|
||||
$table->foreignId('province_id')->nullable()->constrained('provinces');
|
||||
$table->string('province_name')->nullable();
|
||||
$table->foreignId('city_id')->nullable()->constrained('cities');
|
||||
$table->string('city_name')->nullable();
|
||||
$table->tinyInteger('level')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('experts');
|
||||
}
|
||||
};
|
||||
17
backend/database/seeders/ExpertSeeder.php
Normal file
17
backend/database/seeders/ExpertSeeder.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ExpertSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user