it-brains/laravel-validator
Useful Laravel Validation Rules
Custom rules
- uniqueModel
- existsModel
Examples
uniqueModel instead just unique
Instead of
...
use Illuminate\Validation\Rule;
...
public function rules()
{
return [
'title' => [
Rule::unique('containers', 'name')
->where('user_id', $this->user()->id)
->whereNull('deleted_at'),
],
// other rules
'type' => Rule::in(['A', 'B']),
...
];
}
...
or with table from model's class
...
use App\Container;
use Illuminate\Validation\Rule;
...
public function rules()
{
return [
'title' => [
Rule::unique((new Container::class)->getTable(), 'name')
->where('user_id', $this->user()->id)
->whereNull('deleted_at'),
],
// other rules
'type' => Rule::in(['A', 'B']),
...
];
}
...
Use next
...
use App\Container;
use ITBrains\Validation\Rule;
...
public function rules()
{
return [
'title' => [
Rule::uniqueModel(Container::class, 'name')
->where('user_id', $this->user()->id),
// other rules
'type' => Rule::in(['A', 'B']),
...
],
];
}
...
Related Packages
doctrine/dbal
Powerful PHP database abstraction layer (DBAL) with many features for database s...
634,760,849
9,707
laravel/serializable-closure
Laravel Serializable Closure provides an easy and secure way to serialize closur...
408,553,772
609
nunomaduro/collision
Cli error handling for console/command-line PHP applications.
387,976,821
4,658