很多很多人的关系都是很好的

时间:2014-10-27 16:59:31

标签: php mongodb laravel laravel-4 many-to-many

嗨,我是laravel和mongodb的新人。我在许多关系中编写了关于团队,用户和董事会的一些关系。但它不起作用!我应该怎么做控制器。

(我使用jenssegers / laravel-mongodb https://github.com/jenssegers/laravel-mongodb))

关系是用户1 .. * --- *团队* ---- 1 .. *董事会

用户(型号)

class User extends ...

public function teams()
{
  return $this->belongsToMany('Team', null, 'teamMembers', 'teams');
}

董事会(模特)

class Taskboard extends ...
public function teams()
{
   return $this->belongsToMany('Team', null, 'taskboards', 'teams');
}

团队(模型)

class Team extends ...
public function teamMembers()
{
  return $this->belongsToMany('User', null, 'teams', 'teamMembers');
}
public function taskboards()
{
  return $this->belongsToMany('Taskboard', null, 'teams', 'taskboards');
}

控制器团队//好的工作!

   public function store()
   {
    $team = new Team;
    $team->name = Input::get('teamname');
    $team->master =  Auth::user()->_id;
    $team =  Auth::user()->teams()->save($team);  // OK just work!
    $team->save();
    return Redirect::route('main');
    }

控制器板//出现问题

public function store()
{
 $taskboard = new Taskboard;
 $taskboard->name = Input::get('boardname');
 $taskboard->teams = Input::get('team');

 $taskboard = Auth::user()->teams()->save(taskboard);  // Not work! What should I do to store boards in team

 return Redirect::route('main');
 }

0 个答案:

没有答案