105 lines
3.0 KiB
PHP
105 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Nova\Resources\Order\Loan\Remaining;
|
|
|
|
use App\Nova\Resource;
|
|
use App\Repos\System\Settings\Legal\PassportRepo;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Laravel\Nova\Fields\Hidden;
|
|
use Laravel\Nova\Fields\ID;
|
|
use Laravel\Nova\Fields\Number;
|
|
use Laravel\Nova\Fields\Select;
|
|
use Laravel\Nova\Fields\Text;
|
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
|
use Laravel\Nova\Panel;
|
|
use Nurmuhammet\NovaCustomHtml\NovaCustomHtml;
|
|
|
|
class NovaLoanRemainingOrder extends Resource
|
|
{
|
|
/**
|
|
* The model the resource corresponds to.
|
|
*
|
|
* @var class-string<\App\Modules\LoanRemainingOrder\Models\LoanRemainingOrder>
|
|
*/
|
|
public static $model = \App\Modules\LoanRemainingOrder\Models\LoanRemainingOrder::class;
|
|
|
|
/**
|
|
* The single value that should be used to represent the resource when being displayed.
|
|
*
|
|
* @var string
|
|
*/
|
|
public static $title = 'account_number';
|
|
|
|
/**
|
|
* The columns that should be searched.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
public static $search = [
|
|
'account_number', 'passport_id',
|
|
];
|
|
|
|
/**
|
|
* Get the displayable label of the resource.
|
|
*/
|
|
public static function label(): string
|
|
{
|
|
return __('Karzyň galyndysy');
|
|
}
|
|
|
|
/**
|
|
* Build an "index" query for the given resource.
|
|
*
|
|
* @param \Illuminate\Database\Eloquent\Builder<\App\Modules\LoanRemainingOrder\Models\LoanRemainingOrder> $query
|
|
* @return \Illuminate\Database\Eloquent\Builder<\App\Modules\LoanRemainingOrder\Models\LoanRemainingOrder>
|
|
*/
|
|
public static function indexQuery(NovaRequest $request, $query): Builder
|
|
{
|
|
$user = $request->user();
|
|
|
|
if ($user->isAdmin()) {
|
|
return $query;
|
|
}
|
|
|
|
return $query->where('user_id', $request->user()->id);
|
|
}
|
|
|
|
/**
|
|
* Get the fields displayed by the resource.
|
|
*
|
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
|
* @return array<int, \Laravel\Nova\Fields\Field>
|
|
*/
|
|
public function fields(NovaRequest $request): array
|
|
{
|
|
return [
|
|
ID::make()->sortable(),
|
|
|
|
Hidden::make('user_id')
|
|
->default(auth()->id()),
|
|
|
|
Select::make(__('Passport serie'), 'passport_serie')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(PassportRepo::values())
|
|
->rules('required')
|
|
->sortable(),
|
|
|
|
Number::make(__('Passport id'), 'passport_id')
|
|
->rules('required', 'numeric', 'digits:6'),
|
|
|
|
Text::make(__('Karz hasaby'), 'account_number')
|
|
->rules('required'),
|
|
|
|
new Panel(__('Karz taryhy'), [
|
|
NovaCustomHtml::make(__('Karz taryhy'), 'loan_history')
|
|
->onlyOnDetail()
|
|
->canSeeWhen('systemUser', $this)
|
|
->html(view('orders.loan.mobile.loan-remaining', [
|
|
'resource' => $this,
|
|
])->render()),
|
|
]),
|
|
];
|
|
}
|
|
}
|