【问题标题】:NotFoundHttpException in laravel projectLaravel 项目中的 NotFoundHttpException
【发布时间】:2018-01-31 03:51:44
【问题描述】:

我在这条路线上遇到了这个例外:http://localhost:8000/ 和我在 routes.php 文件中写的其他路线以及我写的时候

php 工匠路线:列表

我收到了这条消息

您的应用程序没有任何路由。

我没有更改我的代码中的任何内容并且它运行成功。我搜索了它,但我找不到确切的答案为什么会发生这个问题。 这是routes.php

    <?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/


Route::get('/', function () {
    $name = ['saba','safavi'];
    return view('welcome'/*,compact('name')*/);
});
Route::get('/sabasafavi', function () {
    return "Salam saba safavi";
});
Route::get('/contact-us', function () {
    return view("contact-us");
});
\Illuminate\Support\Facades\Route::get('/user/{id}',function ($id){
    return "hello user : ".$id;
})/*->where(['id'=>'[0-5]+'])*/;
\Illuminate\Support\Facades\Route::get('/user/{name}/comment/{number}',function ($name,$number){
    $comment = "Hello ".$name." this is your comment</br> number : ".$number;
    return $comment;
});
/*Route::post('/send',function (){
   return "OK information saved successfully";
});*/

【问题讨论】:

  • 与我们分享 web.php 文件?
  • 显示你的routes.php
  • 哪个版本的 laravel 5?
  • Laravel 框架版本 5.1.46 (LTS)
  • 有什么理由在新项目中使用旧版本?

标签: php laravel


【解决方案1】:

首先确保您的web.php 正在加载到 RouteServiceProvider.php

protected function mapWebRoutes()
{
    Route::middleware('web')
         ->namespace($this->namespace)
         ->group(base_path('routes/web.php'));
}

或者它可能是你的旧的空 web.php 因为你启用了缓存所以它已经被缓存了:php artisan route:clear 然后运行php artisan route:list

【讨论】:

  • 在 laravel 5.1 中没有 web.php
  • @Mohammadb 没有看到什么版本。他正在使用,但仍然几乎相同,他可以在 routes.php 文件中检查。
  • 我检查了地图功能和 routes.php 正在加载,我尝试过 php artisan route:clear, and list before
  • 检查您的 xampp/ mamp 或任何您正在使用的东西,看看您是否正在加载当前项目。并检查文件 routes.php 是否在正确的目录中
【解决方案2】:

这个问题是因为重命名了你的 Laravel 应用程序。

如果您使用像 PHPStorm 或 sublime 这样的 IDE,请在项目目录和所有子目录中的所有文件中对 laravel5learning 进行完整搜索(在文件中查找)(编辑->查找->在路径中查找),并且然后改成App

然后运行php artisan route:list

【讨论】:

  • 但我没有重命名我的 Laravel 应用程序
  • @sabasafavi 您创建的控制器或代码类中的命名空间是什么?
  • 我没有在项目中编写额外的类或控制器只是添加一些新的路线
  • @sabasafavi 检查存在的控制器知道什么是命名空间并不重要
  • in app/Http/Controllers/contrller.php -->命名空间App\Http\Controllers;
【解决方案3】:

请尝试

php artisan serve

这个命令会给你类似http://127.0.0.1:8000的东西。所以在 localhost 你只需添加这个,然后你的路线就像 -

http://127.0.0.1:8000/

这里'/'是我使用的默认路线/ 希望对你有用

【讨论】:

  • 谢谢,但我之前试过。我决定用新版本的 Laravel 创建一个新项目,它可以工作。我不知道以前的项目到底是什么
猜你喜欢
  • 1970-01-01
  • 2014-11-07
  • 2016-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-10
  • 2016-06-17
  • 2017-01-10
相关资源
最近更新 更多