Laravel 5.2 NotFoundHttpException in RouteCollection.php line 161 Error

16,409

in your store index blade, you're not using a relative link, so it's attaching store/view/{!! $product->id !!} to whatever the current url (without QS) is.

if you add a / to the beginning of that href it might solve your problem. It also looks like you don't have a view method in your store controller, try changing that to show

@foreach($products as $product)
    <div class="col-md-4 col-lg-4 col-sm-12">
        <li>{!! $product->title  !!} - ({!! $product->price !!})</li>
        <p> {!! $product->description !!}</p>
        <a href="/store/{!! $product->id !!}">
            {!! Html::image($product->image ,$product->title) !!}
        </a>
    </div>
@endforeach
Share:
16,409
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin over 1 year

    I am following tuts+ video series for developing an ecommerce web app. I am almost done with it but I got one problem in the store section. I am displaying list of all products on /store route to the end users and I did that BUT now what I want to establish is single view page for each product.In simple words when I am on Store Page with all the products displayed , I want each product linked with his own singlepage view i.e price, picture , and other data about that specific post. I followed the video but when I try to access single page of a product it throws the following error.

    Error:

    NotFoundHttpException in RouteCollection.php line 161:
    in RouteCollection.php line 161
    at RouteCollection->match(object(Request)) in Router.php line 823
    at Router->findRoute(object(Request)) in Router.php line 691
    at Router->dispatchToRoute(object(Request)) in Router.php line 675
    at Router->dispatch(object(Request)) in Kernel.php line 246
    at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
    at CheckForMaintenanceMode->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
    at Pipeline->then(object(Closure)) in Kernel.php line 132
    at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
    at Kernel->handle(object(Request)) in index.php line 54
    at require_once('D:\xampp\htdocs\ecom\public\index.php') in index.php line 21
    

    Store index file on which all products or displayed:

        @foreach($products as $product)
                            <div class="col-md-4 col-lg-4 col-sm-12">
                                    <li>{!! $product->title  !!} - ({!! $product->price !!})</li>
                                    <p> {!! $product->description !!}</p>
                                    <a href="store/view/{!! $product->id !!}">
                                        {!! Html::image($product->image ,$product->title) !!}</p>
                                    </a>        
                                  {!! Form::close() !!}
                             </div>
       @endforeach
    

    View.blade.php or single page for product:

    {!! $product->title !!} <br>
    {!! $product->description !!} <br>
    {!! $product->image !!}
    

    StoreController Code :

    <?php
    
    namespace App\Http\Controllers;
    use Illuminate\Http\Request;
    use App\Http\Requests;
    use App\Category;
    use App\product;
    use View;
    use Illuminate\Support\Facades\Input;
    use Illuminate\Support\Facades\Redirect;
    
    class StoreController extends Controller
    {
    
        /**
         * Display a listing of the resource.
         *
         * @return \Illuminate\Http\Response
         */
        public function index()
        {
            return View::make('store.index')->with('products', product::take(4)->orderBy('created_at','DESC')->get());
        }
    
        /**
         * Show the form for creating a new resource.
         *
         * @return \Illuminate\Http\Response
         */
        public function create()
        {
            return View::make('InsertCategory');
        }
    
        /**
         * Store a newly created resource in storage.
         *
         * @param  \Illuminate\Http\Request  $request
         * @return \Illuminate\Http\Response
         */
        public function store(Request $request)
        {
                $category = new Category;
                $category->name = Input::get('name');
                $category->save();      
                return Redirect::to('admin/categories')->with('message', 'Category Created');
    
        }
    
        /**
         * Display the specified resource.
         *
         * @param  int  $id
         * @return \Illuminate\Http\Response
         */
        public function show($id)
        {
            return View::make('store.view')->with('product', product::find($id));
        }
    
        /**
         * Show the form for editing the specified resource.
         *
         * @param  int  $id
         * @return \Illuminate\Http\Response
         */
        public function edit($id)
        {
            //
        }
    
        /**
         * Update the specified resource in storage.
         *
         * @param  \Illuminate\Http\Request  $request
         * @param  int  $id
         * @return \Illuminate\Http\Response
         */
        public function update(Request $request, $id)
        {
            //
        }
    
        /**
         * Remove the specified resource from storage.
         *
         * @param  int  $id
         * @return \Illuminate\Http\Response
         */
        public function destroy($id)
        {
            $category = Category::find(Input::get('id'));
            var_dump($input);
            if($category){
                $category->delete();
                return Redirect::to('admin/categories');
            }
        }
    }
    

    Routes.php :

    Route::get('/', 'StoreController@index');
    Route::get('/admin', function () {
        return view('welcome');
    });
    Route::resource('store', 'StoreController');
    Route::resource('admin/categories', 'CategoriesController');
    Route::resource('admin/products', 'ProductsController');
    

    PS : If you people need any thing more just mention in comment I will add that.