Helo there, please help me
I have a model that look like this
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');
});
and
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');
});
I want to delete the team model, so I did this:
$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');
}
the delete is success, the team and the team_member has gone from the table. But after I did query like thisTeamMember::where('player_id', Session::get('player_id'))->get();
It's still returning a value.Click here to see the result
but when i did like this TeamMember::get()
the result is empty Click here to see the result
Why this is happening? I need to get the null result when I did TeamMember::where('player_id', Session::get('player_id'))->get();