I think your missing a param in the where
Program::where('name', '=' ,Input::get('name'))->delete();
TerrePorter said:
I think your missing a param in the where
Program::where('name', '=' ,Input::get('name'))->delete();
No, the default is "=" . It deletes the row in programs table so it works, it just doesn't fire the deleting event and the description isn't deleted
ckissi said: No, the default is "=" . It deletes the row in programs table so it works, it just doesn't fire the deleting event and the >description isn't deleted
Ok, I've never used it without so it looked off to me.
Not to insult, but have you check the value that is getting returned? Input::get('name')
Maybe the query log can show you the query, dd(DB::getQueryLog());
Or I think you can dump the query with ->toSql(); after the delete()
Humm,
Maybe,
static::deleting(function()
{
$this->description()->delete();
return parent::delete();
});
I think you can also put a where in there, if you didn't have the relationship setup.
static::deleting(function()
{
$this->description()->where('id',$this->id)->delete();
return parent::delete();
});
Ok, the previous code just didn't look right.
So after some testing, this finally worked.
In the Program model, I changed it to just this
static::deleting(function($program)
{
$program->description()->delete();
});
To delete,
Program::where('id', 1)->first()->delete();
I had to call with the ->first() or it just didn't work. I found a reference to the ->first() required at https://github.com/laravel/framework/issues/2536
The dd(DB::getQueryLog()); shows all of the queries,
array (size=4)
0 =>
array (size=3)
'query' => string 'select * from `programs` where `id` = ? limit 1' (length=47)
'bindings' =>
array (size=1)
0 => int 11
'time' => float 0.82
1 =>
array (size=3)
'query' => string 'select * from `descriptions` where `descriptions`.`program_id` in (?)' (length=69)
'bindings' =>
array (size=1)
0 => int 11
'time' => float 0.94
2 =>
array (size=3)
'query' => string 'delete from `descriptions` where `descriptions`.`program_id` = ?' (length=64)
'bindings' =>
array (size=1)
0 => int 11
'time' => float 1.44
3 =>
array (size=3)
'query' => string 'delete from `programs` where `id` = ?' (length=37)
'bindings' =>
array (size=1)
0 => int 11
'time' => float 1.28
TerrePorter said:
Humm,
Maybe,
static::deleting(function() { $this->description()->delete(); return parent::delete(); });
I think you can also put a where in there, if you didn't have the relationship setup.
static::deleting(function() { $this->description()->where('id',$this->id)->delete(); return parent::delete(); });
You will not have access to $this
from a static method.
mcraz said: You will not have access to
$this
from a static method.
Yeah, it started looking off to me after a bit
@TerrePorter, thanx ! , it was the "first()" thank you for the reference to https://github.com/laravel/framework/issues/2536 They should mention this in the documentation. I wasted 6 hours because of this :(
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community