Laravel - Larabook"方法[执行]不存在。"

时间:2014-12-09 07:07:36

标签: laravel laravel-4

我正在关注Laracasts的Larabook教程。我关注的是“跟随用户”#39;部分。我为所有用户的个人资料添加了一个关注按钮,但是我坚持使用" BadMethodCallException方法[执行]不存在。"错误。这是我的FollowsController;

<?php

use Larabook\Users\FollowUserCommand;

class FollowsController extends \BaseController {

/**
 * Follow a user
 *
 * @return Response
 */
public function store()
{
    //id of the user to follow
    //id of the authenticated user
    $input = array_add(Input::all(), 'userId', Auth::id());
    $this->execute(FollowUserCommand::class, $input);
    Flash::success('You are now following this user.');
    return Redirect::back();
}


/**
 * Unfollow a user
 *
 * @param  int  $id
 * @return Response
 */
public function destroy($id)
{
    //
}

}

1 个答案:

答案 0 :(得分:1)

根据instructions of the laracasts/Commander package,您需要在控制器中注入Commander Trait,以便能够访问execute等方法。

您可以在BaseController中执行此操作,以便在扩展BaseController的每个控制器中使用它:

class BaseController extends Controller {
    use CommanderTrait;
}

或仅在控制器本身:

class FollowsController extends \BaseController {
    use CommanderTrait;

    // your methods
}