I'd like to add a locale field to administrator setting form, what is the best way to do this please?
I met the same issue, please help
@amun1303, fork laravel-admin, replace its route with yours, you might need to extends its controller, or completely use your own. Laravel-admin doesn't have a power form like Symfony Form by which you can customize all other forms without touching its code. I will close this , because there is no easy way to do the job like Symfony in Laravel system.
@videni See https://github.com/z-song/laravel-admin/issues/1739#issuecomment-383784417
Do not need to fork and modify the code, just override the route and controller
I had a solution
1- Create new Model extend from Administrator and add new field locale
class CustomAdministrator extends Administrator {
public function __construct( array $attributes = [] ) {
parent::__construct( $attributes );
array_push( $this->fillable, 'locale' );
}
}
2- Create a new Controller extend from UserController
class CustomUserController extends UserController {
protected function grid() {
$g = parent::grid();
$g->column( 'locale', 'Locale' );
return $g;
}
public function form() {
$f = parent::form();
$f->text( 'locale' );
return $f;
}
}
3- create a new route:
$router->resource( 'test', CustomUserController::class );
4- Call URL on browser:
localhost:8000/admin/test
@amun1303 @z-song thanks a lot.
I had a solution
1- Create new Model extend from Administrator and add new fieldlocaleclass CustomAdministrator extends Administrator { public function __construct( array $attributes = [] ) { parent::__construct( $attributes ); array_push( $this->fillable, 'locale' ); } }2- Create a new Controller extend from UserController
class CustomUserController extends UserController { protected function grid() { $g = parent::grid(); $g->column( 'locale', 'Locale' ); return $g; } public function form() { $f = parent::form(); $f->text( 'locale' ); return $f; } }3- create a new route:
$router->resource( 'test', CustomUserController::class );4- Call URL on browser:
localhost:8000/admin/test
Worked for me after I inversed lines inside constructor :
public function __construct( array $attributes = [] ) {
array_push( $this->fillable, 'locale' );
parent::__construct( $attributes );
}
Most helpful comment
I had a solution
1- Create new Model extend from Administrator and add new field
locale2- Create a new Controller extend from UserController
3- create a new route:
4- Call URL on browser: