A very typical scenario is to add/remove fields to/from base Vanilo models. Changing the model layer however, won't automatically make those fields available in the Admin area.
To customize the admin views, you can simply use Laravel's override package views feature.
As an example, let's add the google_product_category
field to the the category editing area.
The
google_product_category
field is not present in the base Vanilo model, this example assumes that you've already added it to thetaxons
table by creating a migration.
Steps:
resources/views/vendor/vanilo/taxon
vendor/vanilo/framework/src/resources/views/taxon/_form.blade.php
to the folder created aboveThe saving/fetching of the field will happen automatically, without the need for modifying the controller.
If you want the apply validation to the new field then you'll have to do some additional steps.
The base admin contains customizable request form types where you can add the new field.
The update taxon and create taxon requests are separate classes so that you can apply separate logic to them. If you want to apply the same logic to both, then you need to extend both classes.
Steps:
// app/Http/Requests/CreateTaxon.php
namespace App\Http\Requests;
use Vanilo\Framework\Http\Requests\CreateTaxon as BaseCreateTaxon;
class CreateTaxon extends BaseCreateTaxon
{
public function rules()
{
$rules = parent::rules();
$rules['google_product_category'] = 'required|min:16|max:255';
return $rules;
}
}
// app/Http/Requests/UpdateTaxon.php
namespace App\Http\Requests;
use Vanilo\Framework\Http\Requests\UpdateTaxon as BaseUpdateTaxon;
class UpdateTaxon extends BaseUpdateTaxon
{
public function rules()
{
$rules = parent::rules();
$rules['google_product_category'] = 'required|min:16|max:255';
return $rules;
}
}
// app/Providers/AppServiceProvider.php
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
$this->app->concord->registerRequest(
\Vanilo\Framework\Contracts\Requests\CreateTaxon::class,
\App\Http\Requests\CreateTaxon::class
);
$this->app->concord->registerRequest(
\Vanilo\Framework\Contracts\Requests\UpdateTaxon::class,
\App\Http\Requests\UpdateTaxon::class
);
}
}
This way the field will be validated according to your rules without the need for modifying the controller.