Laravel 5.2在RouteCollection.php第161行中发现NotFoundHttpException错误

Laravel 5.2在RouteCollection.php第161行中发现NotFoundHttpException错误,php,routes,laravel-routing,laravel-5.2,Php,Routes,Laravel Routing,Laravel 5.2,我正在关注tuts+视频系列,以开发电子商务web应用程序。我差不多做完了,但我在商店里遇到了一个问题。我正在向最终用户显示/store路线上所有产品的列表,我这样做了,但现在我想为每个产品建立单视图页面。简单地说,当我在商店页面上显示所有产品时,我希望每个产品都与自己的单视图链接,即价格、图片、,以及其他关于该特定职位的数据。我跟踪了视频,但当我试图访问产品的单个页面时,它抛出以下错误 错误: NotFoundHttpException in RouteCollection.php line

我正在关注tuts+视频系列,以开发电子商务web应用程序。我差不多做完了,但我在商店里遇到了一个问题。我正在向最终用户显示
/store
路线上所有产品的列表,我这样做了,但现在我想为每个产品建立单视图页面。简单地说,当我在商店页面上显示所有产品时,我希望每个产品都与自己的单视图链接,即价格、图片、,以及其他关于该特定职位的数据。我跟踪了视频,但当我试图访问产品的单个页面时,它抛出以下错误

错误:

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
{!! $product->title !!} <br>
{!! $product->description !!} <br>
{!! $product->image !!}
<?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');
        }
    }
}
存储索引文件,其中显示所有产品或服务的索引文件

    @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

PS:如果你们需要更多的东西,只要在评论中提及,我会补充。

在你们的商店索引刀片中,你们没有使用相对链接,所以它将
store/view/{!!$product->id!!}
附加到当前的url(没有QS)上

如果您在该href的开头添加一个
/
,它可能会解决您的问题。您的商店控制器中似乎没有
查看
方法,请尝试将其更改为
显示

@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
@foreach($products作为$product)
  • {!!$product->title!!}-({!!$product->price!!})
  • {!!$product->description!!}

    @endforeach
    在商店索引刀片中,您没有使用相对链接,因此它将
    商店/view/{!!$product->id!!}
    附加到当前url(不带QS)的任何位置

    如果您在该href的开头添加一个
    /
    ,它可能会解决您的问题。您的商店控制器中似乎没有
    查看
    方法,请尝试将其更改为
    显示

    @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
    
    @foreach($products作为$product)
    
  • {!!$product->title!!}-({!!$product->price!!})
  • {!!$product->description!!}

    @endforeach
    这是因为您没有调用要执行的方法/函数。例如,在“
    StoreController
    ”上,您将执行
    索引
    您应该将其调用到您的
    routes.php

    像这样

    Route::resource('store', 'StoreController@index');
    

    这是因为您没有调用要执行的方法/函数。例如,在“
    StoreController
    ”上,您将执行
    索引
    您应该将其调用到您的
    routes.php

    像这样

    Route::resource('store', 'StoreController@index');
    

    如果您拼写错误路由名称,则很容易再现此异常:

    NotFoundHttpException in RouteCollection.php
    
    看来没有这样的路线

    试一试

    问题可能是您拼错了路线名称。
    它可能是
    aricles
    而不是
    articles
    之类的东西。

    如果您拼错了路线名称,很容易再现此异常:

    NotFoundHttpException in RouteCollection.php
    
    看来没有这样的路线

    试一试

    问题可能是您拼错了路线名称。
    它可能是
    aricles
    而不是
    文章
    之类的东西。

    @iam解码器哈哈,为什么这么严重?这是冒犯吗?正如我所观察到的,当你调用你的控制器时,你没有调用任何方法。@iam解码器哈哈,为什么这么严肃?这是攻击性的吗?正如我观察到的,在调用控制器时,您没有调用任何方法。@Felix Kamote尝试过,但仍然不起作用,顺便说一句,这是资源控制器,我们不需要指定如下函数controller@funcbcz它会自动为我们这样做。@Felix Kamote尝试过,但仍然不起作用我们不需要指定像这样的函数controller@funcbcz它会自动为我们这样做。@LaravelWarrior当您单击产品时,当前的url地址是什么?@LaravelWarrior您的控制器中没有
    视图
    方法,尝试将其更改为
    show
    ?我将view.blade.php更改为show.blade.php,并在控制器中返回store.show,store/show/{!!$product->id!!}的url仍然相同error@LaravelWarrior我假设您的新url是
    localhost/ecom/store/show/12
    。它必须是
    localhost/ecom/store/12
    ,因此实际上只需从href中删除“show”一词。我已经为你们编辑了我的答案是的,它很有魅力。但你们为什么要从URL中删除这个节目,若你们能解释一下,那个就太好了@LaravelWarrior当您单击一个产品时,当前的url地址是什么?@LaravelWarrior如果您的控制器中没有
    view
    方法,请尝试将其更改为
    show
    ?我将view.blade.php更改为show.blade.php,在控制器中返回store.show,并将url更改为store/show/{!!$product->id!!}还是一样error@LaravelWarrior我假设您的新url是
    localhost/ecom/store/show/12
    。它必须是
    localhost/ecom/store/12
    ,因此实际上只需从href中删除“show”一词。我已经为你们编辑了我的答案是的,它很有魅力。但你们为什么要从URL中删除这个节目,若你们能解释一下,那个就太好了!