I have a project for multi vendor website with laravel 5.7 and vue.js. I used following code for search function.
My Web.php:
Route::post('product/search','Api\productController@search');
My Controller:
public function search(Request $request)
{
$searchTitle = $request->title;
$searchCategory = $request->category;
$searchUni = $request->uni;
$searchCity = $request->city;
if ($searchTitle || $searchCategory || $searchUni || $searchCity) {
$ads = advertise::when($searchCategory, function ($query) use ($searchCategory) {
return $query->where('category_id', 'like', "%{$searchCategory}%");
})
->when($searchUni, function ($query) use ($searchUni) {
return $query->where('university', 'like', "%{$searchUni}%");
})
->when($searchCity, function ($query) use ($searchCity) {
return $query->where('city', 'like', "%{$searchCity}%");
})
->when($searchTitle, function ($query) use ($searchTitle) {
return $query->where('title', 'like', "%{$searchTitle}%");
})
->where('status','=',1)->orderBy('created_at', 'desc')->paginate(18)
->appends(request()->query());
} else {
$ads = advertise::where('status','=',1)->orderBy('created_at', 'desc')->paginate(18);
}
$i = 0;
foreach($ads as $sd){
$images = image::where('adver_id', $sd->id)->get();
// return response()->json($images);
if(!$images->isEmpty()){
// return response()->json($images);
$ads[$i]->image1= $images[0]->image;
}
$i=$i+1;
}
return new productCollection($ads);
}
Axios in my vue-route.js:
axios.post("/api/product/search/",this.searchbox).then(response => {
if( response.data.data.length === 0 ) {
this.showTeezers = "nothing"
this.$store.state.teezers=[]
} else {
this.$store.state.teezers=response.data.data
}
}).catch(error => {
console.log(error)
})
When I run project in my localhost it's work well, but when I moved that into host (Linux server) it doesn't work. This error appears in the host:
"The GET method is not supported for this route. Supported methods: POST.",405 method not allowed