Helo那里,请帮帮我
我有一个看起来像这样的模型
Schema::create('teams', function (Blueprint $table) {
$table->increments('id');
$table->integer('player_id')->unsigned();
});
Schema::table('teams', function (Blueprint $table) {
$table->foreign('player_id')->references('id')->on('players')->onDelete('cascade');
});
和
Schema::create('team_members', function (Blueprint $table) {
$table->increments('id');
$table->integer('team_id');
$table->integer('creator_id');
});`
Schema::table('team_members', function (Blueprint $table) { //another migration
$table->integer('team_id')->unsigned()->change();
$table->integer('creator_id')->unsigned()->change();
$table->foreign('team_id')->references('id')->on('teams')->onDelete('cascade');
$table->foreign('creator_id')->references('id')->on('players')->onDelete('cascade');
});
我想删除团队模型,所以我这样做了:
$team = Team::findOrFail($id);
if(Session::get('player_id') == $team->creator_id)
{
$team_member = TeamMember::where('team_id', $id)->get();
foreach($team_member as $tm)
{
$player = Player::find($tm->player_id);
Notification::send($player, new \App\Notifications\DatabaseNotification(12, Session::get('username'), $id) );
}
@unlink($team->avatar);
$team->delete();
Session::flash('delete_team_success', 'Delete team success!');
return redirect('/teams/me');
}
删除成功,团队和team_member已从表中删除。但在我这样查询之后TeamMember::where('player_id', Session::get('player_id'))->get();
它仍然会返回一个值。Click here to see the result
但当我确实喜欢这个TeamMember::get()
时,结果为空Click here to see the result
为什么会这样?当我做TeamMember :: where(' player_id',Session :: get(' player_id')) - > get();
时,我需要得到null结果