put this code in html file above the form
@if (count($errors) > 0)
<div class = "alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
put this code in controller
public function studentinsert(Request $request)
{
$this->validate($request,[
'name'=>'required|max:30|unique:student',
'price'=>'required',
]);
$student = new Studentview();
$student->name = $request->name;
$student->price= $request->price;
$student->save();
return redirect()->route('admin.show')->with('status','data insert successful');
}
example of html page
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<h1 style="text-align:center; ">Add New Student</h1>
<div class="container-fluid" style="margin-left: 150px; margin-right: 50px;">
@if (count($errors) > 0)
<div class = "alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form method="post" action="{{route('admin.save')}}">
{{@csrf_field()}}
<div class="form-group" class="col-xs-4">
<label for="exampleInputEmail1">Enter the name </label>
<input type="text" name="name" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" style="" value="{{old('student_name')}}">
<small id="emailHelp" class="form-text text-muted">We'll never share your Name with anyone else.</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">enter the price</label>
<input type="number" class="form-control" id="exampleInputPassword1" name="price" value="{{old('price')}}">
</div>
<!-- <div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Check me out</label>
</div> -->
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</body>
</html>
0 Comments