简体   繁体   English

Laravel Blank白页

[英]Laravel Blank white page

I'm having a problem with my get route in a group. 我在组中获取路线时遇到问题。 here is my code: 这是我的代码:

Route::group(['prefix' => 'commodities'], function(){
    Route::get('commodities', [
        'as' => 'showCommodities', 'uses' => 'CommodityController@showAll'
    ]);

    Route::get('{id}', [
        'as' => 'showCommodity', 'uses' => 'CommodityController@show'
    ]);

    Route::get('add', [
        'as' => 'addCommodity', 'uses' => 'CommodityController@create'
    ]);

    Route::post('update', [
        'as' => 'updateCommodity', 'uses' => 'CommodityController@update'
    ]);

    Route::post('destroy', [
        'as' => 'destroyCommodity', 'uses' => 'CommodityController@destroy'
    ]);

    Route::post('add', [
        'as' => 'storeCommodity', 'uses' => 'CommodityController@store'
    ]);
});

I pasted the CommodityController code here http://pastebin.com/bWrdVhsv 我在这里粘贴了CommodityController代码http://pastebin.com/bWrdVhsv

Everything works except the GET route commodites/add . 一切都有效,除了GET路线commodites/add I always get a white page. 我总是得到一个白页。 My debug is set to TRUE and I have the correct blade for it. 我的调试设置为TRUE ,我有正确的刀片。

Am I missing something here? 我在这里错过了什么吗?

The problem is the order of your routes. 问题是您的路线顺序。

Move the add route above your catch all {id} route. add路线移动到捕获所有{id}路线上方。

Route::group(['prefix' => 'commodities'], function(){
    Route::get('commodities', [
        'as' => 'showCommodities', 'uses' => 'CommodityController@showAll'
    ]);

    Route::get('add', [
        'as' => 'addCommodity', 'uses' => 'CommodityController@create'
    ]);

    Route::get('{id}', [
        'as' => 'showCommodity', 'uses' => 'CommodityController@show'
    ]);

    Route::post('update', [
        'as' => 'updateCommodity', 'uses' => 'CommodityController@update'
    ]);

    Route::post('destroy', [
        'as' => 'destroyCommodity', 'uses' => 'CommodityController@destroy'
    ]);

    Route::post('add', [
        'as' => 'storeCommodity', 'uses' => 'CommodityController@store'
    ]);
});

Laravel will go through your routes.php file top to bottom. Laravel将从头到尾浏览您的routes.php文件。 The below route is essentially a catch all. 以下路线基本上是一个全部。

Route::get('{id}', [
        'as' => 'showCommodity', 'uses' => 'CommodityController@show'
]);

This means it will catch all GET requests to urls that match the pattern: 这意味着它将捕获所有与模式匹配的URL的GET请求:

/commodities/some-kind-of-string . /commodities/some-kind-of-string

As the /commodities/add uri matches the above pattern it will use that route because it appears first in the routes file. 由于/commodities/add uri与上述模式匹配,它将使用该路由,因为它首先出现在routes文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM