Will generate the form file app/Admin/Forms/Setting.php
<?phpnamespaceApp\Admin\Forms;use Ezadev\Admin\Widgets\Form;use Illuminate\Http\Request;classSettingextendsForm{/** * The form title. * * @varstring*/public$title ='Settings';/** * Handle the form request. * * @paramRequest $request * * @return\Illuminate\Http\RedirectResponse*/publicfunctionhandle(Request $request){ //dump($request->all());admin_success('Processed successfully.');returnback();}/** * Build a form here.*/publicfunctionform(){$this->text('name')->rules('required');$this->email('email')->rules('email');$this->datetime('created_at');}/** * The data of the form. * * @returnarray $data*/publicfunctiondata(){return['name'=>'John Doe','email'=>'[email protected]','created_at'=>now(),];}}
In the form class above, $title is used to set the title of the form, and the form item is built in the form method. The method is consistent with model-form, and the data method is used to set the form item. Default data
Then put the above form into your page as follows:
After filling in the data submission form on the page, the request will go to the handle method, where you can add your data processing logic. After the processing is complete, return a response object to the front end:
Tab form
tab form Organize multiple forms by using the line selection card, click the tab to jump to the corresponding form page
How to use
Where $forms is an array of data form types
Step form
If you want to divide a form into multiple steps, you can use the step form:
The code for the first step table with class app/Admin/Forms/Steps/Info.php is as follows:
Note that the inheritance of the step form is the Ezadev\Admin\Widgets\StepForm class.
In the handle method, there are some ways to help deal with various situations.
Use the next method to save the current step data to the session and jump to the next step:
Or data processing fails, go back to the previous step:
Clear the data in the session after processing the data in the last step:
<?php
use App\Admin\Forms\Setting;
use App\Http\Controllers\Controller;
use Ezadev\Admin\Layout\Content;
class UserController extends Controller
{
public function setting(Content $content)
{
return $content
->title('Website setting')
->body(new Setting());
}
}
public function handle(Request $request)
{
// Get data from the $request object to process...
// Add a success prompt
admin_success('Success');
// or an error message
admin_success('Asu Ada Error....');
// Go back to the original form page after processing is complete, or jump to another page by returning `redirect()` method
return back();
}
use App\Admin\Forms\Settings;
use App\Http\Controllers\Controller;
use Ezadev\Admin\Layout\Content;
use Ezadev\Admin\Widgets\Tab;
class FormController extends Controller
{
public function settings(Content $content)
{
$forms = [
'basic' => Settings\Basic::class,
'site' => Settings\Site::class,
'upload' => Settings\Upload::class,
'database' => Settings\Database::class,
'develop' => Settings\Develop::class,
];
return $content
->title('Judul Form')
->body(Tab::forms($forms));
}
}
<?php
use App\Admin\Forms\Steps;
use App\Http\Controllers\Controller;
use Ezadev\Admin\Layout\Content;
use Ezadev\Admin\Widgets\MultipleSteps;
class FormController extends Controller
{
public function register(Content $content)
{
$steps = [
'info' => Steps\Info::class,
'profile' => Steps\Profile::class,
'password' => Steps\Password::class,
];
return $content
->title('Register')
->body(MultipleSteps::make($steps));
}
}
<?php
namespace App\Admin\Forms\Steps;
use Ezadev\Admin\Widgets\StepForm;
use Illuminate\Http\Request;
class Info extends StepForm
{
/**
* The form title.
*
* @var string
*/
public $title = 'Basic info';
/**
* Handle the form request.
*
* @param Request $request
*
* @return \Illuminate\Http\RedirectResponse
*/
public function handle(Request $request)
{
return $this->next($request->all());
}
/**
* Build a form here.
*/
public function form()
{
$this->text('username');
$this->email('email');
}
}