vendredi 18 septembre 2015

Ignore route in Laravel 5.1

I want to create dynamic pages CMS for my Laravel app. Admin is allowed to provide any URI for any page, so for example, he can create page with one/two/three URI and http://ift.tt/1W7e1Ij will point to this site. I already figured out it's possible to add single route for multiple level URLs like this:

get('{uri}', 'PageController@view')->where('uri', '.+');

Now, I also want to have /{username} URLs to point to users profiles. That means, if I need to make it work together. For me, the perfect code would be something like this:

get('{username}', 'ProfileController@view');
get('{uri}', 'PageController@view')->where('uri', '.+');

Then, in ProfileController I'd like to make my route go further just like it wasn't there. Something like this:

// ProfileController

public function view()
{
    $user = User::whereUsername($username)->first();

    if ($user === null) {
        // Go to the next route.
    }
}

Can it be done with Laravel?

I can think of another solution, just to have dynamic routing controller for both usernames and page uris mapping, but I would prefer to have it as separate routes.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire