I have a ServiceProvider:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use \Validator;
use App\Services\CustomValidator;
class AppServiceProvider extends ServiceProvider
{
public function boot() {
Validator::extend('firstname_fail', 'App\Services\CustomValidator@fullnameFailValidate');
Validator::extend('lastname_fail', 'App\Services\CustomValidator@lastnameFailValidate');
Validator::extend('hotel_fail', 'App\Services\CustomValidator@hotelFailValidate');
Validator::extend('city_fail', 'App\Services\CustomValidator@cityFailValidate');
}
}
I have a model Tourist, which has such attributes: firstname, lastname, hotel, city. And there can be added some other (many) attributes.
(I know how to get all field names from Tourist model: $array = Schema::getColumnListing('tourists'); )
So my question is how to make a dynamic creation of:
Validator::extend('fieldname_fail', "App\Services\CustomValidator@fieldnameFailValidator')
inside the boot() method?
I tried to use magic _call method, but didn't succeed...
Any help appreciated!:)