Model Laravel 5.2

Asked

Viewed 241 times

2

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

Modal:

<?php

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

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

DD of the input.

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"
]

1 answer

2


If you want to make all attributes assignable in bulk, you can set the property $guarded as an empty matrix:

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 estate $guarded must contain a number of attributes that you nay wants it to be mass assignable. All other attributes in the matrix will not be mass assignable. Then, $guarded works as a "blacklist". Of course, you should use any one $fillable or $guarded - not both.

Otherwise check primaryKey of the table and see if you don’t need to define in the model as well.

protected $primaryKey = 'sua _chave_primaria'; 
  • 1

    Closed friend, I did as you said. I passed the empty $guarded and now is entering and updating only the cases that are in the form. Thanks

Browser other questions tagged

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