I am trying to create a feature on my web application that allows the user to see the posts between two dates. However, I am having problems trying to pass data from my database to my blade template. Instead of retrieving the created_at date of the post I receive the date "1/01/1970" and the job number does not appear.
First I added the routes in my web.php file:
Route::get('/search', function () {
return view('search');
});
Route::post('/select', 'PostController@getDate');
In my PostController.php file, I added my getDate Function:
public function getDate(Request $request){
$posts = DB::table('jobs')
->whereBetween('created_at', [$request->fdate, $request->sdate])
->get();
$posts->created_at = $request->created_at;
$posts->job_number = $request->job_number;
return view('result', ['posts' => $posts]);
}
My search.blade.php which is the form:
<form method="POST" action="/select">
<div class="form-group">
<label>First Date:</label>
<input type="date" class="form-control" name="fdate">
</div>
<div class="form-group">
<label>Second Date:</label>
<input type="date" class="form-control" name="sdate">
</div>
<input type="submit" value="Get Post Between" class="btn btn-primary">
</form>
My result.blade.php file which shows the post.
@if(count( $posts )>0)
<table class="table table-bordered table-striped">
<thead>
<th>Date created</th>
<th>Job Number</th>
</thead>
<tbody>
@foreach($posts as $post)
<tr>
<td></td>
<td></td>
</tr>
@endforeach
</tbody>
</table>
@else
<h3 class="text-center">No Post from Selected Range</h3>
@endif
I am honestly confused, I have used the correct variables.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire