Laravel在非对象问题上调用成员函数follows()

时间:2018-12-14 10:46:26

标签: laravel symfony laravel-5 laravel-4 laravel-5.1

我的UserController包括以下内容:

public function doaction($domain, $some_id)
{
  $user = User::find(Sentry::getUser()->id);
  $user->doactions()->attach($some_id);
  $response = array('message' => 'doactioned', 'url' => 'http://'.$domain.'.'.Config::get('database.domain').'/undoaction/'.$some_id);
  return Response::json($response);
}

我的routes.php还包括以下行:

Route::get('/{name}/doaction/{some_id}', array('as' => 'doaction', 'uses' => 'UserController@doaction'));

我试图称这为他的前端:

<a href="{{URL::route('doaction', array('domain' => $blog->name, 'id' => $blog->id))}}" class="tumblerclone-btn"> <i class="glyphicon glyphicon-plus"></i> Do action here </a>

一旦按下它(URL已正确回显),就会导致我出现错误:

Symfony \组件\调试\异常\ FatalErrorException 在非对象上调用成员函数doactions()

该错误的突出显示的代码部分是:

public function doaction($domain, $some_id)
{
  $user = User::find(Sentry::getUser()->id);
  $user->doactions()->attach($some_id);
  $response = array('message' => 'doactioned', 'url' => 'http://'.$domain.'.'.Config::get('database.domain').'/undoaction/'.$some_id);
  return Response::json($response);
}

任何想法都需要事先感谢。

0 个答案:

没有答案