title: Passing Data through Return Redirect Back to Update Request
body: <p>I am trying to allow a user to update their information after they have submitted a form, but did not check a certain box. Everything is within the same page and I am controlling the different modals by returning a message, which triggers a script to open the different modals. </p>
  
  <p>For some reason, I can't seem to pass the ID or email through to the next step. Can anyone help with this?</p>
  
  <p>Whenever, I try, I get the following error:</p>
  
  <blockquote>
    <p>Undefined variable: leads</p>
  </blockquote>
  
  <p>Any idea?</p>
  
  <p>Thanks!!!</p>
  
  <p>Files:</p>
  
  <ul>
  <li>web.php</li>
  <li>index.blade.php</li>
  <li>LeadsController.php</li>
  <li>Leads.php</li>
  </ul>
  
  <p>Web.php</p>
  
  <pre><code>Route::post('/', [
      'uses' =&gt; 'LeadsController@store',
      'as' =&gt; 'leads.store'
  ]);
  Route::patch('/{email}', [
      'uses' =&gt; 'LeadsController@update',
      'as' =&gt; 'leads.update'
  ]);
  </code></pre>
  
  <p>Index.blade.php</p>
  
  <pre><code>&lt;html&gt;
  &lt;div id="contact" class="modal fade"&gt;
      &lt;div class="modal-dialog modal-content modal-lg"&gt;
          &lt;div class="modal-body"&gt;
              &lt;form id="form" class="form" action="/" method="post" accept-charset="utf-8"&gt;
                  {{ csrf_field() }}
                  &lt;input type="email" name="email" value="{{ old('email') }}"&gt;
                  &lt;input type="checkbox" name="newsletter"&gt;
                  &lt;button type="submit"&gt;Submit&lt;/button&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  @if(session()-&gt;has('message'))
      &lt;div id="sign_up" class="modal fade"&gt;
          &lt;div class="modal-dialog modal-content modal-lg"&gt;
              &lt;div class="modal-body"&gt;
                  &lt;form method="post" action="{{ route('leads.update', $leads-&gt;email) }}"&gt;
                       {{ csrf_field() }}
                       {{ method_field('PATCH') }}
                       &lt;input type="checkbox" name="newsletter"&gt;
                       &lt;button type="submit"&gt;Submit&lt;/button&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  @endif
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>LeadsController.php</p>
  
  <pre><code>public function store(Request $request)
  {
      $validator = Validator::make($request-&gt;all(), [
          'email'        =&gt; 'required|email',
      ]);
      if ($validator-&gt;fails()) {
          return redirect()-&gt;back()-&gt;withErrors($validator)-&gt;withInput($request-&gt;all);
      } else {
          try {
              $leads = new Leads;
              $leads-&gt;email        = $request-&gt;email;
              $leads-&gt;newsletter   = $request-&gt;newsletter;
              $leads-&gt;save();
              if($request-&gt;newsletter == ''){
                  return redirect()-&gt;back()-&gt;with('message','sign up')-&gt;withInput($request-&gt;all)-&gt;with($leads-&gt;email, $request-&gt;get('email'));
              }
              if($request-&gt;newsletter == 'true'){
                  return redirect()-&gt;back()-&gt;with('success','success');
              }
          } catch (Exception $e) {
              return response()-&gt;json(
                  [
                      'status' =&gt; false,
                      'error' =&gt; base64_encode($e-&gt;getMessage()),
                  ],
                  Status::HTTP_INTERNAL_SERVER_ERROR
              );
          }
      }
  }
  
  public function update($email)
  {
      $leads = Leads::find($email);
      $leads-&gt;newsletter = $input('newsletter');
      $leads-&gt;save();
      return redirect()-&gt;back()-&gt;with('success','success');
  }
  </code></pre>
  
  <p>Leads.php</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Leads extends Model
  {
      protected $table = 'my_renamed_table';
      public $timestamps = false;
      protected $fillable = ['email', 'newsletter'];
  }
  </code></pre>