How do I record the data from a form in the database in Laravel 5.4?

Asked

Viewed 90 times

0

I have a small problem in the production of a registration system, everything is working fine, but when I check the database no data submitted in the form appears, ie is not registered.

Class in the Controller:

public function Submit(Request $request)
{
    Model::create($request ->all());
    return redirect()->action('MainController@index');
}        

Observing: I won’t put the View because she’s too big (has about 150 lines of code, only the form, but if necessary I put.)

Their respective model:

class Model extends Model
{
    protected $table = 'user';
    public $timestamps = false;

    protected $fillable = array('nome',
        'CPF',
        'email',
        'datnasc',
        'naturalidade',
        'turno',
        'uf_natural',
        'nome_mae',
        'nome_pai',
        'nome_resp',
        'cpf_resp',
        'rua',
        'numero',
        'bairro',
        'complemento',
        'cep',
        'didade',
        'estado',
        'tel_celular',
        'tel_fixo',
        'tipo_escola',
        'escola_origem',
        'serie');

    protected $guarded = ['id'];
}

How to solve this problem?

  • Gives a dd($request ->all()); before Model::create($request ->all()); and p checks if the data is being submitted. Also check the form action

  • Form field names are the same as the database that were filled in the variable $fillable ?

  • That’s how it is: class Model extends Model if you have is a bad practice because Model is already reserved by Eloquent define its classes, so do not make any class with the name of Model? In your View you could put only the part of <form></form> and their routes too!

  • No, it’s just a generic name. !

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.