Open sulaymankhan opened 8 years ago
Here I am including my case you can describe your problem better to solve your problem.
In my plugin page, I am creating a panel
$panel->add([
'type' => 'panel',
'as' => 'mainPanel',
'title' => 'Analytica',
'rename' => 'General',
'slug' => 'plugin-admin-settings',
'icon' => 'dashicons-chart-area',
'uses' => __NAMESPACE__ . '\Controllers\AdminController@index',
'post' => __NAMESPACE__ . '\Controllers\AdminController@save',
]);
now when my form will be submitted like
<form id="poststuffs" action="{{ panel_url('Analytica::mainPanel') }}" method="post">
the data will be received by save method
class AdminController {
public function save(Http $http)
{
if($http->only($this->option)){
$inputs = $http->only($this->option);
}
if( ! $this->validate($inputs) || ! $this->check($inputs) )
{
}
}
public function validate($inputs){
//validate your data
}
public function check($inputs){
//sanitize your data
}
If you want, you can include Illuminate\Validation.
In the command line, type
composer require illuminate/validation
Put this code in a PHP file and then add it to the require section in herbert.config.php:
// register validator
$container->bind('translator', function(){
return new \Symfony\Component\Translation\Translator('en_US', new \Symfony\Component\Translation\MessageSelector());
});
$container->register('Illuminate\Validation\ValidationServiceProvider');
// end register validator
``
Get the validator like so:
herbert('validator')->make(....)
@extrakun that's great, thank you for this, I am going to use it now +1:
@extrakun Would be so kind to create a pull request for your example to the docs (https://github.com/getherbert/docs)? =)
@extrakun It doesn't work because Laravel upgraded their version. Also, your method does not show translated validation error.
@jeremyzahner I did it but took good amount of time. I think it's more like a submitting tutorial then sending a PR.
@moazam1 can you please tell me how you use illuminate/validation?
It will be really helpful if you include data validation example in Saving Data section.