Oct 30, 2023
0
Level 1
laravel novaMethod Illuminate\\Routing\\UrlGenerator::nullable does not exist
Hi i am using
"laravel/nova": "4.21",
"laravel/framework": "9.41",
i have an error when using a specific relation in nova resource. some time on submit and some time when opening create page or update page. this is error
Method Illuminate\Routing\UrlGenerator::nullable does not exist
and this is my code.
relation in Model/Feature.php
public function category(): BelongsTo
{
return $this->belongsTo(FeatureCategory::class,'category_id');
}
and Nova/Feature.php
public function fields(NovaRequest $request)
{
return [
Number::make('Order', 'visible_priority')
->onlyOnIndex(),
ID::make()->sortable(),
Text::make('Name')
->rules('required'),
Select::make('Type',)
->options(FeatureType::toArray())
->rules('required')
->hideWhenUpdating(),
// ->readonly(function() {
// return $this->products()->exists() ? true : false;
// }),
Select::make('Target', 'target->name')
->hideWhenCreating()
->hideWhenUpdating(),
Select::make('Target', 'target->target')
->rules('required')
->onlyOnForms()
->hideWhenUpdating()
->dependsOn(['type'], function (Select $field, NovaRequest $request) {
if ($request->type == FeatureType::OPTIONAL->value) {
$field->options(FeatureTarget::OPTIONAL_TARGET);
} elseif ($request->type == FeatureType::SWITCH->value) {
$field->options(FeatureTarget::SWITCH_TARGET);
} elseif ($request->type == FeatureType::LIMIT->value) {
$field->options(FeatureTarget::LIMIT_TARGET);
}
})
->fillUsing(function ($request, $model, $attribute, $requestAttribute) {
$featureTarget = FeatureTarget::findCaseWithValue($request->get($attribute));
if ($featureTarget) {
$model->target = $featureTarget;
} else {
throw new \Exception(
ResponseAlias::$statusTexts[ResponseAlias::HTTP_UNPROCESSABLE_ENTITY],
ResponseAlias::HTTP_UNPROCESSABLE_ENTITY
);
}
}),
\Outl1ne\MultiselectField\Multiselect::make('Options')
->hide()
->hideFromIndex()
->taggable()
->saveAsJSON()
->dependsOn(['target->target', 'type'],
function (\Outl1ne\MultiselectField\Multiselect $field, NovaRequest $request) {
if ($request->get('target->target') == FeatureTarget::NONE->value
&& $request->get('type') == FeatureType::OPTIONAL->value) {
$field->show()->rules('required');
}
})
->placeholder('Your Options')
->help('Add an option and click enter'),
Textarea::make('Available Options', 'target->possibleValue')
->readonly()
->hide()
->onlyOnForms()
->dependsOn(['target->target', 'type'], function (Textarea $field, NovaRequest $request) {
if ($request->get('type') == FeatureType::OPTIONAL->value
&& !is_null($request->get('target->target'))
&& $request->get('target->target') != FeatureTarget::NONE->value) {
$target = $request->get('target->target');
$field->show()
->setValue(
(new $target(FeatureType::findCaseWithValue($request->get('type'))))
->possibleValueToString()
);
}
}),
Textarea::make('Description')
->rules('nullable')
->hideFromIndex(),
Text::make('Link')
// ->rules('url', 'nullable')
->rules(new UrlRule())
->hideFromIndex(),
Image::make('Image', 'image')
->hideFromIndex()
->path(TalkToS3::getFeaturePath())
->disk('s3')
->acceptedTypes('image/*')
->prunable()
->rules('image', 'max:2048'),
/*BelongsTo::make('Category', 'category', FeatureCategory::class)
->nullable()
->required(fn() => false),*/
Select::make('Category', 'category_id')
->nullable()
->withMeta(['value' => $this->resource->category_id])
->displayUsingLabels()
->resolveUsing(
fn($value, $resource, $attribute) => empty($resource->category_id) ? ""
: $resource->category->title . ' ( ' . $resource->category->id . ' )'
)
->options(function () {
$values = [];
$categories = \App\Models\FeatureCategory::get(['id', 'title']);
foreach ($categories as $category) {
$values[$category->id] = $category->title . ' ( ' . $category->id . ' )';
}
return $values;
})
->fillUsing(function ($request, $model, $attribute, $requestAttribute) {
if ($request->filled($requestAttribute)) {
$model->category_id = $request->get($requestAttribute);
}
}),
Boolean::make('Active'),
Boolean::make('Highlight')->help('use to show in AC page as important feature'),
];
}
i was use BelongsTo::make() but it cause error then i change to select field and error still exists.
Please or to participate in this conversation.