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] ?? '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user