title: Async task in laravel
body: <p>Can execute an async task from a Controller in Laravel? I have tried doing so with Queues but I cannot.</p>
  
  <p>Route:</p>
  
  <pre><code>Route::post('/loadimages', LoadImagesController@load')-&gt;name('loadimages');
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public function load(Request $request)
  {
      $urls_array = preg_split("/[\s]+/", $request-&gt;urls);
  
      **// I want this task in the background...**
      DownloadImagesJob::dispatch($urls_array);
  
      **// ... and return immediately**
      return view('home');
  }
  </code></pre>
  
  <p>ShouldQueue:</p>
  
  <pre><code>class DownloadImagesJob implements ShouldQueue
  {
      use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  
      protected $urls;
  
      public function __construct(array $urls)
      {
          $this-&gt;urls = $urls;
      }
  
      public function handle()
      {
          // El código que quiero que se ejecute asíncronamente.
      }
  }
  </code></pre>
  
  <p>I am using "database" driver so in config/queues.php:</p>
  
  <pre><code>'default' =&gt; env('QUEUE_DRIVER', 'database'),
  </code></pre>
  
  <p>And:</p>
  
  <pre><code> php artisan queue:table
   php artisan migrate
  </code></pre>
  
  <p>But the task is not running asynchronously.</p>