【问题标题】:Missing required parameters for [Route: showbilling] [URI: {locale}/projects/{id}/billings][Route: showbilling] [URI: {locale}/projects/{id}/billings] 缺少必需参数
【发布时间】:2019-10-01 20:11:10
【问题描述】:

我认为这是我项目的最后一个问题。我在 1 条路由 {locale}/projects/{id}/billings 中有 2 个参数,问题是我在视图中传递了 2 个参数值,但它仍然提示缺少必需参数的错误。这是我的代码

web.php

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('/sendbilling', 'ProjectController@addbilling')->name('sendbilling');   

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

});

projects.blade.php

<a href="{{route('showbilling', ['locale' => app()->getLocale(), 'id' => $cat->id])}}" class="btn btn-default btn-xs waves-effect waves-float waves-green"> {{__('Add Billing')}} </a>

ProjectController.php

public function showbilling($locale, $id){
   $billings = Project::find($id);
   //return $billings;
   return view('admin.addbillings', compact('billings'));
}

【问题讨论】:

  • 你试过清除你的路由缓存吗? php artisan cache:clearphp artisan route:clear。我偶尔会遇到缺少参数的问题,我发现缓存是问题的 50/50。
  • 是的,还是一样的错误

标签: php laravel laravel-5.7


【解决方案1】:

更新

您将参数错误地传递给路由,您得到的错误是在路由器方法而不是在控制器中产生的,正确设置路由器方法,它应该可以解决您的问题。

Route::prefix('{locale}')->middleware('setlocale')->group(function(){
    Route::get('/projects/{id}/billings', 'ProjectController@showbilling')->name('showbilling');
})->where('locale' => '[a-zA-Z]{2}');

结果 URI /{locale}/project/{id}/billings

【讨论】:

  • 他正在使用前缀将语言环境添加到所有路由。 Route::group(['prefix' =&gt; '{locale}', 'where' =&gt; ['locale' =&gt; '[a-zA-Z]{2}']
  • @ImJT,对不起,我的错误,用输入更新了答案
  • 我可能不正确,但路线本身应该变成/{locale}/projects/{id}/billing。路由前缀将被添加到路由的开头,而不是中间。您还有一个额外的 /id/ 不在原始答案中。
  • @imJT,我明白你的意思,这是错字,我从之前的答案中复制了不正确的 url。但现在我已经更新了,
【解决方案2】:

我认为你现在应该改用这个 URL:/{locale}/showbilling(例如:"as/showbilling")。 {locale} 在路由器组中是有效的。所以,我猜你忘记了这个。

【讨论】:

    猜你喜欢
    • 2020-06-05
    • 1970-01-01
    • 2020-07-16
    • 2022-01-16
    • 2019-11-19
    • 2020-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多