Skip to content

Conversation

ryanw3b3r
Copy link

Without backslash Laravel will append namespace to main application namespace and will return an error "Class App\Http\Controllers\Laravel\Cashier\WebhookController does not exist".

Without backslash Laravel will append namespace to main application namespace and will return an error "Class App\Http\Controllers\Laravel\Cashier\WebhookController does not exist".
@GrahamCampbell
Copy link
Member

No it doesn't. That's not true at all. That will ONLY happen if you wrap things in a namespace group, and the example here is not wrapped in such a group.

@ryanw3b3r
Copy link
Author

I might be wrong here but I don't have webhook route wrapped in Route::group() so your comment seems to be not true at all to me. All I have at the end of my routes.php is (no group around it):

Route::post('stripe/webhook', '\Laravel\Cashier\WebhookController@handleWebhook');

and it works. When I remove the backslash and I try this route via Postman (POST) it gives me an error.

@GrahamCampbell
Copy link
Member

All I have at the end of my routes.php is (no group around it):

No, it does. Laravel wraps it in a group when it loads it.

@GrahamCampbell
Copy link
Member

@GrahamCampbell
Copy link
Member

All I have at the end of my routes.php is (no group around it):

So there is a group. ;)

@GrahamCampbell
Copy link
Member

Laravel doesn't magically guess the namespace you see. ;)

@ryanw3b3r
Copy link
Author

Ok, I don't want to argue here, but to me if we want to have the best framework documentation ever, then we have to add notes in the docs. This is not explained and people might just simply copy&paste Taylor's example and it will not work. Majority of people won't go into Postman to test this route, they will rely on Taylor's example. Thanks anyway, but I don't understand why are we doing things like this, ie. "example in docs is not wrapped in group so there's no backslash" but obviously it will be wrapped up in a group automatically! Weird approach.

@ryanw3b3r
Copy link
Author

I'm also not "magically guessing" why docs example doesn't work. Your comment is really unnecessary here.

@GrahamCampbell
Copy link
Member

I'm also not "magically guessing" why docs example doesn't work

I wasn't saying that all. I'm saying Laravel can't magically guess the namespace.

@GrahamCampbell
Copy link
Member

but obviously it will be wrapped up in a group automatically! Weird approach.

It's only wrapped in a group because the user does that in their route service provider. That's no secret.

@GrahamCampbell
Copy link
Member

That said, you are correct in saying that copying and pasting this example will often result in error due to oversight of users, so that's probably good enough reason to change it tbh, so thanks for bringing this up.

taylorotwell added a commit that referenced this pull request Sep 7, 2015
Added backslash before route namespace
@taylorotwell taylorotwell merged commit 6322a67 into laravel:5.1 Sep 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants