how to check in a form if a number from an input exists in db laravel code example

Example 1: 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
}

Example 2: laravel validation

/**
 * Store a new blog post.
 *
 * @param  Request  $request
 * @return Response
 */
public function store(Request $request)
{
    $validatedData = $request->validate([
        'title' => 'required|unique:posts|max:255',
        'body' => 'required',
    ]);

    // The blog post is valid...
}

Tags:

Php Example