控制器返回空白数据/视图,我认为我的路线有问题。如果我删除{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');
});
答案 0 :(得分:0)
您在路由中传递了2个参数,但在控制器中仅接受了1个。添加语言环境。
public function showbilling($locale, $id)