Category in urls

Posted 1 year ago by srikanthgopi

i'm creating an application where i have ArticleCategories and Articles tables.

And i have created Articles index page where i can list all the articles according to their categories. For example Category 1 -article1 -article2 -article3 view all

Category 2 -article1 -article2 -article3 view all

When i click on category1 i want to go to a new page where i can list all the articles in category1 with pagination similarly for other categories.

When i click on category1 and article1 i wan to to the a page showing that article. And the category name should be automatically included in the URL.

So im trying to achieve these route /articles {which lists all the articles in all categories} /articles/category-name {which lists all the articles in that category} /articles/category-name/article-title {to view article in that category}

I'm learning laravel so what i did is created categories and a new route, method in controller and views accordingly. For example, Route::get('/articles/health', '[email protected]')->name('health'); Route::get('/articles/health/{slug}', '[email protected]');

and i have created health and healthshow methods in Article Controller. And in views i have created a folder articles and subfolder health and in that i have created a index and show view files.

Similarly i need to create for each category which works fine. But the problem is i feel this is not dynamic as whenever i create a category i have to create a view folder which is same as category slug and a route. controller method accordingly.

Could someone explain me how to achieve this kind of functionality dynamically?

I also have profiles listed in my project so i want to achieve the following too /doctors/hyderabad/dermatologist/{slug}

Where /doctors route should show all the doctors in all categories and /doctors/hyderabad should show all the doctors in hyderabad and /doctors/hyderabad/dermatologist should show all doctors in hyderabad with dermatologist specialty. My tables are DoctorSpecialties, Doctors, Countries, States, Cities

I don't need code. I want to understand the concept how to achieve these kind of urls dynamically so that i can understand and code myself to learn the framework better. I guess i will need these kind of urls in every project

Please sign in or create an account to participate in this conversation.