New to Laravel. I am trying to use a controller to services that match what is sent in the URL.
Sample URL:
/public/service/cost/2
The Code in the Controller is:
public function getServiceCost($id) {
$service = Service::whereIn('id', array($id))->get();
return $service;
}
I want to be able to pass multiple ids in the URL like so: /public/service/cost/1,2,3
If I hard-code to test, it works fine.
public function getServiceCost($id) {
$service = Service::whereIn('id', array(1, 2, 3))->get();
return $service;
}
What do I need to do to pass the arguments from the URL into the whereIn so that it returns what I pass in the URL?
If I use
/public/service/cost/2,3
It only returns the data for id 2.
I changed the function to use Request $request, but it still only shows one result:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Service;
class ServiceController extends Controller
{
public function getServiceCost2(Request $request) {
$service = Service::whereIn('id', array($request->get('id')))->get();
return $service;
}
}
URL used was:
public/service/cost?id=1,2