public $guarded = ['id', 'created_at', 'updated_at'];
SQLSTATE[42S22]: Column not found: 1054 Field 'OtherField' unknown in field list
The problem comes from my request having unrelated fields, because they are for another related model update.
One solution would be to filter the requests input to only get the relevant fields to my model, but I'm wondering if there's an eloquent way to do this, beacuse there are a lot of fields and might change in the future.
I generally use guarded because I have many tables with too many fields to list them in fillable (some are 30+ fields). To get round this I wrote a model function in my parent model class like this:
/**
* Returns all writable fields for the model's table
*
* @return array
*/
public function getWritable()
{
if (!empty($this->fillable))
return $this->fillable;
return collect(Schema::getColumnListing($this->getTable()))
->flip()
->except($this->guarded)
->keys()
->toArray();
}