Laravel Date Validation between two dates | Laravel date range validation
create.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Help</title>
</head>
<body>
@if(session()->has('success'))
<div style="color:green;"> {{session()->get('success')}} </div>
@endif
@if(session()->has('error'))
<div style="color:red;"> {{session()->get('error')}} </div>
@endif
<h2>Apply for Help</h2>
<form action="help" method="POST">
{{csrf_field()}}
<input type="text" name="name" placeholder="name">
<input type="text" name="mobile" placeholder="mobile">
<input type="date" name="date" >
<input type="submit" value="Submit">
</form>
<br>
<table border="1">
<tr>
<th>Name</th>
<th>Mobile</th>
<th>Date</th>
</tr>
@foreach($helps as $help)
<tr>
<td> {{$help->name}} </td>
<td> {{$help->mobile}} </td>
<td> {{$help->date}} </td>
</tr>
@endforeach
</table>
</body>
</html>
HelpController.php
<?php
namespace App\Http\Controllers\Backend;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Helps;
class HelpController extends Controller
{
public function create()
{
$helps=Helps::all();
return view('backend.help.create',compact('helps'));
}
public function store(Request $request)
{
$request->validate([
'name'=>'required',
]);
$check=Helps::where('mobile',$request->mobile)->first();
$date1=strtotime($check->date);
$date2=strtotime($request->date);
$sec=$date2-$date1;
$day=$sec/86400;
if($day>5){
$data=$request->all();
Helps::create($data);
return back()->with('success',"Done $day");
}else{
return back()->with('error',"$day");
}
}
}
No comments