Контроллер возвращает пустые данные - PullRequest
0 голосов
/ 14 мая 2019

контроллер возвращает пустые данные / представление, и я думаю, что что-то не так с моими маршрутами.если я удаляю {locale}, данные извлекаются.

Может ли кто-нибудь помочь с правильным возвратом данных, пока в моих маршрутах есть {locale}?Вот мой связанный код:

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'));
}

Редактировать:Вот мой полный 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 Ответ

0 голосов
/ 14 мая 2019

Вы передаете 2 параметра в своем маршруте, но принимаете только 1 в контроллере. Добавить локаль.

public function showbilling($locale, $id)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...