• Developer New

    Friday, March 24, 2017

    how to use route in laravel 5.4 5.3

    Route::get('URL', function(){});
    Route::get($url, 'Controller@method');
    // RESTful actionsRoute::controller($baseUrl, 'FooController');
    Route::resource($url, 'PostsController');
    Triggering Errors
    App::abort(404);
    App::missing(function($exception){});
    throw new NotFoundHttpException;
    Route Parameters
    Route::get('foo/{bar}', function($bar){});
    Route::get('foo/{bar?}', function($bar = 'bar'){});
    HTTP Verbs
    Route::any($uri, function(){});
    Route::post($url, function(){});
    Route::put($url, function(){});
    Route::patch($url, function(){});
    Route::delete($url, function(){});
    Route::match(['GET', 'POST'], $url, function(){});
    // RESTful actionsRoute::resource($baseUrl, 'FooController');
    Secure Routes
    Route::get($uri, ['https', function(){}]);
    Route Constraints
    Route::get('foo/{bar}', function($bar){})
    ->where('bar', '[0-9]+');
    Route::get('foo/{bar}/{baz}', function($bar, $baz){})
    ->where(['bar' => '[0-9]+', 'baz' => '[A-Za-z]'])
    // Set a pattern to be used across routesRoute::pattern($key, '[0-9]+')
    Filters
    // Declare an auth filterRoute::filter('auth', function(){});
    // Register a class as a filterRoute::filter($uri, 'FooFilter');
    Route::get($uri, ['before' => 'auth', function(){}]);
    // Routes in this group are guarded by the 'auth' filterRoute::get($uri, ['before' => 'auth', function(){}]);
    Route::group(['before' => 'auth'], function(){});
    // Pattern filterRoute::when('foo/*', 'foo');
    // HTTP verb patternRoute::when('foo/*', 'foo', ['post']);
    Named Routes
    Route::currentRouteName();
    Route::get('foo/bar', ['as' => 'foobar', function(){}]);
    Route::get('foo/bar', ['as' => 'foobar', 'uses' => 'ControllerName@function']);
    Route Prefixing
    // This route group will carry the prefix 'foo'Route::group(['prefix' => $uri], function(){})
    Sub-Domain Routing
    // {sub} will be passed to the closureRoute::group(['domain' => '{sub}.example.com'], function(){});

    No comments:

    Post a Comment

    Fashion

    Beauty

    Travel