title: Laravel ErrorException in Factory.php line 153: array_merge(): Argument #2 is not an array
body: <p>I'm trying to loop through my database items but I'm getting this error.</p>
  
  <pre><code>ErrorException in Factory.php line 153:
  array_merge(): Argument #2 is not an array (View: C:\Users\Saad\Desktop\laravel\laravel\resources\views\pages\doclist.blade.php)
  in Factory.php line 153
  at CompilerEngine-&gt;handleViewException(object(ErrorException), '1') in PhpEngine.php line 44
  at PhpEngine-&gt;evaluatePath('C:\Users\Saad\Desktop\laravel\laravel\storage\framework\views/696ff312d502382f4d2ab3d7a9657ab1', array('__env' =&gt; object(Factory), 'app' =&gt; object(Application), 'errors' =&gt; object(ViewErrorBag), 'out' =&gt; array(object(stdClass)))) in CompilerEngine.php line 58
  at CompilerEngine-&gt;get('C:\Users\Saad\Desktop\laravel\laravel\resources\views/pages/doclist.blade.php', array('__env' =&gt; object(Factory), 'app' =&gt; object(Application), 'errors' =&gt; object(ViewErrorBag), 'out' =&gt; array(object(stdClass)))) in View.php line 135
  at View-&gt;getContents() in View.php line 106
  at View-&gt;renderContents() in View.php line 80
  at View-&gt;render() in Response.php line 51
  at Response-&gt;setContent(object(View)) in Response.php line 198
  at Response-&gt;__construct(object(View)) in Router.php line 1229
  at Router-&gt;prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 113
  at ControllerDispatcher-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
  at Pipeline-&gt;then(object(Closure)) in ControllerDispatcher.php line 114
  at ControllerDispatcher-&gt;callWithinStack(object(consultController), object(Route), object(Request), 'find') in ControllerDispatcher.php line 69
  at ControllerDispatcher-&gt;dispatch(object(Route), object(Request), 'App\Http\Controllers\consultController', 'find') in Route.php line 203
  at Route-&gt;runWithCustomDispatcher(object(Request)) in Route.php line 134
  at Route-&gt;run(object(Request)) in Router.php line 708
  at Router-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
  at Pipeline-&gt;then(object(Closure)) in Router.php line 710
  at Router-&gt;runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
  at Router-&gt;dispatchToRoute(object(Request)) in Router.php line 635
  at Router-&gt;dispatch(object(Request)) in Kernel.php line 236
  at Kernel-&gt;Illuminate\Foundation\Http\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
  at VerifyCsrfToken-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
  at ShareErrorsFromSession-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
  at StartSession-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
  at AddQueuedCookiesToResponse-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
  at EncryptCookies-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
  at CheckForMaintenanceMode-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
  at Pipeline-&gt;then(object(Closure)) in Kernel.php line 122
  at Kernel-&gt;sendRequestThroughRouter(object(Request)) in Kernel.php line 87
  at Kernel-&gt;handle(object(Request)) in index.php line 54
  at require_once('C:\Users\Saad\Desktop\laravel\laravel\public\index.php') in server.php line 21
  1/2
  ErrorException in Factory.php line 153:
  array_merge(): Argument #2 is not an array
  in Factory.php line 153
  at HandleExceptions-&gt;handleError('2', 'array_merge(): Argument #2 is not an array', 'C:\Users\Saad\Desktop\laravel\laravel\vendor\laravel\framework\src\Illuminate\View\Factory.php', '153', array('view' =&gt; 'includes.doc', 'data' =&gt; object(stdClass), 'mergeData' =&gt; array('obLevel' =&gt; '1', '__env' =&gt; object(Factory), 'app' =&gt; object(Application), 'errors' =&gt; object(ViewErrorBag), 'out' =&gt; array(object(stdClass)), 'doc' =&gt; object(stdClass)), 'path' =&gt; 'C:\Users\Saad\Desktop\laravel\laravel\resources\views/includes/doc.blade.php', 'this' =&gt; object(Factory)))
  at array_merge(array('obLevel' =&gt; '1', '__env' =&gt; object(Factory), 'app' =&gt; object(Application), 'errors' =&gt; object(ViewErrorBag), 'out' =&gt; array(object(stdClass)), 'doc' =&gt; object(stdClass)), object(stdClass)) in Factory.php line 153
  at Factory-&gt;make('includes.doc', object(stdClass), array('obLevel' =&gt; '1', '__env' =&gt; object(Factory), 'app' =&gt; object(Application), 'errors' =&gt; object(ViewErrorBag), 'out' =&gt; array(object(stdClass)), 'doc' =&gt; object(stdClass))) in 696ff312d502382f4d2ab3d7a9657ab1 line 16
  at include('C:\Users\Saad\Desktop\laravel\laravel\storage\framework\views\696ff312d502382f4d2ab3d7a9657ab1') in PhpEngine.php line 42
  at PhpEngine-&gt;evaluatePath('C:\Users\Saad\Desktop\laravel\laravel\storage\framework\views/696ff312d502382f4d2ab3d7a9657ab1', array('__env' =&gt; object(Factory), 'app' =&gt; object(Application), 'errors' =&gt; object(ViewErrorBag), 'out' =&gt; array(object(stdClass)))) in CompilerEngine.php line 58
  at CompilerEngine-&gt;get('C:\Users\Saad\Desktop\laravel\laravel\resources\views/pages/doclist.blade.php', array('__env' =&gt; object(Factory), 'app' =&gt; object(Application), 'errors' =&gt; object(ViewErrorBag), 'out' =&gt; array(object(stdClass)))) in View.php line 135
  at View-&gt;getContents() in View.php line 106
  at View-&gt;renderContents() in View.php line 80
  at View-&gt;render() in Response.php line 51
  at Response-&gt;setContent(object(View)) in Response.php line 198
  at Response-&gt;__construct(object(View)) in Router.php line 1229
  at Router-&gt;prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 113
  at ControllerDispatcher-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
  at Pipeline-&gt;then(object(Closure)) in ControllerDispatcher.php line 114
  at ControllerDispatcher-&gt;callWithinStack(object(consultController), object(Route), object(Request), 'find') in ControllerDispatcher.php line 69
  at ControllerDispatcher-&gt;dispatch(object(Route), object(Request), 'App\Http\Controllers\consultController', 'find') in Route.php line 203
  at Route-&gt;runWithCustomDispatcher(object(Request)) in Route.php line 134
  at Route-&gt;run(object(Request)) in Router.php line 708
  at Router-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
  at Pipeline-&gt;then(object(Closure)) in Router.php line 710
  at Router-&gt;runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
  at Router-&gt;dispatchToRoute(object(Request)) in Router.php line 635
  at Router-&gt;dispatch(object(Request)) in Kernel.php line 236
  at Kernel-&gt;Illuminate\Foundation\Http\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
  at VerifyCsrfToken-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
  at ShareErrorsFromSession-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
  at StartSession-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
  at AddQueuedCookiesToResponse-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
  at EncryptCookies-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
  at CheckForMaintenanceMode-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
  at Pipeline-&gt;then(object(Closure)) in Kernel.php line 122
  at Kernel-&gt;sendRequestThroughRouter(object(Request)) in Kernel.php line 87
  at Kernel-&gt;handle(object(Request)) in index.php line 54
  at require_once('C:\Users\Saad\Desktop\laravel\laravel\public\index.php') in server.php line 21
  </code></pre>
  
  <p>Controller consultController</p>
  
  <pre><code>class consultController extends Controller
  {
      public function index(){
  
  
          return view('pages.consult');
      }
  
      public function find(){
          $input=Request::all();
          $location=$input['location'];
          $spec=$input['specialization'];
  
          $out = DB::table('doctors')-&gt;where('location','=', $location)
                                         -&gt;where('specialization_group','=', $spec)
                                         -&gt;get();
          return view('pages.doclist')-&gt;with('out',$out);
          //return count($out);
      }
  }
  </code></pre>
  
  <p>pages.doclist file</p>
  
  <pre><code>@section('content')
  
  &lt;div class='container-fluid'&gt;
      &lt;div class='row'&gt;
          @if (count($out))
              @foreach($out as $doc)
                  @include('includes.doc', $doc)
              @endforeach
          @else
              &lt;p&gt;No Doctor exist with your criteria.&lt;/p&gt;
          @endif 
      &lt;/div&gt;
  &lt;/div&gt;
  
  @endsection
  </code></pre>
  
  <p>includes.doc file</p>
  
  <pre><code>&lt;div class='col-xs-12'&gt;
      &lt;p&gt; {{ $doc['name'] }}
  &lt;/div&gt;
  </code></pre>