http://laravel.com/docs/のいくつかのチュートリアルに従いましたが、うまくいきません。これが私が試したことです:
ロールモデル:
<?php
class Role extends Eloquent {
protected $table = 'accounts';
public function users()
{
return $this->belongsToMany('User');
}
}
RoleController.php
<?php
class RoleController extends BaseController {
public function get_role()
{
$roles = User::find(16)->group_id;
if ($roles->contains(3))
{
echo 'this works';
}
else
{
return Redirect::to('news/index');
}
}
}
そして私のルート:
Route::get('dash', 'RoleController@get_role');
そして、ここに私のエラーがあります:
Call to a member function contains() on a non-object
エラーがオンラインであると言います:
if ($roles->contains(3))
containsメソッドのように...私は知りません。
また、$roles = User::find(16)->group_id;
16はid
アカウントのですよね?で、group_id
テーブルは?
前もって感謝します。
編集:
RoleController.php
解決策は次のとおりです。次のように変更しました。
<?php
class RoleController extends BaseController {
public function get_role()
{
$roles = User::find(16)->group_id;
if (if ($roles == '1')
{
echo 'this works';
}
else
{
return Redirect::to('news/index');
}
}
}