public function isModelRecordExist($model, $recordId)
{
if (!$recordId) return false;
$count = $model->where(['id' => $recordId])->count();
return $count ? true : false;
}
// To Test
$recordId = 5;
$status = $this->isModelRecordExist( (new MyTestModel()), $recordId);
// Outcome: true | false
Hope it helps!
Thursday, 24 January 2019
Laravel Method to check if the given record id exists on DB table or not.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Please post any queries and comments here.