Support the ongoing development of Laravel.io →
posted 10 years ago
Requests
Last updated 2 years ago.
0

Try using:

Route::get('setting/{id?}', function($key,$name,$id = null) {

        if($id) {
            return "Ceci est ma route avec mon id {$id}";
        } else {
            return "This is my route without my id";
        }
});

Your function should know about all the parameters in the url.

In your case, the id parameter is the third, and your function catches only the first parameter

Last updated 2 years ago.
0

Yes! it works . but I suddenly found another problem. In the context here , many controller will start from that route prefix

Route::group(['prefix' => 'book/{key}/{name}', 'as' => 'book.profile'], function()
{
    Route::get('/', 'HomeController@Home');

    Route::get('setting/{id?}', 'UserController@setting');

    Route::get('diary', 'UserController@listDiary');

    Route::get('diary/edit/{num}', 'UserController@editDiary');

    Route::get(.....
});

How in this context there. Because I will have many routes. And if I have each time add the key $ $ name parameters and this may be quite complicated .

I thought the constructor of the class by sending both parameters. But I dry a little. Thank you for your help @moinecumihai

Last updated 2 years ago.
0

I didn't quite understand what you wanted to say.

If you don't want a controller to use those parameter, you simply take the controller out of the group. You can always to this

Route::group(array('prefix'=>'foo1'),function(){
    Route::any('ba1r',array('uses=>'FooController@ba1r'));
    Route::any('bar1/{id}',array('uses=>'FooController@bar1Show'));
});

Route::any('test1',array('uses'=>'TestController@method1'));
Route::any('test2',array('uses'=>'TestController@method2'));

Route::group(array('prefix'=>'foo2/{param}'),function(){
    Route::any('bar2',array('uses=>'FooController@bar2'));
    Route::any('bar2/{id}',array('uses=>'FooController@bar2Show'));
});

Last updated 2 years ago.
0

Oh, now I understood,

You were referring to something like this, and you don't want to get all three parameters in the method.

class UserController{
    public function editDiary($book,$name,$id){
    }

}

I don't have an answer for this question for now, but I will try looking into it. P.S.: If you find it first, please let me know. It's something I, too, need.

Last updated 2 years ago.
0

Yes it's that. No problem, for now I must to work on another module where I did not need to use the route for the moment. But Monday I would return to this part here at work, and I think look on my side this weekend at home. If I find I come back here post a solution.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

theshadoo theshadoo Joined 3 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.