本文介绍了Laravel:缺少论点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立此网站,我想传递url参数

I am building this website and I want to pass url parameters

http://movies.com/people?genre=action

应生成所有带有genre = action列出的人员

Should generate all the people listed with genre=action

这是我的路线

Route::resource(Str::slug(trans('main.people')), 'ActorController');

这是我的ActorController

This is my ActorController

public function index($input)
{

if (isset($input['genre']) && $input['genre'] != 'all')
    {
        return $this->actor->where('genre', 'like', '$input');

        return View::make('Actor.All')->withActors($actors);
    }
    else
    {

         return View::make('Actor.All')->withActors($actors);
}
}

我一直收到此错误 ErrorExceptionActorController :: index()缺少参数1

I keep receiving this error ErrorExceptionMissing argument 1 for ActorController::index()

推荐答案

查询字符串不会自动传递给控制器​​的方法,您需要手动获取它们:

Query strings aren't passed down automatically to controller's method, you need to fetch them manually:

public function index()
{
  if(Input::has('genre') && Input::get('genre') != 'all') {
     $this->actor->where('genre', 'like', Input::get('genre'));

  }
  return View::make('Actor.all')->withActors($this->actor);
}

这篇关于Laravel:缺少论点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 08:30