Closed glenelkinsdev closed 1 year ago
Hey, @glenelkinsdev
could you please share the relationship code as well for a better understanding... I assume it is:
public function type(){
return $this->belongsTo('App\Models\BusinessType', 'type_id');
}
Hey, @glenelkinsdev
could you please share the relationship code as well for a better understanding... I assume it is:
public function type(){ return $this->belongsTo('App\Models\BusinessType', 'type_id'); }
public function type() : HasOne
{
return $this->hasOne(BusinessType::class,'id','type_id');
}
i've just realised what my mistake is, i've created this as a one-to-one instead of a one-to-many
the screen in question allows to add a business to the database and has a dropdown of options to select the business type, which is populated from the BusinessType model.
I have included type_id in the fillable for the business, but the query never selects the field to insert so i'm getting "SQLSTATE[HY000]: General error: 1364 Field 'type_id' doesn't have a default value"
It generates this query:
insert into
businesses
(name
,description
,website_url
,telephone
,email
,address1
,address2
,town
,post_code
,lat
,lng
,fb_url
,tw_url
,li_url
) values (dsfsdf, dsfdsf, ?, ?, ?, ?, ?, dsfdsf, ?, ?, ?, ?, ?, ?)As you can see it's missing type_id completely but all the other fields in fillable work:
The type_id is present in the post request! Here is the setup method: