if exists laravel code example

Example 1: check if file exists laravel

$file = public_path('storage/images/' . $value)

if(! file_exists($file)){
  return asset('storage/images/default.png');
}

Example 2: laravel check record exists

$user = User::where('email', '=', Input::get('email'))->first();
if ($user === null) {
   // user doesn't exist
}

Example 3: laravel exists validation

'state_id' => 'exists:states,id'

Example 4: if notexists in laravel query

if (User::where('email', '=', Input::get('email'))->exists()) {
   // user found
}

Example 5: check for an existing user laravel eloquent

$users = User::where('email', '=', $request->input('email'))->first();
if ($users === null) {
  // User does not exist
} else {
  // User exits
}

Tags:

Php Example