2
When I leave the registration form fields without filling in, rule messages are displayed.
This is the customer registration code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use \App\Clientes;
use Validator; // Validação
use App\Http\Requests\ClienteRules;// Regras do formulário
class VendedorController extends Controller
{
public function cadastrar(ClienteRules $request){
$cliente = new \App\Clientes();
$cliente->nome = $request->nome;
$cliente->descricao = $request->descricao;
$cliente->vendedor = $request->vendedor;
$cliente->orcamento = $request->orcamento;
$cliente->save();
return redirect()->to('/lista_Cliente');
}
And here the requests
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ClienteRules extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'nome' => 'required',
'descricao' => 'required',
'vendedor' => 'required',
'orcamento' => 'required'
];
}
public function messages(){
return[
'nome.required' => 'Informe seu nome.',
'descricao.required' => 'Informe a descrição do produto.',
'vendedor.required' => 'Informe o nome do vendedor.',
'orcamento.required' => 'Informe o orçamento.'
];
}
}