This is the problem that I am meeting with - problem on search function with parameter is $from_date
and $to_date
in Laravel.
I have a function getByDate()
in ProjectRepository with the following code:
public function getByDate() {
$from_date = Carbon::parse(request('startDate'))->startOfDay();
$to_date = Carbon::parse(request('endDate'))->endOfDay();
$project = DB::table('projects')
->whereBetween('startDate', [$from_date, $to_date])
->get();
return $project;
}
From the ProjectController, I inject the repository into searchProject()
in Controller, in this one I have:
public function searchProject(){
$project = $this->repository->getByDate();
if (is_null($project)) {
return $this->sendError('Projects not found. Try again :)');
}
return response()->json([
'status' => true,
'data' => $project,
]);
}
In the api.php
where I declare Route for mapping API URL, I have this line:
Route::get('search_project', 'Project\ProjectController@searchProject');
And when I test on POSTMAN with the URL localhost:8000/api/search_project?from_date=2018-01-12&to_date=2018-03-03
, it return the result
"message": "",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
"file": "D:\\project-porfolio\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\RouteCollection.php",
"line": 179,
Can anyone give me some advise what I do have something wrong and suggest for another way?