trim()期望参数1为字符串,在laravel中给出数组

时间:2019-02-11 04:45:17

标签: laravel

如果将其添加到api.php路由中,则会出现此错误

 trim() expects parameter 1 to be string, array given in laravel     
 Route::get(['chapter/{chapter_id}/quiz' , 'API\QuizController@index']);
 Route::post(['chapter/{chapter_id}/quiz' , 'API\QuizController@store']);
 Route::put(['chapter/{chapter_id}/quiz/{id}' , 'API\QuizController@update']);

该行中发生错误

protected function prefix($uri)
{
    return trim(trim($this->getLastGroupPrefix(), '/').'/'.trim($uri, '/'), '/') ?: '/';
}

1 个答案:

答案 0 :(得分:1)

只需从您的路线中删除[]

 Route::get('chapter/{chapter_id}/quiz' , 'API\QuizController@index');
 Route::post('chapter/{chapter_id}/quiz' , 'API\QuizController@store');
 Route::put('chapter/{chapter_id}/quiz/{id}' , 'API\QuizController@update');