unique in laravel code example

Example 1: get unique values in laravel

$users = User::select('name')->distinct()->get();

Example 2: laravel validate integer between

'item' => 'required|integer|between:1,10',

Example 3: laravel set field unique

Schema::table('manufacturers', function($table)
{
    $table->string('name')->unique(); 
});

Example 4: laravel unique 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...
}

Example 5: 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...
}

Example 6: laravel rule unique where

'required|email|unique:company_users,email_address,NULL,id,company_id,' . $request->company_id