I am new to Laravel and I do not know how to solve this problem, which is as follows:
I have a table like that on MySql:
Table: propiedad_x_tipo
Columns:
**id_tipo_propiedad** int(11) **PK**
**id_propiedad** int(11) **PK**
As you can see the two columns are primary keys.
Now my model is as follows:
class Tipo_X_Propiedad extends Model
{
protected $table='propiedad_x_tipo';
protected $primaryKey= ['id_tipo_propiedad','id_propiedad'];
public $timestamps=false;
protected $fillable=[
'id_tipo_propiedad',
'id_propiedad'
];
protected $guarded=[
];
}
and when inserting into the database I do it like this:
$tipos_seleccionados=$request->get('tipo_propiedad');
foreach ($tipos_seleccionados as $key => $value ) {
$tipo_x_propiedad=new Tipo_X_Propiedad;
$tipo_x_propiedad->id_tipo_propiedad=$key.$value;
$tipo_x_propiedad->id_propiedad=(int)$count;
$tipo_x_propiedad->save();
}
But it gives me an error when running it:
(1/1) ErrorException Illegal offset type in HasAttributes.php (line 820) at HandleExceptions-> handleError (2, 'Illegal offset type', 'C: \ Users \ USER \ Documents \ XXXX \ XXXX \ vendor \ laravel \ framework \ src \ Illuminate \ Database \ Eloquent \ Concerns \ HasAttributes.php', 820, array ()) in HasAttributes.php (line 820)