RouteCollection.php 第 161 行中的 NotFoundHttpException:在 Laravel 5 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33565479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:32:44  来源:igfitidea点击:

NotFoundHttpException in RouteCollection.php line 161: in laravel 5

phplaravel-5laravel-5.2

提问by Vikram Anand Bhushan

I know this is very common question on stack overflow I tried few of them but its not working in my scenario .

我知道这是关于堆栈溢出的非常常见的问题,我尝试了其中的几个,但在我的场景中不起作用。

My CollectionController looks like this .

我的 CollectionController 看起来像这样。

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Middleware\Role;
use Illuminate\Support\Facades\Input;
use App\User;
use App\Invoice;
use Session;
use Validator;


    class CollectionController extends Controller
    {
        /**
         * Display a listing of the resource.
         *
         * @return Response
         */

      public function __construct(){

        $this->middleware('role:collector'); // replace 'collector' with whatever role you need.
    }


      public function getHome(){

          $empid= Auth::user()->empid;
          $invoice = Invoice::where('Status','=',1)->orderBy('Id', 'desc')->get();


        return View('collectionmodule/home')->with(array('invoices'=>$invoice));

     }

       public function getPayment(){

    dd('sssss');
             $id =$invoiceid;
             $invoice = Invoice::where('Id','=',$id)->payments()->comments()->get();

             return View('collectionmodule/payment')->with(array('invoice'=>$id));

     }




        }

My Routes for this Class is as follow

我这门课的路线如下

Route::controller('collection/home','CollectionController');
Route::controller('collection/payment','CollectionController');

I am getting following error

我收到以下错误

NotFoundHttpException in RouteCollection.php line 161:

None of the routes are working can any one help me out

没有一条路线有效,谁能帮助我

I tried with

我试过

http://localhost:8000/collection/home/

and 

http://localhost:8000/collection/payment

Thanks

谢谢

采纳答案by Vikram Anand Bhushan

Well It was pretty simple

这很简单

In Implicit call

隐式调用

I should define the route only once

我应该只定义一次路线

Route::controller('collection','CollectionController');

so now in url collection/home if being parsed then laravel will automatically call getHome() function

所以现在在 url collection/home 中,如果被解析,laravel 会自动调用 getHome() 函数

回答by Santiago Mendoza Ramirez

You have to define only one time the route:

您只需定义一次路线:

Route::controller('collection','CollectionController');

And then you can go to the routes you declare in functions name of the controller.

然后您可以转到您在控制器的函数名称中声明的路由。

Example:

例子:

getHome. The route will be collection/home

获得首页。路线将是收集/回家

getPayments. The route will be collection/payments

获得付款。路线将是收款/付款

回答by Varun Taliyan

I was getting the exact same exception message in laravel 5.4.10 and after wasting around 2 hours I found out that routes.php has been removed in 5.3 onward versions and just creating file is not enough. We need to include file in RouteServiceProvider.php file inside "map" function. Adding below line inside mapfunction resolved the issue for me :

我在 laravel 5.4.10 中收到了完全相同的异常消息,浪费了大约 2 个小时后,我发现 routes.php 已在 5.3 以后的版本中删除,仅创建文件是不够的。我们需要在“map”函数中包含 RouteServiceProvider.php 文件中的文件。在map函数中添加以下行为我解决了这个问题:

require app_path('Http/routes.php');

回答by prosti

This is the most common exception.

这是最常见的例外。

NotFoundHttpException in RouteCollection.php

And it is quite easy to understand. You can dupe it if you misspell the route name. It may be ariclesinstead of articlesand things like that.

而且很容易理解。如果您拼错了路线名称,您可以欺骗它。它可能是aricles代替之articles类的。

Try

尝试

php artisan route:list

And check if all the route names are OK.

并检查所有路线名称是否都正确。

回答by Sandeep Rana

Check The Name Of The route,

检查路线名称,

whether it is capital or small.

不管是大资本还是小资本。

Example-> If Folder name is Testing and view name is contact.

示例-> 如果文件夹名称是测试,视图名称是联系人。

If You Write -> localhost/testing/contact, then it is an error because folder name i.e Testing and you have written small t i.e testing.

如果你写 -> localhost/testing/contact,那么这是一个错误,因为文件夹名称 ie Testing 并且你写了小 t ie testing。

So you have to write -> localhost/Testing/contact.

所以你必须写 -> localhost/Testing/contact。

And error is solved.

并解决了错误。