Hi, I'm starting with laravel and I'm building a simple CMS in order to learn how to use laravel. I have a pages table in my database and each page has a slug. This way I can set my routes to {slug} targeting my PagesController@index.
The problem is that some pages have different page types, like news, projects, etc. So something like /news/{slug} would work but I need to have multilanguage slugs like /noticias/{slug} and /news/{slug} pointing to the same page. This way, /noticias and /news are not the controller name, but just the slug of the page.
What I'm thinking it would work is checking if the slug exists in the database and which type that page is. Then, somehow, redirect to the correct controller.
This way I could have an URL like /news/some-news, check to see if news is a page in the database, check the page type and check (in another table) what controller that page type should use.
I'm not sure if this even makes sense... Appreciate any help.
Couldn't you just do multiple routes? (That saves a trip to the DB to verify)..
But I don't know the routes. I want to catch the URI, check the slug in the DB, and use the correct controller (page, news, etc) accordingly to the page type. The problem is that the news page can have any slug (/news, /hot-news, /noticias, etc). I need to check it in the DB to check the page type of that record and use the correct controller or model.
This way I'm not forced to use /news to load the News controller in all languages. I want to use the slug from the menu item and check it's page type. Then load the correct controller, model, view...
I'm thinking in maybe using a frontend controller to check the slug and correspondent page type, then redirect to the correspondent controller... But it doesn't feel solid...
Hmm, well, then you have to do a lookup for your page type and then slug (or maybe in the same lookup).. ? Do you have a github project for this? :)
ClausMunch said:
Hmm, well, then you have to do a lookup for your page type and then slug (or maybe in the same lookup).. ? Do you have a github project for this? :)
Not yet... I'm thinking in having a table in my DB with all possible page types and the correspondent Controller. Then use a "catch all" route to a controller that checks the page type for a given uri in the pages table.
Something like this: https://gist.github.com/fana605/85e4da394105ede0200c
This way, when a request is made to /latest-news, I have to check the pages table for a matching slug a get the page type. Then check the page_types table and get the controller name. What comes next is my doubt: How to load the correct controller from the "catch all" controller.
I guess this is not the best way of doing it. Maybe I can loop the pages table in the routes files, assigning the correct controller for each page directly...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community