Skip to content

Instantly share code, notes, and snippets.

@boyhagemann
Last active December 24, 2015 15:39
Using the Boyhagemann\Crud package, we can listen to the init method and change the behaviour of the Form, Model and Overview. In this case we notify the user to configure some form fields first.
// We can listen to the init method of the CrudController. There we have access to
// the FormBuilder, ModelBuilder and OverviewBuilder.
Event::listen('crudController.init', function(Boyhagemann\Crud\CrudController $controller) {
// We can check if the user has configured some form elements yet.
// If not, then show him a message in your layout.
// You must have a dedicated variable available in your layout. We are using
// the '$message' variable here
if(!$controller->getFormBuilder()->getElements()) {
View::composer('layouts.default', function($layout) {
$layout->message = 'What?! You have no fields added yet! Go to your controller and add some form fields.';
$layout->content = '';
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment