0
I have the code below on the route, but it doesn’t work! What am I doing wrong? It is returning users correctly but doesn’t delete.
$Usuario = User::find(2);
$Usuario->delete();
return User::orderBy('username', 'asc')->take(4)->get();
0
I have the code below on the route, but it doesn’t work! What am I doing wrong? It is returning users correctly but doesn’t delete.
$Usuario = User::find(2);
$Usuario->delete();
return User::orderBy('username', 'asc')->take(4)->get();
1
Use Builder instead of ORM as a test
DB::table('users')->where('id', 2)->delete();
I think this will work
0
Add primary key setting to your model:
protected $primaryKey = 'ID';
It worked for me...
Browser other questions tagged laravel laravel-eloquent
You are not signed in. Login or sign up in order to post.
try to use a Try ali in delete to see why. An alternative is you use User::Destroy($id)
– Daniel Lemes
User::Destroy($id) didn’t work, what’s wrong? No error returns.
– Hugo
dd( DB::getQueryLog(); after $Usuario->delete(); ai you will see SQL, paste here
– Daniel Lemes
array (size=2)
 0 => 
 array (size=3)
 'query' => string 'select * from
userswhere
id= ? limit 1' (length=44)
 'bindings' => 
 array (size=1)
 0 => int 2
 'time' => float 0.68
 1 => 
 array (size=3)
 'query' => string 'delete from
userswhere
idis null' (length=38)
 'bindings' => 
 array (size=0)
 empty
 'time' => float 0.33
– Hugo
you’re using softdelete ?
– Daniel Lemes
I am not using softdelete, but I already did the test using it and the same error occurred!
– Hugo
put the code of your model.
– Daniel Lemes
At the moment it’s like this:
<?php

class User extends Eloquent {

 public $timestamps = false;

 /**
 * The database table used by the model.
 *
 * @var string
 */
 //protected $table = 'users';

 /**
 * The attributes excluded from the model's JSON form.
 *
 * @var array
 */
 protected $hidden = array('password', 'remember_token');

}

– Hugo
Createreadupdate working less delete than not.
– Hugo