Kanchan186
4 weeks ago
581
2
Laravel

Facade\Ignition\Exceptions\ViewException Undefined variable: country (View: C:\xampp\htdocs\register\resources\views\register.blade.php)

Posted 4 weeks ago by Kanchan186

RegisterController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\country;
use App\state;
use App\city;

class RegisterController extends Controller
{
    public function adduser()
    {
               $country=country::get();

                      return view('register',compact('country','state','city'));
                  }

 public function store(Request $request)
    {
        //dd($req->all());
        register::create([
                    'name'=>request('name'),
                    'country'=>request('country'),
                    'state'=>request('state'),
                    'city'=>request('city'),
                    'hobby'=>request('hobby'),
                ]);

        //return redirect('viewprod');
    }



}

register.blade.php

<body>
    <h1>User Registration Form</h1>

    <form method="post" action="{{url('/')}}/store"  enctype="multipart/form-data">
                        {{csrf_field()}}
    <table>
    <tr><label for="name"><b>Name</b></label>
    <input type="text" placeholder="Enter user name" name="name" required></tr>

  

    <tr><select name="country" class="form-control">
        @foreach ($country as $coun)
        <option  value ="{{$coun->c_id}}">{{$coun->c_name}}</option>
        @endforeach
        </select></tr> 

    <tr><select name="state" class="form-control">
        @foreach ($state as $st)
        <option value ="{{$st->s_id}}" >{{$st->s_name}}</option>
        @endforeach
        </select></tr>   

    <tr><select name="city" class="form-control">
        @foreach ($city as $ct)
        <option value ="{{$ct->ct_id}}" >{{$ct->ct_name}}</option>
        @endforeach
        </select></tr> 
    
     @foreach($hobby as $hb)
       <tr><label for="hobbies"><b>Hobbies</b></label> 
           <input type="checkbox" name="hb[{{$hb->h_id}}]"  value ="{{$hb->h_id}}">{{$hb->h_name}}<br></tr>
     @endforeach







    
    <hr>

   
    <button type="submit" class="registerbtn">Register</button>
  </div>    

    </table>   




       
    </body>

web.php

Route::get('/', function () {
    return view('register');
});

Route::get('adduser','[email protected]');
Route::post('store','[email protected]');

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