Laravel仅在某些路线上返回空白页 [英] Laravel returning a blank page only on certain routes

查看:166
本文介绍了Laravel仅在某些路线上返回空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了路由返回空白页的问题.我正在使用Homestead作为开发环境,不确定如何调试.

I'm having an issue where a route is returning a blank page. I am using Homestead as my dev environment and I'm unsure how to debug.

当我访问白页时,/storage/logs/laravel ...没有返回任何异常.

The /storage/logs/laravel ... isn't returning any exceptions when I visit the white page.

web.php(失败):

Route::get('/clinic/register', 'ClinicController@register');

Controller.php:

public function register()
{
    return view('clinic.register', ['specialisms' => Specialism::pluck('specialism', 'id')]);
}

但是,当我访问/clinic/register时,会看到空白页.我怎么知道为什么它失败了?白页肯定会在某处返回异常吗?

Yet when I visit /clinic/register I am shown a blank white page. How can I see why it's failing? Surely a white page will return an exception somewhere?

推荐答案

由于您尚未提供完整的路由设置.这个答案是我最好的猜测.看看是否有帮助.

As you have not provided your entire route setup. This answer is my best guess. See if it helps.

您的问题提示路由设置不正确.如果您创建了诊所资源,则诊所/注册路由应位于该资源之前.

Your issue hint at improper route setup. If you have created a clinic resource then clinic/register route should precede it.

// clinic/register route should come first
Route::get('clinic/register','ClinicController@register');

// followed by rest of the routes which resource will create
Route::resource('clinic','ClinicController');

获取空白页面的原因是因为Route :: resource将使用通配符创建一些路由. 例如诊所/{诊所},它将映射以显示控制器上的方法.因此,当您请求获取诊所/注册的请求时,它将被映射到此 show 方法,而不是您的 register 方法.

The reason behind getting a blank pages is because Route::resource will create some route with wildcards. For e.g. clinic/{clinic} which will map to show method on controller. So when you make a get request to clinic/register it will be mapped to this show method instead of your register method.

一种不会出现任何错误的可能性是您的 show 方法还没有任何代码.因此,回复为空.

One possibility for not getting any errors is your show method does not have any code yet. Hence, a blank response.

总结:您注册路线的顺序很重要

这篇关于Laravel仅在某些路线上返回空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆