title: Laravel form submission with url parameters
body: <p>When the user accesses a certain brand page, I pull the information associated with that brand. Then the user has the chance to submit an application for this brand. </p>
  
  <p>When the user submits the form, I want the form to post to <code>/apply/brand/{brand_id}</code> because I want to store this application in my application table with the <code>brand_id</code> as one of the fields (the other fields in this table comes from the fields in my form, but the <code>brand_id</code> will be an URL parameter) </p>
  
  <p>The problem is that when I submit the form, the form posts to <strong>/apply/brand/undefined</strong> and the submission does not work correctly. I do not reach the <code>ApplicationController@apply_store</code> method. </p>
  
  <p><strong>EDIT:</strong>
  To debug my problem, I printed out the {{$brand -> id }} right before the  element and it printed out fine. However, when the form submits, it goes to /apply/brand/undefined instead of /apply/brand/{{$brand -> id }}. The $brand variable somehow becomes undefined inside of my form. </p>
  
  <p><strong>EDIT:</strong>
  I hardcoded the from to submit to /apply/brand/43. When I press submit, the url shows up as /apply/brand/43 at first but then quickly changes to /apply/brand/undefined before redirecting me to my default page. </p>
  
  <p><strong>Controller Method for Accessing a Brand Page</strong></p>
  
  <pre><code>public function brandProfile(){
          $brand = Brand::where('user_id', Auth::user()-&gt;id)-&gt;first();
          $industry = Industry::where('status', 1)-&gt;get();
          return view('new-design.pages.profile_brand')
                              -&gt;withData($brand)
                              -&gt;withIndustry($industry);
  }
  </code></pre>
  
  <p><strong>Brand Application Form</strong></p>
  
  <pre><code>&lt;form id="application_form" method="post" action="/apply/brand/{{ $data -&gt; id }}" enctype="multipart/form-data"&gt;
    {{ csrf_field() }}
    &lt;ul&gt;
        &lt;div class="col-md-6"&gt;
          &lt;li&gt;
              &lt;label&gt;First Name&lt;/label&gt;
              &lt;input type="text" class="form-control" name="firstname" placeholder="First Name"/&gt;
          &lt;/li&gt;
        &lt;/div&gt;
        &lt;div class="col-md-6"&gt;
          &lt;li&gt;
              &lt;label&gt;Last Name&lt;/label&gt;
              &lt;input type="text" class="form-control" name="lastname" placeholder="Last Name"/&gt;
          &lt;/li&gt;
        &lt;/div&gt;
        &lt;div class="col-md-6"&gt;
          &lt;li&gt;
              &lt;label&gt;Email&lt;/label&gt;
              &lt;input type="email" class="form-control" name="email" placeholder="Email"/&gt;
          &lt;/li&gt;
        &lt;/div&gt;
        &lt;div class="col-md-6"&gt;
          &lt;li&gt;
              &lt;label&gt;Instagram Handle&lt;/label&gt;
              &lt;input type="text" class="form-control" name="instagram" placeholder="Instagram Handle"/&gt;
          &lt;/li&gt;
        &lt;/div&gt;
          &lt;li&gt;
              &lt;label&gt;Cover Letter&lt;/label&gt;
              &lt;p&gt;Please write your message in the space below, or attach a file (-list of file types accepted-)&lt;/p&gt;
              &lt;textarea cols="30" rows="50" name="message" class="textarea"&gt;&lt;/textarea&gt;
          &lt;/li&gt;
          &lt;li&gt;
              &lt;div class="upload-cover-letter"&gt;
                &lt;i class="fa fa-paperclip" style="cursor:pointer;font-size:20px;"&gt;&lt;/i&gt;
                &lt;input type="file" name="file" id="myFileDocument" class="inputfile inputfile-1"/&gt;
                &lt;label for="myFileDocument" id="myFileDoc"&gt;&lt;span&gt;Choose File&lt;/span&gt;&lt;/label&gt;
                &lt;span style="font-size: 12px"&gt;No File Chosen&lt;/span&gt;
                &lt;span class='hidden_text' style="font-size: 12px"&gt;Upload File (Max 2MB)&lt;/span&gt;
              &lt;/div&gt;
              &lt;input type="hidden" id="myFileName" name="file_name" /&gt;
          &lt;/li&gt;
    &lt;/ul&gt;
    &lt;div class="btn-center"&gt;
         &lt;button type="button" class="btn btn-gradient waves-effect" id="create_campaign"&gt;Apply Now&lt;/button&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Route in web.php</strong></p>
  
  <pre><code>Route::post('/apply/brand/{brand_id}', 'ApplicationController@apply_store');
  </code></pre>
  
  <p><strong>Store application in database</strong></p>
  
  <pre><code>public function apply_store(Request $request)
      {
          $application = new Application([
              'influencer_id' =&gt; Auth::id(),
              'brand_id' =&gt; $request-&gt;get('brand_id'),
              'message' =&gt; $request-&gt;get('message'),
              'status' =&gt; 'applied'
          ]);
          $application-&gt;save();
  
          // TODO: add helper message to confirm application did return
          return redirect('/apply');
      }
  </code></pre>