laravel route group controller code example

Example 1: laravel route namespace and prefix

Route::prefix('admin')->group(function () {
    Route::get('/users', function () {
        // Matches The "/admin/users" URL
    });
});

Example 2: group routes in laravel

Route::middleware(['first', 'second'])->group(function () {
    Route::get('/', function () {
        // Uses first & second middleware...
    });

    Route::get('/user/profile', function () {
        // Uses first & second middleware...
    });
});

Example 3: laravel group routes

Route::group(['prefix' => 'admin'], function () {
    Route::get('users', function ()    {
        // Matches The "/admin/users" URL
    });
});

Example 4: route group in laravel

Route::group(['prefix' => 'admin']){
	Route::get('/',function(){
    	//...
    });
}

Example 5: laravel route

Route::get('user/profile', [UserProfileController::class, 'show'])->name('profile');

Example 6: comment = Comment::find($this->route('comment')); in laravel

Schema::create('comments', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users')->onCascade('update')->onDelete('cascade');
            $table->integer('post_id')->unsigned();
            $table->foreign('post_id')->references('id')->on('users')->onCascade('update')->onDelete('cascade');
            $table->text('comment');
            $table->timestamps();
            $table->rememberToken();
        });