Skip to content

Instantly share code, notes, and snippets.

@sam-ngu
Last active June 16, 2021 08:08
Show Gist options
  • Select an option

  • Save sam-ngu/c82383172be8524fdd337ba4cccf26bb to your computer and use it in GitHub Desktop.

Select an option

Save sam-ngu/c82383172be8524fdd337ba4cccf26bb to your computer and use it in GitHub Desktop.

Revisions

  1. sam-ngu revised this gist Jun 16, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions route_group_array_syntax.php
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,8 @@
    Route::get('/users', [\App\Http\Controllers\UserController::class, 'index'])
    ->name('index');

    // Once we defined the 'namespace' attribute, we can invoke our controller method
    // by using the <controller_class>@<method> string
    Route::post('/users', 'UserController@store')
    ->name('store');

  2. sam-ngu revised this gist Jun 16, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions route_group_array_syntax.php
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,8 @@
    'auth:api',
    \App\Http\Middleware\RedirectIfAuthenticated::class,
    ],
    'prefix' => 'heyaa', // adding url prefix to all route in this group
    'as' => 'users.', // adding url name
    'prefix' => 'heyaa', // adding url prefix to all routes in this group
    'as' => 'users.', // adding route name prefix to all routes in this group
    'namespace' => "\App\Http\Controllers",
    ], function(){
    Route::get('/users', [\App\Http\Controllers\UserController::class, 'index'])
  3. sam-ngu revised this gist Jun 16, 2021. 2 changed files with 2 additions and 1 deletion.
    1 change: 1 addition & 0 deletions route_group_array_syntax.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    <?php
    // using array syntax
    Route::group([
    'middleware' => [
    'auth:api',
    2 changes: 1 addition & 1 deletion route_group_method_syntax.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    <?php

    // using method syntax
    Route::middleware([
    'auth:api',
    \App\Http\Middleware\RedirectIfAuthenticated::class,
  4. sam-ngu revised this gist Jun 16, 2021. 2 changed files with 24 additions and 8 deletions.
    20 changes: 15 additions & 5 deletions route_group_array_syntax.php
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,19 @@
    'as' => 'users.', // adding url name
    'namespace' => "\App\Http\Controllers",
    ], function(){
    Route::get('/users', [\App\Http\Controllers\UserController::class, 'index'])->name('index');
    Route::post('/users', 'UserController@store')->name('store');
    Route::get('/users/{user}', [\App\Http\Controllers\UserController::class, 'show'])->name('show');
    Route::patch('/users/{user}', [\App\Http\Controllers\UserController::class, 'update'])->name('update');
    Route::delete('/users/{user}', [\App\Http\Controllers\UserController::class, 'destroy'])->name('destroy');
    Route::get('/users', [\App\Http\Controllers\UserController::class, 'index'])
    ->name('index');

    Route::post('/users', 'UserController@store')
    ->name('store');

    Route::get('/users/{user}', [\App\Http\Controllers\UserController::class, 'show'])
    ->name('show');

    Route::patch('/users/{user}', [\App\Http\Controllers\UserController::class, 'update'])
    ->name('update');

    Route::delete('/users/{user}', [\App\Http\Controllers\UserController::class, 'destroy'])
    ->name('destroy');

    });
    12 changes: 9 additions & 3 deletions route_group_method_syntax.php
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,13 @@
    Route::get('/users/{user}', [\App\Http\Controllers\UserController::class, 'show'])
    ->name('show');

    Route::post('/users', [\App\Http\Controllers\UserController::class, 'store'])->name('store');
    Route::patch('/users/{user}', [\App\Http\Controllers\UserController::class, 'update'])->name('update');
    Route::delete('/users/{user}', [\App\Http\Controllers\UserController::class, 'destroy'])->name('destroy');
    Route::post('/users', [\App\Http\Controllers\UserController::class, 'store'])
    ->name('store');

    Route::patch('/users/{user}', [\App\Http\Controllers\UserController::class, 'update'])
    ->name('update');

    Route::delete('/users/{user}', [\App\Http\Controllers\UserController::class, 'destroy'])
    ->name('destroy');

    });
  5. sam-ngu revised this gist Jun 16, 2021. 2 changed files with 2 additions and 3 deletions.
    2 changes: 2 additions & 0 deletions route_group_array_syntax.php
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,6 @@
    Route::get('/users', [\App\Http\Controllers\UserController::class, 'index'])->name('index');
    Route::post('/users', 'UserController@store')->name('store');
    Route::get('/users/{user}', [\App\Http\Controllers\UserController::class, 'show'])->name('show');
    Route::patch('/users/{user}', [\App\Http\Controllers\UserController::class, 'update'])->name('update');
    Route::delete('/users/{user}', [\App\Http\Controllers\UserController::class, 'destroy'])->name('destroy');
    });
    3 changes: 0 additions & 3 deletions route_group_method_syntax.php
    Original file line number Diff line number Diff line change
    @@ -14,10 +14,7 @@
    Route::get('/users/{user}', [\App\Http\Controllers\UserController::class, 'show'])
    ->name('show');


    Route::post('/users', [\App\Http\Controllers\UserController::class, 'store'])->name('store');

    Route::patch('/users/{user}', [\App\Http\Controllers\UserController::class, 'update'])->name('update');

    Route::delete('/users/{user}', [\App\Http\Controllers\UserController::class, 'destroy'])->name('destroy');
    });
  6. sam-ngu created this gist Jun 16, 2021.
    14 changes: 14 additions & 0 deletions route_group_array_syntax.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <?php
    Route::group([
    'middleware' => [
    'auth:api',
    \App\Http\Middleware\RedirectIfAuthenticated::class,
    ],
    'prefix' => 'heyaa', // adding url prefix to all route in this group
    'as' => 'users.', // adding url name
    'namespace' => "\App\Http\Controllers",
    ], function(){
    Route::get('/users', [\App\Http\Controllers\UserController::class, 'index'])->name('index');
    Route::post('/users', 'UserController@store')->name('store');
    Route::get('/users/{user}', [\App\Http\Controllers\UserController::class, 'show'])->name('show');
    });
    23 changes: 23 additions & 0 deletions route_group_method_syntax.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <?php

    Route::middleware([
    'auth:api',
    \App\Http\Middleware\RedirectIfAuthenticated::class,
    ])
    ->name('users.') // you can use the as() method here as well
    ->namespace("\App\Http\Controllers")
    ->prefix('heyaa')
    ->group(function () {
    Route::get('/users', [\App\Http\Controllers\UserController::class, 'index'])
    ->name('index');

    Route::get('/users/{user}', [\App\Http\Controllers\UserController::class, 'show'])
    ->name('show');


    Route::post('/users', [\App\Http\Controllers\UserController::class, 'store'])->name('store');

    Route::patch('/users/{user}', [\App\Http\Controllers\UserController::class, 'update'])->name('update');

    Route::delete('/users/{user}', [\App\Http\Controllers\UserController::class, 'destroy'])->name('destroy');
    });