php - Laravel Routes Based On MySQL Queries -


i'm trying build catalog of movies own , set route so

route::get('movie/{name}', array('uses' => 'moviecontroller@showmovie')); 

with controller of

class moviecontroller extends basecontroller  { public function showmovie($name) {     $movie = movie::firstbyatrributes(array('name' => $name));      return view::make('movie', array( 'movie' => $movie));     } } 

however, want name pulled database, instance if have table called movies, within table have, id, title , cover_art.

when type myurl.com/movie/findingnemo display relevant information movie me without having create movietitle.blade.php every movie own.

i can figure out view, it's routing i'm struggling with

how can accomplish this?

thanks!

if change code following, should work myurl.com/movie/{movieid} pull movie want. seems make more sense me, titles have spaces , things make pain put url.

so you're looking at:

class moviecontroller extends basecontroller{     public function showmovie(movie $movie){         return view::make('movie', compact('movie'));     } } 

then in view, movie able called $movie->title or whatever each movie id.

you'll have define model in route.php

route::model('movie','movie'); 

and change route::get('movie/{name}' route::get('movie/{movie}'

hope helps!


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -