Skip to content

Instantly share code, notes, and snippets.

@soediro
Forked from andy-williams/lumen-cheatsheet.md
Created April 9, 2021 08:34
Show Gist options
  • Save soediro/b8b16cd1618f052b2ef2f9b626def5f5 to your computer and use it in GitHub Desktop.
Save soediro/b8b16cd1618f052b2ef2f9b626def5f5 to your computer and use it in GitHub Desktop.

Revisions

  1. @andy-williams andy-williams revised this gist Jan 2, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions lumen-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,12 @@

    ### install global installer
    `composer global require "laravel/lumen-installer"`

    `composer global require "laravel/installer"`

    ### start new project
    `lumen new {project-name}`

    `laravel new {project-name}`

    ### start app
  2. @andy-williams andy-williams revised this gist Jan 2, 2017. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions lumen-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,14 @@
    # Lumen / Laravel Cheat sheet

    ## Install Lumen
    ## Install Lumen / Laravel

    ### install global lumen installer
    ### install global installer
    `composer global require "laravel/lumen-installer"`
    `composer global require "laravel/installer"`

    ### start new lumen project
    ### start new project
    `lumen new {project-name}`
    `laravel new {project-name}`

    ### start app
    `php -S localhost:8000 -t public`
  3. @andy-williams andy-williams revised this gist Dec 31, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions lumen-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Lumen / Laravel Cheat sheet

    ## Install Lumen

    ### install global lumen installer
  4. @andy-williams andy-williams revised this gist Dec 31, 2016. 1 changed file with 66 additions and 2 deletions.
    68 changes: 66 additions & 2 deletions lumen-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -54,10 +54,74 @@

    $url = route('profile');

    ### Base Route / Prefix
    ### Route Groups

    Allows a group of routes to share namespaces, prefix and middleware

    #### Middleware

    $app->group(['middleware' => 'auth'], function () use ($app) {
    $app->get('/', function () {
    // Uses Auth Middleware
    });

    $app->get('user/profile', function () {
    // Uses Auth Middleware
    });
    });

    #### Base Route / Prefix

    $app->group(['prefix' => 'accounts/{account_id}'], function ($app) {
    $app->get('detail', function ($account_id) {
    // Matches The accounts/{account_id}/detail URL
    });
    });
    });


    ## Middleware

    A middleware is a layer that lives between the `web request handler (web server)` and the `router and controller`.

    `request -> middleware -> routing/controller`

    This allows you to modify the request before being passed to the controller, check for `tokens`, start a timer before and stop after allowing you to log how long the controller takes etc.


    ### Creating a Middleware

    <?php
    namespace App\Http\Middleware;
    use Closure;
    class MyMiddleware
    {
    public function handle($request, Closure $next)
    {
    // before
    $response = $next($request);
    // after
    return $response;
    }
    }
    ### Using a Middleware
    #### All Requests
    $app->middleware([
    App\Http\Middleware\App\Http\Middleware\MyMiddleware::class
    ]);

    #### Only Certain Routes


    $app->routeMiddleware([
    'middleware' => App\Http\Middleware\App\Http\Middleware\MyMiddleware::class
    ]);

  5. @andy-williams andy-williams revised this gist Dec 31, 2016. 1 changed file with 42 additions and 0 deletions.
    42 changes: 42 additions & 0 deletions lumen-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -19,3 +19,45 @@

    `$config_key = env('{config-key}')`


    ## Routing

    **Note: Route parameters cannot contain the - character. Use an underscore (_) instead.**

    ### Verbs

    $app->get($uri, $callback);
    $app->post($uri, $callback);
    $app->put($uri, $callback);
    $app->patch($uri, $callback);
    $app->delete($uri, $callback);
    $app->options($uri, $callback);


    ### Route Parameters

    $app->get('user/{id}, function(Request $req, $id) {
    //
    }

    ### Constrained Route Parameters

    $app->get('user/{name:[A-Za-z]+}', function ($name) {
    //
    });

    ### Named Routes

    $app->get('profile', ['as' => 'profile', function (Request $req) {
    //
    }]);

    $url = route('profile');

    ### Base Route / Prefix

    $app->group(['prefix' => 'accounts/{account_id}'], function ($app) {
    $app->get('detail', function ($account_id) {
    // Matches The accounts/{account_id}/detail URL
    });
    });
  6. @andy-williams andy-williams revised this gist Dec 31, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lumen-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ## Install Lumen

    ### install global install
    ### install global lumen installer
    `composer global require "laravel/lumen-installer"`

    ### start new lumen project
  7. @andy-williams andy-williams created this gist Dec 31, 2016.
    21 changes: 21 additions & 0 deletions lumen-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    ## Install Lumen

    ### install global install
    `composer global require "laravel/lumen-installer"`

    ### start new lumen project
    `lumen new {project-name}`

    ### start app
    `php -S localhost:8000 -t public`

    ## Config

    ### change config

    `.env` in `root dir`

    ### access config

    `$config_key = env('{config-key}')`