Laravel 4 routing to controller method

I'm currently trying to get directions as follows:

  • If the user is GET /account/
    • If the session has account_id, the user is logged in; show account information.
    • If not, the user is not logged in; show login / create form
  • If custom post /account/
    • If there is an input create, the user wants to create an account; create it
    • If not, the user wants to log in; find his account and go to/account/

My routes are set as follows:

Route::get('account', function() {
    if (Session::has('account_id'))
        return 'AccountsController@show';
    else
        return 'AccountsController@index';
});

Route::post('account', function() {
    if (Input::has('create')) {
        return 'AccountsController@create';
    else    
        return 'AccountsController@login';
)};

Here's how to do it with Rails, but I don't know how to point to the controller method. As a result, I get the returned string. I did not find it in the Laravel documentation (what did I find very bad, or did I search incorrectly?) Not in any other web tutorial.

+3
2

:

Route::get('account', function() {
    if (Session::has('account_id')) {
        $action = 'show';
        return App::make('AccountsController')->$action();  
    }
    else {
        $action = 'index'; 
        return App::make('AccountsController')->$action();
    }
});

Route::post('account', function() {
    if (Input::has('create')) {
        $action = 'create';
        return App::make('AccountsController')->$action();
    }
    else {
        $action = 'login';
        return App::make('AccountsController')->$action();
    }
)};
+9

, .

Route::get('account', 'AccountsController@someFunction'); 
Route::get('account', 'AccountsController@anotherFunction');

, , ,

if (Session::has('account_id')){
    return Redirect::action('AccountsController@show');
}
else{
    return Redirect::action('AccountsController@index');
}

, , URL.
,

 Redirect::action('AccountsController@show')

, :

Route::get('/account/show', 'AccountsController@show')
0

All Articles