I'm fairly new to Laravel, but I'm trying to make a small API for my course. I've got this route Route::get('films/search', 'App\Http\Controllers\FilmController@search'); which calls my custom function search which get as a parameter a Request. Here it is:
public function search(Request $request) { $keyword = $request->input('keyword'); $rating = $request->input('rating'); $minLength = $request->input('minLength'); $maxLength = $request->input('maxLength'); if ($this->isParamExisting($keyword)) { return $this->getFromKeyword($keyword); } elseif ($this->isParamExisting($rating)) { return $this->getRatings($rating); } elseif ($this->isParamExisting($minLength)) { return $this->getMinLength($minLength); } elseif ($this->isParamExisting($maxLength)) { return $this->getMaxLength($maxLength); } else { return $this->getAllFilms(); } } At first it was working, but thenm I added joins in my models for other foreign keys and now it gives me Trying to get property 'id' of non-object and says it comes from my resource which is also used by my index method which works. I don't see any reason why it wouldn't work.
It may come from my route since when I put @index instead of my custom method it still gives me the error message. And I know my index works, because I'm using it on another route and there is no problem.
Solution:
The problem was coming from one of my other routes. I add one which used films/{id} and the system thought that search was used as an {id}. I changed my route for Route::get('films/search/param', 'App\Http\Controllers\FilmController@search');
没有评论:
发表评论