how to delete record with using modeling data

Deepak Tailor Image
Deepak Tailor - Jan 27 2021
how to delete record with using modeling data

The ID that is passed in the delete function matches the primary key of the table and updates the current date time in the deleted_at column. If you pass true in the second parameter, it deletes that row.

Update only deleted_at column
public function delete_data()
{
	$id = 11;
	$result = $this->userModel->delete($id);
	if($result == true){
		echo "delete data";
	}
	else{
		echo "delate fail";
	}
}
Delete row with pass second parameter true
public function delete_data()
{
	$id = 11;
	$result = $this->userModel->delete($id,true);
	if($result == true){
		echo "delete data";
	}
	else{
		echo "delate fail";
	}
}
Update deleted_at column with multiple ids

In the delete function, you can also pass multiple ids in the array format.

public function delete_data()
{
	$ary = array(7,8,9);
	$result = $this->userModel->delete($ary);
	if($result == true){
		echo "delete data";
	}
	else{
		echo "delate fail";
	}
}
Delete multiple ids with pass second parameter true
public function delete_data()
{
	$ary = array(7,8,9);
	$result = $this->userModel->delete($ary,true);
	if($result == true){
		echo "delete data";
	}
	else{
		echo "delate fail";
	}
}
Delete data with where

If we do not pass any parameters in the delete function, then we need to call the where.

public function delete_data()
{
	$result = $this->userModel
					->where('id',11)
					->delete();
	if($result == true){
		echo "delete data";
	}
	else{
		echo "delate fail";
	}
}
Delete all records where not null deleted_at column

With the purgeDeleted function, we can delete all the records. deleted_at column whose values are not null.

public function delete_data()
{
	$result = $this->userModel->purgeDeleted();
	if($result == true){
		echo "delete data";
	}
	else{
		echo "delate fail";
	}
}
Deepak Tailor Image
Deepak Tailor

My name is Deepak tailor as a fullstack developer. I have been in the IT industry for the last 5 years. For professional and customize web development, you can send inquiry on our email.
----
You can contact him at support@fulstackdev.com