In this article, i will let you know how to make unique validation with soft delete in laravel 5.6 application.
Actually, when i was new with soft delete and i require to add unique validation with my email column at that time i fetched this type of issue. At that time i just plane to write manually database query for check unique validation and i done my task. But after some day i was free on Saturday and i search on google about this, after some research i found best solution for unique validation with soft delete.
I added both example below code, One is for create time and another is on edit time on controller validation.
On Create Method:
public function store(Request $request)
{
$request->validate([
'name'=>'required|unique:form_types,name,NULL,id,deleted_at,NULL',
]);
// Write your code here
}
On Update Method:
public function update(Request $request, $id)
{
$request->validate([
'name'=>'required|unique:form_types,name,'.$id.',id,deleted_at,NULL',
]);
// Write Code here
}
You can see both way.
I hope you found your best....
Do you like below Tutorials ?
- Laravel 5.6 - Collection could not be converted to int
- Laravel - How to generate secure https URL from route?
- Laravel - Vue JS File Upload Example
- How to get last 7 days data in Laravel?
- Laravel Validation required if other field empty example
- Laravel Eloquent - When Case Statement in Select Query Example
- Laravel 7.x and 6.x Passing Variable to Javascript Example
- How to pass PHP variables in JavaScript or jQuery?