orchidsoftware / crud

Simplify the process of building CRUD (Create, Read, Update, Delete) functionality in Laravel using the features of Orchid.
https://orchid.software
MIT License
143 stars 36 forks source link

Resource::rules() parameter injection #4

Closed pqr closed 3 years ago

pqr commented 3 years ago

According to documentation rules method accepts $model

image

but rules() definition does not: https://github.com/orchidsoftware/crud/blob/master/src/Resource.php#L225

As a result I get an error when trying to define a rules() method with $model parameter:

ErrorException
Declaration of App\Orchid\Resources\LocationResource::rules($model): array should be compatible with Orchid\Crud\Resource::rules(): array 
tabuna commented 3 years ago

Hey @pqr! I updated this. This should work now:

public function rules(Model $model): array
{
    return [
        'slug' => [
            'required',
            Rule::unique(self::$model, 'slug')->ignore($model),
        ],
    ];
}

https://user-images.githubusercontent.com/5102591/103000702-9714a900-453c-11eb-95cf-b0c9b103f047.mp4

pqr commented 3 years ago

Confirm, works now!