title: Laravel - How to pass variable to WhereIn
body: <p>New to Laravel. I am trying to use a controller to services that match what is sent in the URL.</p>
  
  <p>Sample URL:</p>
  
  <pre><code>/public/service/cost/2
  </code></pre>
  
  <p>The Code in the Controller is:</p>
  
  <pre><code>public function getServiceCost($id) {
  
      $service = Service::whereIn('id', array($id))-&gt;get();
  
      return $service;
  }
  </code></pre>
  
  <p>I want to be able to pass multiple ids in the URL like so:
  /public/service/cost/1,2,3</p>
  
  <p>If I hard-code to test, it works fine.</p>
  
  <pre><code>public function getServiceCost($id) {
    $service = Service::whereIn('id', array(1, 2, 3))-&gt;get();
    return $service;
  }  
  </code></pre>
  
  <p>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?</p>
  
  <p>If I use</p>
  
  <pre><code>/public/service/cost/2,3
  </code></pre>
  
  <p>It only returns the data for id 2.</p>
  
  <p>I changed the function to use Request $request, but it still only shows one result:</p>
  
  <pre><code>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-&gt;get('id')))-&gt;get();
  
          return $service;
      }
  }
  </code></pre>
  
  <p>URL used was:</p>
  
  <pre><code>public/service/cost?id=1,2
  </code></pre>