php - Laravel 5 Has One Relationship with Form Binding -


i have spent pretty 2 days on simple , small. have model called user has 1 user note relationship.

on user model's side have belongsto relationship defined , user's model defines hasone side of relationship.

the form using binds $user model meanwhile usernote model has own table maps user user_id.

i have been trying shown below right;

{{ form::textarea($user->notes, null , [ 'class' => 'form-control', 'placeholder' => 'note content']) }} 

somebody out there me figure out?b need able add note , if user has no note yet should not getting errors because if shown below error:

{{ form::textarea('usernote[content]',... }} 

your advice 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');   } } 

surely user_id in $fillable shouldn't there in first place because means can update table manually whereas want done automatically controller form binding.

first of all, you're doing relationship wrong.

  • user hasone usernote
  • usernote belongsto user

so, you've swap relations on corresponding models.
secondly, form's textarea has parameter list like:

public function textarea($name, $value = null, $options = []){} 

so, first parameter form_name. second parameter value of input. you're doing wrong.
in case, should ( think )

{{ form::textarea('user_note', $user->note , [ 'id' => 'user_note', 'class' => 'form-control', 'placeholder' => 'note content']) }} 

edit
property note method name, you're writing notes, method didn't exist. edit ends
hope helps. happy coding!


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -