Last active
January 23, 2020 13:46
-
-
Save shreesubhendu/77f9ae8f01e1563657cbd9bc83b847ee to your computer and use it in GitHub Desktop.
Check whether record exists in, DB Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you want to use the Model object if it exists: | |
$model = Model::where('column', '=', Input::get('column'))->first(); | |
if ($model === null) { | |
// Model doesn't exist | |
} | |
// If only to check if exist or not | |
if (Model::where('column', '=', Input::get('column'))->count() > 0) { | |
// Model found | |
} | |
// If only to check if exist or not | |
if (Model::where('column', '=', Input::get('column'))->exists()) { | |
// Model found | |
} | |
try { | |
$model = Model::where('mobile', Input::get('column'))->firstOrFail(); | |
// Model not found | |
} catch (ErrorException $e) { | |
// Model not found | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment