/** * Remove the specified resource from storage. * * @param int $id * * @return \Illuminate\Http\Response */ public function destroy($id) { Photo::destroy($id); return back(); }
public function testDelete() { // test delete() $phone = Phone::find(1); $this->assertNotNull($phone); $phone = Phone::find(1); $phone->delete(); $phone = Phone::find(1); $this->assertNull($phone); // test delete() with query builder // Post is soft delete model $posts = Post::where('id', '<', 3)->get(); $this->assertFalse($posts->isEmpty()); Post::where('id', '<', 3)->delete(); $posts = Post::where('id', '<', 3)->get(); $this->assertTrue($posts->isEmpty()); // test destroy() $phone = Phone::find(2); $this->assertNotNull($phone); Phone::destroy(2); $phone = Phone::find(2); $this->assertNull($phone); $photos = Photo::all(); $this->assertFalse($photos->isEmpty()); Photo::destroy([1, 2, 3]); $photos = Photo::all(); $this->assertTrue($photos->isEmpty()); // test destopy with non-existing primary key // expect no exception Photo::destroy([1, 2, 3]); $photos = Photo::all(); $this->assertTrue($photos->isEmpty()); }