Model Form
The Ezadev\Admin\Form class is used to generate a data model-based form. For example, there is amovies table in the database
CREATE TABLE `movies` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`director` int(10) unsigned NOT NULL,
`describe` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`rate` tinyint unsigned NOT NULL,
`released` enum(0, 1),
`release_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;The corresponding data model is App\Models\Movie, and the following code can generate themovies data form:
use App\Models\Movie;
use Ezadev\Admin\Form;
use Ezadev\Admin\Facades\Admin;
$form = new Form(new Movie);
// Displays the record id
$form->display('id', 'ID');
// Add an input box of type text
$form->text('title', 'Movie title');
$directors = [
'John' => 1,
'Smith' => 2,
'Kate' => 3,
];
$form->select('director', 'Director')->options($directors);
// Add textarea for the describe field
$form->textarea('describe', 'Describe');
// Number input
$form->number('rate', 'Rate');
// Add a switch field
$form->switch('released', 'Released?');
// Add a date and time selection box
$form->dateTime('release_at', 'release time');
// Display two time column
$form->display('created_at', 'Created time');
$form->display('updated_at', 'Updated time');Custom tools
The top right corner of the form has two button tools by default. You can modify it in the following way:
Form footer
Use the following method to remove the elements of the form foot
Other methods
Disable submit btn:
Disable reset btn:
Ignore fields to store
Set width for label and field
Set form action
Model relationship
One to One
The users table and the profiles table are generated one-to-one relation through the profiles.user_id field.
The corresponding data model are:
You can associate them in a form with the following code:
Last updated