Kanchan186's avatar

ErrorException (E_ERROR) Undefined variable: product (View: C:\xampp\htdocs\check\resources\views\prodview.blade.php)

please tell me where i going wrong

ProductController.php


<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\product;


class ProductController extends Controller
{
    

public function show()
                 {



                    $product=product::get();

                    return view('prodview',compact('product'));

                    //return redirect('prodview');
                  } 


}

prodview.blade.php


            <div class="content">
               
                <form method="post" action="{{url('/')}}/store1" enctype="multipart/form-data">
                        {{csrf_field()}}
                <input type="hidden" name="MAX_FILE_SIZE" value="10485760">


                     <table  class="table table-striped">
                        
                   
                         <td><select name="p_id" class="form-control">

                           @foreach($product as $prod)

                            <option value ="{{$prod->p_id}}">{{$prod->p_name}}</option>
                           @endforeach
                        </select></td> 

                       
                        
                        </table>



                 



                  
                </form>

               <br><hr>
               
            </div>


web.php



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

Route::get('show','ProductController@show');


0 likes
6 replies
ftiersch's avatar
Route::get('/', function () {
    return view('prodview');
});

You display the prodview without passing it the product variable.

Kanchan186's avatar

sir, how to pass product variable please tell me little more

ftiersch's avatar

The same way you are doing it in your controller?

$product=product::get();

return view('prodview',compact('product'));

Or different approach: Simply call the correct url :) /show instead of /

munazzil's avatar
munazzil
Best Answer
Level 13

If you have problem with url then type as like below in your command promt and show the result here,

    php artisan route:list

with that use below query us all() instead of get(),

     $product=product::all();
Kanchan186's avatar

thanks sir, problem is there about url and it get solved.

Please or to participate in this conversation.