Add branch & province model
This commit is contained in:
42
app/Models/Branch/Branch.php
Normal file
42
app/Models/Branch/Branch.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Branch;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Branch extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table name
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'branches';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'region',
|
||||||
|
'province_id',
|
||||||
|
'unique_code',
|
||||||
|
'billing_username',
|
||||||
|
'billing_password',
|
||||||
|
'address',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translatable fields
|
||||||
|
*
|
||||||
|
* @var array<string>
|
||||||
|
*/
|
||||||
|
public $translatable = [
|
||||||
|
'name',
|
||||||
|
'address',
|
||||||
|
];
|
||||||
|
}
|
||||||
30
app/Models/System/Location/Province.php
Normal file
30
app/Models/System/Location/Province.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\System\Location;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Spatie\Translatable\HasTranslations;
|
||||||
|
|
||||||
|
class Province extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
use HasTranslations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'region',
|
||||||
|
'name',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translatable fields
|
||||||
|
*
|
||||||
|
* @var array<string>
|
||||||
|
*/
|
||||||
|
public $translatable = ['name'];
|
||||||
|
}
|
||||||
59
app/Nova/Resource.php
Normal file
59
app/Nova/Resource.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Nova;
|
||||||
|
|
||||||
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||||
|
use Laravel\Nova\Resource as NovaResource;
|
||||||
|
|
||||||
|
abstract class Resource extends NovaResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Build an "index" query for the given resource.
|
||||||
|
*
|
||||||
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public static function indexQuery(NovaRequest $request, $query)
|
||||||
|
{
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a Scout search query for the given resource.
|
||||||
|
*
|
||||||
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||||
|
* @param \Laravel\Scout\Builder $query
|
||||||
|
* @return \Laravel\Scout\Builder
|
||||||
|
*/
|
||||||
|
public static function scoutQuery(NovaRequest $request, $query)
|
||||||
|
{
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a "detail" query for the given resource.
|
||||||
|
*
|
||||||
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public static function detailQuery(NovaRequest $request, $query)
|
||||||
|
{
|
||||||
|
return parent::detailQuery($request, $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a "relatable" query for the given resource.
|
||||||
|
*
|
||||||
|
* This query determines which instances of the model may be attached to other resources.
|
||||||
|
*
|
||||||
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public static function relatableQuery(NovaRequest $request, $query)
|
||||||
|
{
|
||||||
|
return parent::relatableQuery($request, $query);
|
||||||
|
}
|
||||||
|
}
|
||||||
139
app/Nova/Resources/Branch/Branch.php
Normal file
139
app/Nova/Resources/Branch/Branch.php
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Nova\Resources\Branch;
|
||||||
|
|
||||||
|
use App\Nova\Resources\Branch\Concerns\BranchNovaRepo;
|
||||||
|
use App\Repos\System\Settings\Location\RegionRepo;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Laravel\Nova\Fields\ID;
|
||||||
|
use Laravel\Nova\Fields\Select;
|
||||||
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||||
|
use Laravel\Nova\Resource;
|
||||||
|
use \App\Models\Branch\Branch as BranchModel;
|
||||||
|
|
||||||
|
class Branch extends Resource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The model the resource corresponds to.
|
||||||
|
*
|
||||||
|
* @var class-string<BranchModel>
|
||||||
|
*/
|
||||||
|
public static $model = BranchModel::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The single value that should be used to represent the resource when being displayed.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public static $title = 'name';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The columns that should be searched.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $search = [
|
||||||
|
'name', 'unique_code',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the displayable label of the resource.
|
||||||
|
*/
|
||||||
|
public static function label(): string
|
||||||
|
{
|
||||||
|
return __('Branches');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the displayable singular label of the resource.
|
||||||
|
*/
|
||||||
|
public static function singularLabel(): string
|
||||||
|
{
|
||||||
|
return __('Branch');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the fields displayed by the resource.
|
||||||
|
*
|
||||||
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function fields(NovaRequest $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
ID::make()->sortable(),
|
||||||
|
|
||||||
|
Text::make(__('Name'), 'name')
|
||||||
|
->rules('required', 'string', 'max:255')
|
||||||
|
->translatable(),
|
||||||
|
|
||||||
|
Select::make(__('Region'), 'region')
|
||||||
|
->displayUsingLabels()
|
||||||
|
->searchable()
|
||||||
|
->options(RegionRepo::values())
|
||||||
|
->default(RegionRepo::default())
|
||||||
|
->rules('required')
|
||||||
|
->sortable(),
|
||||||
|
|
||||||
|
Select::make(__('Province'), 'province_id')
|
||||||
|
->displayUsingLabels()
|
||||||
|
->searchable()
|
||||||
|
->dependsOn('region', BranchNovaRepo::dependsOnRegion()),
|
||||||
|
|
||||||
|
Text::make(__('Unique code'), 'unique_code')
|
||||||
|
->rules('required', 'string', 'max:255'),
|
||||||
|
|
||||||
|
Text::make(__('Billing username'), 'billing_username')
|
||||||
|
->rules('nullable', 'string', 'max:255'),
|
||||||
|
|
||||||
|
Text::make(__('Billing password'), 'billing_password')
|
||||||
|
->rules('nullable', 'string', 'max:255'),
|
||||||
|
|
||||||
|
Textare::make('address', 'address'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the cards available for the request.
|
||||||
|
*
|
||||||
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function cards(NovaRequest $request)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the filters available for the resource.
|
||||||
|
*
|
||||||
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function filters(NovaRequest $request)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the lenses available for the resource.
|
||||||
|
*
|
||||||
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function lenses(NovaRequest $request)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the actions available for the resource.
|
||||||
|
*
|
||||||
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function actions(NovaRequest $request)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Nova/Resources/Branch/Concerns/BranchNovaRepo.php
Normal file
22
app/Nova/Resources/Branch/Concerns/BranchNovaRepo.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Nova\Resources\Branch\Concerns;
|
||||||
|
|
||||||
|
use App\Models\Branch\Branch;
|
||||||
|
|
||||||
|
class BranchNovaRepo
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Depends on region
|
||||||
|
*/
|
||||||
|
public static function dependsOnRegion(): Closure
|
||||||
|
{
|
||||||
|
return function ($field, $request, $formData) {
|
||||||
|
$field->options(
|
||||||
|
$formData->region
|
||||||
|
? Branch::where('region', $formData->region)->pluck('name', 'id')
|
||||||
|
: []
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
7
app/Repos/Branch/BranchRepo.php
Normal file
7
app/Repos/Branch/BranchRepo.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repos\Branch;
|
||||||
|
|
||||||
|
class BranchRepo
|
||||||
|
{
|
||||||
|
}
|
||||||
73
app/Repos/System/Settings/Location/RegionRepo.php
Normal file
73
app/Repos/System/Settings/Location/RegionRepo.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repos\System\Settings\Location;
|
||||||
|
|
||||||
|
class RegionRepo
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Mary
|
||||||
|
*/
|
||||||
|
public const MR = 'mr';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aşgabat
|
||||||
|
*/
|
||||||
|
public const AG = 'ag';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arkadag
|
||||||
|
*/
|
||||||
|
public const AK = 'ak';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ahal
|
||||||
|
*/
|
||||||
|
public const AH = 'ah';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lebap
|
||||||
|
*/
|
||||||
|
public const LB = 'lb';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Balkan
|
||||||
|
*/
|
||||||
|
public const BN = 'bn';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daşoguz
|
||||||
|
*/
|
||||||
|
public const DZ = 'dz';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regions
|
||||||
|
*/
|
||||||
|
public static function values(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
self::AG => __('Ashgabat'),
|
||||||
|
self::AK => __('Arkadag'),
|
||||||
|
self::MR => __('Mary'),
|
||||||
|
self::AH => __('Ahal'),
|
||||||
|
self::LB => __('Lebap'),
|
||||||
|
self::BN => __('Balkan'),
|
||||||
|
self::DZ => __('Dashoguz'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default region
|
||||||
|
*/
|
||||||
|
public static function default(): string
|
||||||
|
{
|
||||||
|
return self::AG;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label for given region
|
||||||
|
*/
|
||||||
|
public static function label(string $region = 'ag'): string
|
||||||
|
{
|
||||||
|
return static::values()[$region] ?? '';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Repos\System\Settings\Location\RegionRepo;
|
||||||
|
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('provinces', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('region', 2)->index();
|
||||||
|
$table->jsonb('name');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('provinces');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Repos\System\Settings\Location\RegionRepo;
|
||||||
|
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('branches', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->jsonb('name');
|
||||||
|
$table->jsonb('address')->nullable();
|
||||||
|
$table->string('unique_code')->index()->nullable();
|
||||||
|
|
||||||
|
$table->string('region', 2)->index();
|
||||||
|
$table->foreignId('province_id')->constrained()->nullOnDelete();
|
||||||
|
|
||||||
|
$table->string('billing_username')->nullable();
|
||||||
|
$table->string('billing_password')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('branches');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -3,7 +3,9 @@
|
|||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
use Spatie\Permission\Models\Role;
|
||||||
|
|
||||||
class DatabaseSeeder extends Seeder
|
class DatabaseSeeder extends Seeder
|
||||||
{
|
{
|
||||||
@@ -12,11 +14,50 @@ class DatabaseSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
// \App\Models\User::factory(10)->create();
|
$this->createRoles();
|
||||||
|
$this->createAdmins();
|
||||||
|
}
|
||||||
|
|
||||||
// \App\Models\User::factory()->create([
|
public function createRoles(): void
|
||||||
// 'name' => 'Test User',
|
{
|
||||||
// 'email' => 'test@example.com',
|
if (Role::count() > 0) {
|
||||||
// ]);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$roles = [
|
||||||
|
'king',
|
||||||
|
'superadmin',
|
||||||
|
'admin',
|
||||||
|
'operator',
|
||||||
|
'user',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($roles as $role) {
|
||||||
|
Role::create(['name' => $role]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createAdmins(): void
|
||||||
|
{
|
||||||
|
$admins = [
|
||||||
|
[
|
||||||
|
'name' => 'Nurmuhammet Allanov',
|
||||||
|
'email' => 'nurmuhammet@mail.com',
|
||||||
|
'password' => '$2y$10$O7LFNdFIT3Rmfeo8tUfbqekB0x0incovkRP6eQuzvb7dVXysQyyBC',
|
||||||
|
], [
|
||||||
|
'name' => 'Mahmyt Allaberdiyev',
|
||||||
|
'email' => 'mahmyt1206@gmail.com',
|
||||||
|
'password' => '$2y$10$O7LFNdFIT3Rmfeo8tUfbqekB0x0incovkRP6eQuzvb7dVXysQyyBC',
|
||||||
|
], [
|
||||||
|
'name' => 'Döwran Myratlyýew',
|
||||||
|
'email' => 'dovran.m@mail.ru',
|
||||||
|
'password' => '$2y$10$EFQaBb.aM2KJRGGtuhjdM.3m4Mtm/vw68NjU2280d2RICDGI.o336',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($admins as $admin) {
|
||||||
|
$user = User::create($admin);
|
||||||
|
$user->assignRole('superadmin');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user