【问题标题】:laravel route work wrong to direct to viewslaravel 路线工作错误,无法定向到视图
【发布时间】:2016-08-21 16:57:27
【问题描述】:

我是一个新的 laraveler,现在我正在处理有关 laravel 的问题。我想将/ 直接发送给钓鱼者index.html。和其他路由到 laravel 控制器。但是当\直接好了。其他路由到 views 目录时出错。
\app\Http\route.php 如下:

Route::get('/',function(){
    return File::get(public_path().('/views/index.html'));
});

Route::get('scan', "userController@Scan");
Route::get('check', "userController@Check");
Route::get('login', "userController@Login");

directy 如下所示:

├── app │ ├── Http │ │ ├── route.php //route file │ ├── Library │ ├── Providers │ ├── Services │ ├── User.php │ └── views
│ │ ├── Index.php // php index file , the entry for nginx server │ └── .......... ├── bootstrap │ ├── app.php │ ├── autoload.php │ └── cache ├── config │ ├── app.php │ └── view.php │ └── .......... ├── public │ ├── bower_components │ ├── css │ ├── data │ ├── index.bak │ ├── index.html //angular index file │ └── scripts │ └── ..........

现在当我访问 http://hostname/scan 时,它会出现 404 未找到。

日志如下: ``` *2221 open() "/service/angular-laravel/app/views/scan" 失败(2:没有这样的文件或目录),客户端:x.x.x.x,服务器:主机名,请求:"GET /scan HTTP/1.1",主机: "banliyun.com:8081"

```

因为我对路线的运作方式有些困惑。谁能告诉我为什么它会路由到放置 laravel 索引页面的 /views 目录。

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    将您的index.html 保存为index.blade.php/resources/views/index.blade.php 中,然后将您的路线更改为以下代码:

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

    【讨论】:

      【解决方案2】:

      AppServiceProviderboot 方法中添加以下行:

      View::addLocation(public_path('views')); 
      

      index.html 文件重命名为index.blade.php,然后按照route.php 中的以下行进行操作

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

      【讨论】:

        猜你喜欢
        • 2021-12-17
        • 2017-10-11
        • 2021-05-03
        • 2014-09-30
        • 2017-03-15
        • 2015-03-03
        • 2020-12-08
        • 2020-02-12
        • 1970-01-01
        相关资源
        最近更新 更多