Closed chrispage1 closed 4 years ago
Please paste your model class
@alberto-bottarini - thanks for your message. Here's the model -
<?php
namespace App\Domains\Series\Models;
use App\Domains\Locations\Models\Event;
use App\Domains\Series\Models\Series;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Class Season
*
* @property Series series
* @property integer series_id
*
* @package App\Domains\Series\Models
*/
class Season extends Model
{
public function series(): BelongsTo
{
return $this->belongsTo(Series::class);
}
public function events(): HasMany
{
return $this->hasMany(Event::class)
->orderBy('events.position', 'asc')
->orderBy('events.started_at', 'asc');
}
}
I got it!
rules
method accepts strings, not an array: https://nova.laravel.com/docs/3.0/resources/validation.html#validation
Is it fixed now?
@alberto-bottarini good try, but the rules
field docblock says otherwise:
/**
* Set the validation rules for the field.
*
* @param callable|array|string $rules
* @return $this
*/
Ah ok, i'm sorry... I just read documentation and array syntax is never referenced
I am currently experiencing this as well. With the code below:
BelongsTo::make(__('Jurisdiction'), 'jurisdiction')
->rules(function(NovaRequest $novaRequest) {
$rules = [];
if ($novaRequest->input('jurisdiction') === null && $novaRequest->input('role') !== Role::Jurisdiction) {
$rules = [ 'required' ];
}
return $rules;
})
->help('If the user is a jurisdiction user, select the jurisdiction (team) that this user will belong to.')
Nova will not evaluate the closure and will simply make the input required.
I was not able to replicate your issue by using string validation or array validation:
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Description:
I've created a BelongsTo field which has validation rules required and exists, to check the existence of the key within the database before saving. However, if I leave the BelongsTo field empty, I don't get any validation errors but do get a database constraint violation because the database field cannot be null.
It seems to entirely pass the validation phase and straight to database insertion.
Steps To Reproduce:
Create a BelongsTo with validation rules:
Hit save without populating the value and watch the errors roll in...