WallyJ
50
10
Laravel

ID does not pass from view to controller

Posted 4 months ago by WallyJ

Relationships are set in the model

Form in view:

{!! Form::open(['route' => ['contactnotes.store', $contact->id]]) !!} 
     {{ csrf_field() }}
          <div class="form-group">
               {{Form::textarea('contactnotetext', null, array('placeholder' => 'Your note here', 'class' => 'form-control', 'rows' => '3'))}}
          </div>
          <div class="form-group">
               {{Form::submit('Add Note', array('class' => 'btn btn-primary'))}}
          </div>
{{Form::close()}}

ContactnotesController:

public function store(Contact $contact, Request $request)
    {
        $contactnote = new Contactnote;
        $contactnote->contact_id = $contact->id;
        $contactnote->contactnotetext = $request->contactnotetext;
        $contactnote->contact()->associate($contact);
        return $contactnote;
    }

I don't understand why the id is not being passed. When I submit the form I get:

{
"contact_id": null,
"contactnotetext": "adsf",
"contact": []
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.