leminhluan4244 / aptech-laravel-ecommerce-demo

0 stars 0 forks source link

Route::prefix hoặc Route::<function>()->prefix #4

Open leminhluan4244 opened 2 months ago

leminhluan4244 commented 2 months ago

Thay vì viết:

<?php
Route::get('user/', [HomeController::class, 'index'])->name('user');
// Profile
Route::get('user/profile', [HomeController::class, 'profile'])->name('user-profile');
Route::post('user/profile/{id}', [HomeController::class, 'profileUpdate'])->name('user-profile-update');
//  Order
Route::get('user/order', [HomeController::class, "orderIndex"])->name('user.order.index');
Route::get('user/order/show/{id}', [HomeController::class, "orderShow"])->name('user.order.show');
Route::delete('user/order/delete/{id}', [HomeController::class, 'userOrderDelete'])->name('user.order.delete');
// Product Review
Route::get('user/user-review', [HomeController::class, 'productReviewIndex'])->name('user.productreview.index');
Route::delete('user/user-review/delete/{id}', [HomeController::class, 'productReviewDelete'])->name('user.productreview.delete');
Route::get('user/user-review/edit/{id}', [HomeController::class, 'productReviewEdit'])->name('user.productreview.edit');
Route::patch('user/user-review/update/{id}', [HomeController::class, 'productReviewUpdate'])->name('user.productreview.update');

// Post comment
Route::get('user/user-post/comment', [HomeController::class, 'userComment'])->name('user.post-comment.index');
Route::delete('user/user-post/comment/delete/{id}', [HomeController::class, 'userCommentDelete'])->name('user.post-comment.delete');
Route::get('user/user-post/comment/edit/{id}', [HomeController::class, 'userCommentEdit'])->name('user.post-comment.edit');
Route::patch('user-post/comment/udpate/{id}', [HomeController::class, 'userCommentUpdate'])->name('user.post-comment.update');

// Password Change
Route::get('user/change-password', [HomeController::class, 'changePassword'])->name('user.change.password.form');
Route::post('user/change-password', [HomeController::class, 'changPasswordStore'])->name('user.change.password.submit');

Bạn có thể viết:

Route::prefix('user')->group(function () {
    Route::get('/', [HomeController::class, 'index'])->name('user');
    // Profile
    Route::get('/profile', [HomeController::class, 'profile'])->name('user-profile');
    Route::post('/profile/{id}', [HomeController::class, 'profileUpdate'])->name('user-profile-update');
    //  Order
    Route::get('/order', [HomeController::class, "orderIndex"])->name('user.order.index');
    Route::get('/order/show/{id}', [HomeController::class, "orderShow"])->name('user.order.show');
    Route::delete('/order/delete/{id}', [HomeController::class, 'userOrderDelete'])->name('user.order.delete');
    // Product Review
    Route::get('/user-review', [HomeController::class, 'productReviewIndex'])->name('user.productreview.index');
    Route::delete('/user-review/delete/{id}', [HomeController::class, 'productReviewDelete'])->name('user.productreview.delete');
    Route::get('/user-review/edit/{id}', [HomeController::class, 'productReviewEdit'])->name('user.productreview.edit');
    Route::patch('/user-review/update/{id}', [HomeController::class, 'productReviewUpdate'])->name('user.productreview.update');

    // Post comment
    Route::get('user-post/comment', [HomeController::class, 'userComment'])->name('user.post-comment.index');
    Route::delete('user-post/comment/delete/{id}', [HomeController::class, 'userCommentDelete'])->name('user.post-comment.delete');
    Route::get('user-post/comment/edit/{id}', [HomeController::class, 'userCommentEdit'])->name('user.post-comment.edit');
    Route::patch('user-post/comment/udpate/{id}', [HomeController::class, 'userCommentUpdate'])->name('user.post-comment.update');

    // Password Change
    Route::get('change-password', [HomeController::class, 'changePassword'])->name('user.change.password.form');
    Route::post('change-password', [HomeController::class, 'changPasswordStore'])->name('user.change.password.submit');

});