Laravel 6 Validation Unique with Soft Delete

Admin   Laravel   448  2021-03-17 03:30:04

Hi guys,

I will show you Laravel unique validation with softdelete.Unique validation in check without delete_at column.Soft deleted record with the same name exists but not check in unique validation.

You can create categories table.

Solution Unique Validation

Step 1 : Create Blade File

you can create blade file.



<!DOCTYPE html>






@if (count($errors) > 0)


@foreach($errors->all() as $error)

<li>{{ $error }} </li><br>




<form action="{{ route('') }}" method="post">



<input type="text" name="name">




<input type="text" name="city">



<label>Mobile No:</label>

<input type="text" name="mno">



<button type="submit">Save</button>






<table border="2" width="50%">





<th>Mobile No</th>



<?php $no = 1; ?>

@foreach($categories as $key => $value)

<tr style="text-align: center;">

<td>{{ $no }}</td>

<td>{{ $value->name }}</td>

<td>{{ $value->city }}</td>

<td>{{ $value->mno }}</td>

<td><a href="{{ route(" target="_blank" rel="nofollow" category.destroy',[$value->id]) }}"><button>Delete</button></a></td>

<?php $no++; ?>






Step 2 : Create Controller File

you can create controller file.




namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Category;

class CategoryController extends Controller


public function index()


$categories = Category::get();

return view('category.index',compact('categories'));



* Store a newly created resource in storage.


* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response


public function store(Request $request)







$input = $request->all();


return redirect(route('category.index'));


public function destroy($id)



return redirect(route('category.index'));


Step 3 : Add Route in web.php

In this step, we will add routes to handle request.



Route::get('category','[email protected]')->name('category.index');

Route::post('category','[email protected]')->name('');

Route::delete('category/{id}','[email protected]')->name('category.destroy');

It will help you...