0
Hello, in this code below I delete the database of the selected records in a list of chekboxes.
I have an array of Ids that is mounted as follows:
Array (
[0] => 810
[1] => 811
)
On top of this array I do a foreach search each record and call the exclusion method, complete code below:
public function destroy_download($id = 0){
$ids = ($id >= 1) ? array($id) : Input::get('ids');
if( ! empty($ids) ){
foreach ($ids as $id) {
$download = Download::find($id);
$download->delete();
}
}
}
This should work properly, however gives the following error:
Symfony \ Component \ Debug \ Exception \ FatalErrorException Call to a member function delete() on a non-object
on the line:
$download->delete();
It’s like the record hasn’t been found.
It removes the record in the database only if this error happens, someone can imagine what it is?
The Array is correct, I’ve debugged but always gives it.
I tried to use the Try catch, but it does not release a Modelnotfoundexception exception. It gives error in $download->delete(), and does not enter the catch. This is bizarre. Here’s a printa for you to see: http://imageshack.com/img600/2163/dfzi.png
– Jarbas
The strange thing is that if instead of calling the method $download->delete(), I do echo $download->name works, there is no error, it displays the names.
– Jarbas
@Jarbas try to post a var_dump of the object
$download
and post your modelDownload
– gmsantos
posted in Pastebin. Dump is the object without calling ->delete(), because there is no error. Object $download: http://pastebin.com/dwGcStJg Model: http://pastebin.com/vSDGsxt7
– Jarbas
Strange... I’ll try to reproduce the error here
– gmsantos