dimanche 4 octobre 2015

Laravel controller method for router with an optional parameter

I'd like to have a controller handling url like .../item/list and .../item/list/5. First one would be to display all items, second one would display items whose author has an ID = 5.

public function getList($userid) {
    $items = \DB::table('items')->get();
    if ($userid) $items = \DB::table('items')->where('user_id', '=', $userid)->get();
    foreach ($items as $item) {
        // ...
    }
}

URL like .../item has an argument missing. Is there option to solve this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire