title: Undefined variable: UserRegistration (View: C:\xampp\htdocs\laravel\Form_submit\resources\views\registration.blade.php)
body: <p>I am new in laravel 8 &amp; I am trying to edit &amp; show the value of that field in a form and i am able to show it in that field.
  But when i am trying to add another data it is showing Undefined variable: UserRegistration.</p>
  <p>My registration.blade.php code:</p>
  <pre><code>&lt;form action=&quot;{{$url}}&quot;, method=&quot;POST&quot;&gt;
  
                  @csrf
  
              &lt;div class=&quot;row&quot;&gt;
                  &lt;div class=&quot;col-md-6 mb-4&quot;&gt;
                      &lt;div class=&quot;form-outline&quot;&gt;
                          &lt;input type=&quot;text&quot; id=&quot;form3Example1m&quot; name=&quot;Fname&quot;
                              class=&quot;form-control form-control-lg&quot; value=&quot;{{$UserRegistration-&gt;Fname}}&quot; /&gt;
                          &lt;label class=&quot;form-label&quot; for=&quot;form3Example1m&quot;&gt;First name&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;col-md-6 mb-4&quot;&gt;
                      &lt;div class=&quot;form-outline&quot;&gt;
                          &lt;input type=&quot;text&quot; id=&quot;form3Example1n&quot; name=&quot;Lname&quot;
                              class=&quot;form-control form-control-lg&quot; value=&quot;{{$UserRegistration-&gt;Lname}}&quot; /&gt;
                          &lt;label class=&quot;form-label&quot; for=&quot;form3Example1n&quot;&gt;Last name&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;row&quot;&gt;
                  &lt;div class=&quot;col-md-6 mb-4&quot;&gt;
                      &lt;div class=&quot;form-outline&quot;&gt;
                          &lt;input type=&quot;text&quot; id=&quot;form3Example1m1&quot; name=&quot;mother&quot;
                              class=&quot;form-control form-control-lg&quot; value=&quot;{{ $UserRegistration-&gt;mother}}&quot; /&gt;
                          &lt;label class=&quot;form-label&quot; for=&quot;form3Example1m1&quot;&gt;Mother's
                              name&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;col-md-6 mb-4&quot;&gt;
                      &lt;div class=&quot;form-outline&quot;&gt;
                          &lt;input type=&quot;text&quot; id=&quot;form3Example1n1&quot; name=&quot;father&quot;
                              class=&quot;form-control form-control-lg&quot; value=&quot;{{$UserRegistration-&gt;father}}&quot; /&gt;
                          &lt;label class=&quot;form-label&quot; for=&quot;form3Example1n1&quot;&gt;Father's
                              name&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;form-outline mb-4&quot;&gt;
                  &lt;input type=&quot;text&quot; id=&quot;form3Example8&quot; name=&quot;address&quot; value=&quot;{{$UserRegistration-&gt;address}}&quot; class=&quot;form-control form-control-lg&quot; /&gt;
                  &lt;label class=&quot;form-label&quot; for=&quot;form3Example8&quot;&gt;Address&lt;/label&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;d-md-flex justify-content-start align-items-center mb-4 py-2&quot;&gt;
  
                  &lt;h6 class=&quot;mb-0 me-4&quot;&gt;Gender: &amp;nbsp;&lt;/h6&gt;
  
                  &lt;div class=&quot;form-check form-check-inline mb-0 me-4&quot;&gt;
                      &lt;input class=&quot;form-check-input&quot; type=&quot;radio&quot; name=&quot;gender&quot;
                          id=&quot;femaleGender&quot; value=&quot;M&quot;{{$UserRegistration-&gt;gender=='M'?'checked':''}} /&gt;
                      &lt;label class=&quot;form-check-label&quot; for=&quot;femaleGender&quot;&gt;Male&lt;/label&gt;
                  &lt;/div&gt;
  
                  &lt;div class=&quot;form-check form-check-inline mb-0 me-4&quot;&gt;
                      &lt;input class=&quot;form-check-input&quot; type=&quot;radio&quot; name=&quot;gender&quot;
                          id=&quot;maleGender&quot; value=&quot;F&quot; {{$UserRegistration-&gt;gender=='F'?'checked':''}} /&gt;
                      &lt;label class=&quot;form-check-label&quot; for=&quot;maleGender&quot;&gt;Female&lt;/label&gt;
                  &lt;/div&gt;
  
                  &lt;div class=&quot;form-check form-check-inline mb-0&quot;&gt;
                      &lt;input class=&quot;form-check-input&quot; type=&quot;radio&quot; name=&quot;gender&quot;
                          id=&quot;otherGender&quot; value=&quot;O&quot; {{$UserRegistration-&gt;gender=='O'?'checked':''}} /&gt;
                      &lt;label class=&quot;form-check-label&quot; for=&quot;otherGender&quot;&gt;Other&lt;/label&gt;
                  &lt;/div&gt;
  
              &lt;/div&gt;
  
              &lt;div class=&quot;row&quot;&gt;
                  &lt;h6 class=&quot;mb-0 me-4&quot;&gt;State: &amp;nbsp;&lt;/h6&gt;
  
                  &lt;div class=&quot;col-md-6 mb-4&quot;&gt;
  
                      &lt;select class=&quot;select&quot; name=&quot;state&quot;&gt;
                          &lt;option value=&quot;&quot;&gt;State&lt;/option&gt;
                          &lt;option value=&quot;Khulna&quot; {{$UserRegistration-&gt;state=='Khulna' ? 'selected':''}}&gt;Khulna&lt;/option&gt;
                          &lt;option value=&quot;Dhaka&quot; {{$UserRegistration-&gt;state=='Dhaka' ? 'selected':''}}&gt;Dhaka&lt;/option&gt;
                          &lt;option value=&quot;Dinajpur&quot; {{$UserRegistration-&gt;state=='Dinajpur' ? 'selected':''}}&gt;Dinajpur&lt;/option&gt;
                      &lt;/select&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;row&quot;&gt;
                  &lt;h6 class=&quot;mb-0 me-4&quot;&gt;City: &amp;nbsp; &amp;nbsp;&lt;/h6&gt;
                  &lt;div class=&quot;col-md-6 mb-4&quot;&gt;
                      {{-- &lt;h6 class=&quot;mb-0 me-4&quot;&gt;City: &amp;nbsp;&lt;/h6&gt; --}}
                      &lt;select class=&quot;select&quot; name=&quot;city&quot;&gt;
                          &lt;option value=&quot;&quot;&gt;City&lt;/option&gt;
                          &lt;option value=&quot;Khulna&quot; {{$UserRegistration-&gt;state=='Khulna' ? 'selected':''}}&gt;Khulna&lt;/option&gt;
                          &lt;option value=&quot;Dhaka&quot; {{$UserRegistration-&gt;state=='Dhaka' ? 'selected':''}}&gt;Dhaka&lt;/option&gt;
                          &lt;option value=&quot;Dinajpur&quot; {{$UserRegistration-&gt;state=='Dinajpur' ? 'selected':''}}&gt;Dinajpur&lt;/option&gt;
                      &lt;/select&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class=&quot;d-flex justify-content-end pt-3&quot;&gt;
                  &lt;button type=&quot;button&quot; class=&quot;btn btn-light btn-lg mr-3&quot;&gt;Reset all&lt;/button&gt;
                  &lt;button type=&quot;submit&quot; name=&quot;submit&quot; class=&quot;btn btn-warning btn-lg ms-2&quot;&gt;{{$btntitle}}&lt;/button&gt;
              &lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>
  <p>My controller UserSignup.php file:</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use App\Models\UserRegistration;
  
  class UserSignup extends Controller
  {
      //
      public function homePage(){
  
          return view('home');
      }
      
      public function signup(){
  
          $url=url('/usersignup');
          $title=&quot;Student registration form&quot;;
          $btntitle=&quot;Submit&quot;;
          
          $data=compact('url','title','btntitle');
          
          return view('registration')-&gt;with($data);
      }
  
      public function storeData(Request $request){
          
          //insert into table
  
          $UserRegistration=new UserRegistration;
          
          $UserRegistration-&gt;Fname=$request['Fname'];
          $UserRegistration-&gt;Lname=$request['Lname'];
          $UserRegistration-&gt;mother=$request['mother'];
          $UserRegistration-&gt;father=$request['father'];
          $UserRegistration-&gt;address=$request['address'];
          $UserRegistration-&gt;gender=$request['gender'];
          $UserRegistration-&gt;state=$request['state'];
          $UserRegistration-&gt;pincode=$request['pincode'];
          $UserRegistration-&gt;course=$request['course'];
          $UserRegistration-&gt;city=$request['city'];
          $UserRegistration-&gt;email=$request['email'];
          $UserRegistration-&gt;dob=$request['dob'];
  
          $UserRegistration-&gt;save();
  
          return redirect('/signup/view');
      }
  
  
      public function viewData(){
          
          // show data
          $UserRegistration=UserRegistration::all();
  
          $data=compact('UserRegistration');
          return view(&quot;customer-view&quot;)-&gt;with($data);
  
      }
  
      
  
      public function edit($id){
  
          $UserRegistration=UserRegistration::find($id);
  
          if (is_null($UserRegistration)) {
              # not found
              return redirect('/signup/view');
          }else{
  
              $url=url('/signup/update').'/'.$id;
  
              $title=&quot;Update Student registration form&quot;;
              $btntitle=&quot;Update&quot;;
              $data=compact('UserRegistration','url','title','btntitle');
              return view('registration')-&gt;with($data);
          }
  
          
      }
  
      public function update($id,Request $request)
      {
          $UserRegistration=UserRegistration::find($id);
  
          $UserRegistration-&gt;Fname=$request['Fname'];
          $UserRegistration-&gt;Lname=$request['Lname'];
          $UserRegistration-&gt;mother=$request['mother'];
          $UserRegistration-&gt;father=$request['father'];
          $UserRegistration-&gt;address=$request['address'];
          $UserRegistration-&gt;gender=$request['gender'];
          $UserRegistration-&gt;state=$request['state'];
          $UserRegistration-&gt;pincode=$request['pincode'];
          $UserRegistration-&gt;course=$request['course'];
          $UserRegistration-&gt;city=$request['city'];
          $UserRegistration-&gt;email=$request['email'];
          $UserRegistration-&gt;dob=$request['dob'];
  
          $UserRegistration-&gt;save();
          return redirect('/signup/view');
  
      }
  }
  </code></pre>
  <p>web.php:</p>
  <pre><code>Route::get('/home',[UserSignup::class,'homePage']);
  
  Route::get('/signup',[UserSignup::class,'signup']);
  Route::post('/usersignup',[UserSignup::class,'storeData']);
  
  Route::get('/signup/view',[UserSignup::class,'viewData']);
  
  Route::get('/signup/delete/{id}',[UserSignup::class,'delete'])-&gt;name('customer.delete');
  
  Route::get('/signup/edit/{id}',[UserSignup::class,'edit'])-&gt;name('customer.edit');
  Route::post('/signup/update/{id}',[UserSignup::class,'update'])-&gt;name('customer.update');
  </code></pre>