So when I applied laravel inbuilt validations it was working fine. But when I'm applying jquery validations is not working and give me an error " SQLSTATE[HY000]: General error: 1364 Field 'profile_img' doesn't have a default value"
**home.blade.php**
This is my main home page which has form for creating students details.
```
<div class="jumbotron">
<form name="form" id="frm" action="{{ url('/addStud') }}" method="POST" class="col-md-4 d-flex flex-column justify-content-center">
@csrf
<div class="form-group ">
<label for="name">NAME</label>
<input type="text" class="form-control" name="name">
<span class="text-danger">@error('name'){{$message}}@enderror</span>
</div>
<div class="form-group">
<label for="rollno">ROLL NO</label>
<input type="text" class="form-control" name="rollno">
<span class="text-danger">@error('rollno'){{$message}}@enderror</span>
</div>
<div class="form-group">
<label for="address">Email </label>
<input type="email" class="form-control" name="email">
<span class="text-danger">@error('email'){{$message}}@enderror</span>
</div>
<div class="form-group">
<label for="phone">PHONE NO</label>
<input type="tel" class="form-control" name="phoneno">
<span class="text-danger">@error('phoneno'){{$message}}@enderror</span>
</div>
<div class="form-group">
<label for="dob">DOB</label>
<input type="date" class="form-control" name="dob">
<span class="text-danger">@error('dob'){{$message}}@enderror</span>
</div>
<div class="form-group">
<label for="dob">COURSE</label>
<input type="text" class="form-control" name="course">
<span class="text-danger">@error('course'){{$message}}@enderror</span>
</div>
<div class="form-group mb-2">
<input type="file" class="form-control" name="profile_img">
<span class="text-danger">@error('profile_img'){{$message}}@enderror</span>
</div>
<div>
<button type="submit" class="btn btn-primary text-uppercase">create</button>
<a href="/list" class="btn btn-secondary text-uppercase">view list</a>
</div>
</form>
</div>
<!-- jquery validation before form submit -->
<script>
// $.validator.addMethod('filesize', function(value, element, param) {
// return this.optional(element) || (element.files[0].size <= param)
// });
$("form[name = 'form']").validate({
rules: {
name: {
required: true,
},
rollno: {
required: true,
},
email: {
required: true,
email: true,
},
phoneno: {
required: true,
digits: 10,
},
dob: {
required: true,
date: true
},
course: {
required: true,
},
profile_img: {
required: true,
extension: "png|jpg|PNG|JPEG",
filesize: 1048576,
},
},
messages: {
name: {
required: 'name is required',
},
rollno: {
required: 'roll no is required',
},
email: {
required: 'email is required',
},
phoneno: {
required: 'phone no is required',
},
dob: {
required: 'dob is required',
},
course: {
required: 'course is required',
},
profile_img: {
required: 'image is required',
},
}
})
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.3/jquery.validate.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.3/additional-methods.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<!-- <script src="../js/validations.js"></script> -->
@endsection
This is my controller in which I have commented the inbuilt laravel validations which is working fine.
**StudentController.php**
```
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Student;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
class StudentController extends Controller
{
// public function index()
// {
// return view('');
// }
public function create(Request $req)
{
$student = new Student;
$student->name = $req->name;
$student->rollno = $req->rollno;
$student->email = $req->email;
$student->phoneno = $req->phoneno;
$student->dob = $req->dob;
$student->course = $req->course;
// $student->profile_img = $req->profile_img;
if ($req->hasFile('profile_img')) {
$file = $req->file('profile_img');
$extension = $file->getClientOriginalExtension();
$filename = time() . '.' . $extension;
$file->move('uploads/students/', $filename);
$student->profile_img = $filename;
}
// $req->validate([
// 'name' => 'required|regex:/^[\p{L}\s-]+$/|max:255',
// 'rollno' => 'required',
// 'email' => 'required|email',
// 'phoneno' => 'required|digits:10',
// 'dob' => 'required',
// 'course' => 'required|string',
// // 'profile_img' => 'required|mimetypes:image/jpeg,image/png,image/bmp,image/svg',
// ]);
$student->save();
return redire`enter code here`ct('list');
}
```