php 如何将路线返回到 Laravel 中的视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26086710/
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 18:09:03  来源:igfitidea点击:

How to return routes to views in laravel

phplaravelviewcontrollerroutes

提问by Cozzbie

I just tried loading a view using a route like so:

我只是尝试使用如下路线加载视图:

route.php
Route::get("/page", function(){
   return View::make("dir.page");
});


controller.php
View::make("/page");

...and an error was thrown. So my question is:

...并抛出一个错误。所以我的问题是:

Is it possible to load a route via a view and if its possible then how?

是否可以通过视图加载路线,如果可能,那么如何加载?

Thanks.

谢谢。

回答by Danny

Your should returnyour View.

你应该return你的观点。

So this will work fine:

所以这会正常工作:

Route::get("/page", function(){
   return View::make("dir.page");
});

回答by Neabfi

In Laravel 5.5 you can now do:

在 Laravel 5.5 中,您现在可以执行以下操作:

Route::view('/page', 'dir.page');

回答by Aruna Perera

In laravel 5.8 I had to use this.

在 laravel 5.8 中我不得不使用它。

Route::get("/page", function(){
   return \View::make("dir.page");
});