Error trying to insert into the database with Laravel

0

I'm using Laravel and I've been banging my head for a long time trying to figure out the cause of the following error when trying to insert :

  

(1/1) ErrorException   Illegal offset type

     

in HasAttributes.php (line 818)

     

at HandleExceptions-> handleError (2, 'Illegal offset type',   'C: \ nisfram \ vendor \ laravel \ framework \ src \ Illuminate \ Database \ Eloquent \ Concerns \ HasAttributes.php'   818, array ()) in HasAttributes.php (line 818)

     

at Model-> getCasts () in HasAttributes.php (line 803)

     

at Model-> hasCast ('ST_ALUNO_ALU', array ('date', 'datetime')) in   HasAttributes.php (line 832)

     

at Model-> isDateCastable ('ST_ALUNO_ALU') in HasAttributes.php (line   565)

     

at Model-> isDateAttribute ('ST_ALUNO_ALU') in HasAttributes.php (line   525)

     

at Model-> setAttribute ('ST_ALUNO_ALU', 'Matheus') in Model.php (line   233)

And the error messages go even further.

My table is as follows:

Schema::create('alunos', function (Blueprint $table) {
        $table->increments('ID_ALUNO_ALU');
        $table->string('ST_ALUNO_ALU', 100);
        $table->string('ST_RESPONSAVEL_ALU', 100);
        $table->integer('NM_MATRICULA_ALU');
        $table->date('DT_NASCIMENTO_ALU')->nullable();
        $table->timestamps();
    });

My form is as follows:

<form class="form" action="{{ route('alunos.store') }}" method="POST">

   <input name="_token" type="hidden" value="{{ csrf_token() }}"/>

    <div class="row">
        <div class="col-md-12">
            <label for="ST_ALUNO_ALU" class="control-label">Nome</label>
            <input type="text" class="form-control" name="ST_ALUNO_ALU" value="" autofocus>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <label for="ST_RESPONSAVEL_ALU" class="control-label">Responsável</label>
        <input type="text" class="form-control" name="ST_RESPONSAVEL_ALU" value="">
    </div>
</div>

<div class="row">
    <div class="col-md-4">
        <label for="NM_MATRICULA_ALU" class="control-label">NIS</label>
        <input type="number" class="form-control" name="NM_MATRICULA_ALU" value="">
    </div>
    <div class="col-md-4">
        <label for="DT_NASCIMENTO_ALU" class="control-label">Data de Nascimento</label>
        <input type="date" class="form-control" name="DT_NASCIMENTO_ALU" value="">
    </div>
</div>

And my method in the controller:

public function store(Request $request)
{
    $save = Aluno::create($request->all());

    if($save)
        redirect()->back();
    else
        throw new Exception("Não foi possível registrar o aluno");            
}

If someone can help me, I thank you, because I have no idea where the error is.

    
asked by anonymous 03.08.2017 / 02:29

1 answer

0

I found the error. In my model the primary key was like this:

protected $primaryKey = ['ID_ALUNO_ALU'];

Just remove the array brackets that worked.

    
03.08.2017 / 16:38