StuBlackett
StuBlackett

Reputation: 3857

Laravel Routing Query

I've made some bespoke pages in my admin of my site and they as the first segment of the URL.

e.g

/property-hartlepool

I thought of adding a trap all route into my routes file :

Route::get('{any?}', 'PagesController@view');

The problem I have is it's totally overwriting my other routes, I guess that's the name of a trap all route. However I'd like it to skip if it can't find a match.

I had a route for admin

/admin

But now it throws a 404 Error...

My PagesController@view method is :

public function view(Request $request)
{
    $route = $request->segment(1); // $request->path();

    // get page content
    $page = Page::where('route', $route)->firstOrFail();

    // If not full width, get four latest properties
    //$properties = Property::latest_properties_for_frontend();

    //metadata
    $meta = get_metadata($page);

    //page is Temporary
    return view('frontend.'.themeOptions().'.page', [
        'route' => $route,
        'meta' => $meta,
        'page' => $page
    ]);
}

Is their a better way of doing this, I do have other routes that sit at "top" level too. e.g...

Route::get('/property/{property}/{propertyId}', 'PropertiesController@property');

Upvotes: 0

Views: 43

Answers (1)

N69S
N69S

Reputation: 17205

declare your trap Route as the last route.

Route::get('/admin', 'AdminController@view');
...
...
Route::get('{any?}', 'PagesController@view');

Upvotes: 3

Related Questions