Lavarel5.1 시작 - 라우팅

1765 단어
Route::get('/', function () {
    return view('welcome');
});
Route::any('/hello',function(){
    return "Hello Laravel!";
});
Route::match(['get','post'],'/hello',function(){
   return "Hello Laravel![get/post]";
});
Route::post('/hello',function(){
    return "Hello Laravel[POST]!";
});
Route::get('/hello', function () {
    return "Hello Laravel[GET]!";
});
Route::get('/hello/{name}',function($name){
//name 
    return "Hello {$name}!";
});
Route::get('/hello/{name?}',function($name="Laravel"){
//name 
    return "Hello {$name}!";
});
Route::get('/hello/{name?}',function($name="Larave2"){
//name 
    return "Hello {$name}!";
})->where('name','[A-Za-z]+');
// , app/Providers/RouteServiceProvider.php boot :
public function boot(Router $router)
{
    $router->pattern('name','[A-Za-z]+');
    parent::boot($router);
}

라우팅 이름
Route::get('/hello/laravelacademy',['as'=>'academy',function(){
    return 'Hello LaravelAcademy!';
}]);
Route::get('/testNamedRoute',function(){
   return redirect()->route('academy');
});

라우팅 그룹
Route::group(['as' => 'admin::'], function () {
    Route::get('dashboard', ['as' => 'dashboard', function () {
        return "admin::dashboard";
    }]);
});
Route::get('/testNamedRoute',function(){
    return redirect()->route('admin::dashboard');
});

참고


Laravel 5.1 기본 자습서

좋은 웹페이지 즐겨찾기