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
public function store(Request $request)
{
$validatedData = $request->validate([
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
}
Example 5: laravel validation
public function store(Request $request)
{
$validatedData = $request->validate([
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
}
Example 6: laravel rule unique where
'required|email|unique:company_users,email_address,NULL,id,company_id,' . $request->company_id