I spent quite a good two days on something so simple and small. I have a model called User, which has one relationship to user notes.
On the user model side, I have a specific toTo relationship, and then the user model defines the hasOne side of the relationship.
The form I use is bound to the $user model, while the UserNote model has its own table, which maps to user_id.
I am trying to get what is shown below on the right;
{{ Form::textarea($user->notes, null , [ 'class' => 'form-control', 'placeholder' => 'Note Content']) }}
Is there anyone to help me figure this out? b All I need to be able to add a note, and if the user does not have a note, I should not get errors, because if I do as shown below, I get an error
{{ Form::textarea('UserNote[content]',... }}
Your advice will be appreciated.
class User{ ... public function note() { return $this->belongsTo(UserNote::class); } } class UserNote{ protected $fillable = ['content', 'user_id']; ... public function user() { return $this->hasOne(User::class, 'user_id'); } }
Of course, the user_id in $fillable should not be there in the first place, because this means that I can update this table manually, whereas I want everything to be done automatically from the controller to form the binding.
Maximum86
source share