I delete post:
$this->delete('/api/posts/1');
How check if that delete?
$this->assertNull(Post::find($post->id));
It doesn't work!
I delete post:
$this->delete('/api/posts/1');
How check if that delete?
$this->assertNull(Post::find($post->id));
It doesn't work!
try this :
$this->notSeeInDatabase('posts', ['id' => $post->id]);
description :
->notSeeInDatabase($table, array $data)
and
->missingFromDatabase($table, array $data)
One is just an alias for the other.
Most answers are way to complex or use a extra function to call. The Laraval delete function returns a boolean or a null
/**
* Delete the model from the database.
*
* @return bool|null
* @throws \Exception
*/
public function delete()
{
....
....
}
So you can simply can use this code to check a delete.
try {
if ($this->delete('/api/posts/1')) {
}
} catch (\Exception $exception) {}
You could check it with Post::findOrFail()
, or you could just check this if(Post::findById($id) == null)
.
Edit: not sure if this still works in Laravel >5.2 but you might be able to fetch the collection withTrashed()
if you soft-delete the record. Then you could use if($record->isTrashed()) { ... }
. This functionality isn't default in a Model, but is present in the SoftDelete
trait.
Found the information for the edit here: link.
YOu should try this:
$post = Post::find($post->id);
if(is_null($post))
Hope this work for you !!!