0

I have a movies website that I want to allow people to search by genre

movies.com/people/action/genre

The Route

Route::get('people/{genre}/genre', array('uses' => 'ActorController@genre', 'as' => 'people.genre'));

The ActorController@genre

public function genre()
{

    $genre=Input::get('genre');
        $actors = $this->actor->allgenre($genre);
            return View::make('Actor.All')->withActors($actors);

}

This grabs all the actors from the db

function allGenre($genre)
{

        return $this->actor->where('genre', 'like', '$genre')->orderBy('views', 'desc')->paginate(24);

}

This is returning no results, when it should be returning results because if I go

function allGenre($genre)
{

        return $this->actor->where('genre', 'like', 'action')->orderBy('views', 'desc')->paginate(24);

}

Results show up

2
  • Why you tag it as symfony2 ? Commented Feb 7, 2014 at 8:48
  • Sorry cause im using the symfony2 package. Commented Feb 7, 2014 at 8:54

2 Answers 2

1

When you use that routing, the $genre variable would be bound the the controller:

public function genre($genre)
{
  $actors = $this->actor->allgenre($genre);
  return View::make('Actor.All')->withActors($actors);
}

While in your previous question you used query strings, so you needed Input::get('key'), now you changed the url, and you don't use resource controllers anymore, so you must go back to the "usual" way

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Damien Thanks for sharing , but it is still not returning results when I go movies.com/people/action/genre. How do I check if the $genre variable is getting passed to the allgenre function?
0

I got it to work

function allGenre($genre)
{

    return $this->actor->where('genre', 'like', $genre)->orderBy('views', 'desc')->paginate(24);

}

Apparently Laravel doesn't accept '$genre' with the ' around the variable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.