mercredi 28 octobre 2015

laravel route with parameter not coming from url

I have multiple routes that look like this:

Route::get('pending-submit', 'CasesController@cases');
Route::get('submited', 'CasesController@cases');
Route::get('closed', 'CasesController@cases');

I have been looking around even in the router API documentation and I can't find a solution for my requirement other than creating multiple methods within the controller. The method does the exact same query except for adding a where clause to identify the different status between each case, what I was trying to do is have a method like this

public function cases($whereStatus = 0){
    return Cases::where('status', $whereStatus)->get();
}

Instead of doing this:

public function pendingCases(){
    return Cases::where('status', 0)->get();
}

public function submitedCases(){
    return Cases::where('status', 1)->get();
}

public function closedCases(){
    return Cases::where('status', 2)->get();
}

But I can figure a way to pass that parameter to the method from the route so I now have to create a method for each route which does not seem necessary to me. I understand I could just generate urls with the get parameter in it but I wanted to make that cleaner, is there a way for me to add that parameter without having it in the url?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire