Model Laravel 5.2

1

Good morning. I need to insert / update data from a table in my database, however I do not know the columns that can hold within that table, because the system is very flex. I created a modal with $fillable = ['*']; to try to update only the cases that pass in the input, but it is not inserting anything. Follow the codes below. Note: the same input data is the data in the table.

Modal:

<?php

namespace App;
use Illuminate\Database\Eloquent\Model;
use Request;

class ChamadosChamados extends Model
{
protected $table = 'chamados_chamados';
public $timestamps = false;
protected $fillable = ['*'];
}

Input DD.

array:15 [▼
"_token" => "J05hMfB9PtZ6uoVdpKPNc29mZcN4KXgqkpVn71Y0"
"equipe" => "SANTANDER - RCI MOROSO"
"tipo" => "1"
"categoria" => "1"
"modelo_formulario" => "1"
"segmento" => "LEVES PR"
"dias_atraso" => "1"
"contrato" => "1"
"nome_financiado" => "1"
"endereco_financiado" => "1"
"uf" => "PA"
"cidade" => "AURORA"
"telefone_acordo" => "1"
"telefone_agendamento" => "1"
"observacao_required" => "1"
]
    
asked by anonymous 15.12.2017 / 13:05

1 answer

2

If you want to make all attributes attributable in bulk, you can set the $guarded property to an empty array:

protected $guarded = [];
While $fillable serves as a "white list" of attributes that must be assigned in bulk, you can also choose to use $guarded . The $guarded quer property must contain a series of attributes that you do not want to be mass-attributable. All other attributes in the array will not be mass-attributable. So, $guarded works as a "blacklist". Of course, you should use either $fillable or $guarded - not both.

Otherwise check the primaryKey of the table and see if you do not need to define it in the model either.

protected $primaryKey = 'sua _chave_primaria'; 
    
15.12.2017 / 13:15