Laravel - 扩展ResourceController

i have two different forms that should use one controller. I created this controller as a resource controller using the following method in the routes.php:

Route::resource('account', 'AccountController');

In the first form I use

{{ Form::model($user, array('route' => array('account.update', $user->id), 'method' => 'PUT', 'class' => 'form-outside', 'files' => true)) }}

As the resource controller knows the update function this works well.

However i want to create a second form, which relates to the account and updates other sections of a user's profile. I now want to extend the Controller by a function like "updateSettings."

But how can i do that? I created a function in the AccountController and use the following in the second form:

{{ Form::model($user, array('action' => array('AccountController@updateSettings', $user->id), 'method' => 'PUT', 'class' => 'form-outside')) }}

But Laravel fires an exception that

Route [AccountController@updateSettings] not defined.

How can i extend my Resource controller that updateSettings is a valid method? Or how can i use the model binding forms without a resource controller?

Thanks!

To fully extend the resource controller you would need to extend the class Illuminate\Routing\Router and override the needed methods. Next step is to use App::bind() to substitute old Router class with the new one you would write.

Faster method is to use just a new route, giving it an unique name, for ex in your routes.php: App::put('updateSettings', 'AccountController@updateSettings'). Good luck.

Or how can i use the model binding forms without a resource controller?

So, in this case you may bind a model from the controller, actually you may manually pass the model, for example, if you have a Post model and want to edit a post then you may manually load the model from controller and pass it to the view to bind with form, for example:

class PostController extends BaseController {

    //...
    public function getEdit($id)
    {
        $post = Post::find($id);
        return View::make('post.edit')->with('post', $post);
    }

    public function postUpdate($id)
    {
        //...
    }
}

Then in your views/post/edit.blade.php you may use something like this:

{{ Form::model($post, array('route' => array('post.update', $post->id) )) }}

Now you need to create routes for these methods, like this:

Route::get('post/edit/{id}', array('as' => 'post.edit', 'uses' => 'PostController@getEdit'));
Route::post('post/update/{id}', array('as' => 'post.update', 'uses' => 'PostController@postUpdate'));