justinkekeocha / udemy

Udemy clone using VITL stack: Vue, Inertia.JS, TailwindCSS and Laravel
https://udemy.justinkekeocha.com
2 stars 0 forks source link

Prefer resource routes over route controllers #2

Open newtonjob opened 1 year ago

newtonjob commented 1 year ago

https://github.com/justinkekeocha/udemy/blob/fdc6555aeeb4da81cfde8a64064899905aeb411f/routes/web.php#L54

Resource routes typically offer better flexibility for model resources. In addition, it can be a good way to keep your routes looking simple and clean;

For example, instead of;

Route::prefix('/topic/{topic}')->controller(TopicController::class)->name('topics.')->group(function () {
   Route::get('/', 'show')->name('show');
});

Route::prefix('/course/{course}')->controller(CourseController::class)->name('courses.')->group(function () {
   Route::get('/', 'show')->name('show');
});

You might do something like this;

Route::resource('topic', TopicController::class)->only('show');

Route::resource('course', CourseController::class)->only('show');
justinkekeocha commented 1 year ago

Correction taken. I will apply this in the new web app I am building, using the API resource route. Thanks.