Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am successfully using the following codes to auto-route HTTP parameters to a model in Laravel:

Route::model('user', 'User', function()
{
    throw new AccountNotFoundException('Account does not exists.');
});

I recently started using namespaces to my classes and that's where the problem started.

So far, I tried this one to no avail:

Route::model('user', 'PackageName\User\Repository\User', ....blahh....)

Question: How do I specify the namespace on Model routes?

share|improve this question
add comment

1 Answer

Analyzing the error message itself, I chanced to solve the problem. Apparently the 2nd parameter of the Route::model() method accepts either a string class name or an object of the model itself:

Route::model('user', new PackageName\User\Repository\User, function()
{
    throw new AccountNotFoundException('Account does not exists.');
});

where:

new PackageName\User\Repository\User

is an instantiation of the namespaced model.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.