Delete by id - Laravel ORM

0

I want to do a delete by id with the ORM of Laravel , and from what I've read it's not possible, and it should be done a way similar to this one.

File::find($code)->delete();

or

$file = File::find($code);
$file->delete();

in both cases it throws me an error Call to a member function delete () on null

The fact is that I deleted the database record.

Could someone tell me what I'm doing wrong or if I left something?

    
asked by RuralGalaxy 29.07.2016 в 10:23
source

4 answers

0

The error was that you can only use the find () when you want to search for the primary_key in my case I had to use:

$file = File::where('FILE_code', '=', $fileCode);
$file->delete();
    
answered by 29.07.2016 / 11:33
source
0

You could try something like:

$file = File::whereCode($code)->first() ;

$file->delete();

Tell us how you are doing.

    
answered by 29.07.2016 в 15:01
0

Did you try this?

public function destroy($id){
    File::destroy($id);
}
    
answered by 29.07.2016 в 23:23
0

You can try this code

public function eliminar(Request $request,$id){
    $file = File::find($id)->delete();
    return 'Eliminado correctamente';
 }
    
answered by 27.08.2016 в 00:29