dou47278 2019-05-14 16:57
浏览 57
已采纳

控制器返回空白数据

the controller is returning a blank data/view and I think something is wrong with my routes. if I remove {locale}, the data is retrieved.

Can anyone help with returning the data properly while my routes have {locale} in it? Here are my related code:

Web.php

Route::get('{locale}/projects/{id}/billings', 'ProjectController@showbilling')
     ->name('showbilling');
Route::post('{locale}/projects/{id}', 'ProjectController@addbilling')
     ->name('addbilling');

ProjectController.php

public function showbilling($id)
{
    $billings = Project::find($id);
    $locale = app()->getLocale();

    return $billings;
    //return view('admin.addbillings', compact('billings'));
}

Edit: Here's my full web.php

web.php

Route::get('/', function() {
    return redirect(app()->getLocale());
});



Route::group(['prefix' => '{locale}', 'where' => ['locale' => '[a-zA-Z]{2}'], 'middleware' => 'setlocale'], function () {

    Route::get('/', function () {

    return view('welcome');
    })->name('main');

    Auth::routes();

    Route::get('/home', 'HomeController@index')->name('home');

    //Customers
    Route::get('/customers', 'CustomerController@showcust')->name('customers');
    Route::post('/sendcust', 'CustomerController@sendcust')->name('sendcust');


    //Items
    Route::get('/items', 'ItemController@showitems')->name('items');
    Route::post('/senditem', 'ItemController@senditem')->name('senditem');

    //Projects
    Route::get('/projects', 'ProjectController@showprojects')->name('projects');
    Route::post('/sendproj', 'ProjectController@sendproj')->name('sendproj');
    //ProjectBillings
    Route::get('/projects/{id}/billings', 'ProjectController@showbilling')->name('showbilling');
    Route::post('/projects/{id}', 'ProjectController@addbilling')->name('addbilling');  

    //Invoices
    Route::get('/invoices', 'InvoiceController@showinvoice')->name('invoices');
    Route::post('/sendinvoitem', 'InvoiceController@sendinvoitem')->name('sendinvoitem');
    Route::get('/invoices/{id}/details', 'InvoiceController@showdetails');
    Route::post('/updateitem','InvoiceController@updatedetail')->name('updateitem');
    Route::get('invoices/{id}/generate', 'InvoiceController@generate');
    Route::post('/updatestatus', 'InvoiceController@changestatus')->name('updatestatus');

});
  • 写回答

1条回答 默认 最新

  • doulang9521 2019-05-14 17:32
    关注

    You are passing 2 params in your route but accepting only 1 in the controller. Add locale.

    public function showbilling($locale, $id)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误