Factory.php第153行中的Laravel ErrorException:array_merge():参数#2不是数组

时间:2015-12-11 16:52:58

标签: php laravel laravel-5.1

我试图遍历我的数据库项目,但我收到此错误。

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->handleViewException(object(ErrorException), '1') in PhpEngine.php line 44
at PhpEngine->evaluatePath('C:\Users\Saad\Desktop\laravel\laravel\storage\framework\views/696ff312d502382f4d2ab3d7a9657ab1', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'out' => array(object(stdClass)))) in CompilerEngine.php line 58
at CompilerEngine->get('C:\Users\Saad\Desktop\laravel\laravel\resources\views/pages/doclist.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'out' => array(object(stdClass)))) in View.php line 135
at View->getContents() in View.php line 106
at View->renderContents() in View.php line 80
at View->render() in Response.php line 51
at Response->setContent(object(View)) in Response.php line 198
at Response->__construct(object(View)) in Router.php line 1229
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 113
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(consultController), object(Route), object(Request), 'find') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\consultController', 'find') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 708
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 710
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
at Router->dispatchToRoute(object(Request)) in Router.php line 635
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->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->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->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->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->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->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->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->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->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->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->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->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->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->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' => 'includes.doc', 'data' => object(stdClass), 'mergeData' => array('obLevel' => '1', '__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'out' => array(object(stdClass)), 'doc' => object(stdClass)), 'path' => 'C:\Users\Saad\Desktop\laravel\laravel\resources\views/includes/doc.blade.php', 'this' => object(Factory)))
at array_merge(array('obLevel' => '1', '__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'out' => array(object(stdClass)), 'doc' => object(stdClass)), object(stdClass)) in Factory.php line 153
at Factory->make('includes.doc', object(stdClass), array('obLevel' => '1', '__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'out' => array(object(stdClass)), 'doc' => 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->evaluatePath('C:\Users\Saad\Desktop\laravel\laravel\storage\framework\views/696ff312d502382f4d2ab3d7a9657ab1', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'out' => array(object(stdClass)))) in CompilerEngine.php line 58
at CompilerEngine->get('C:\Users\Saad\Desktop\laravel\laravel\resources\views/pages/doclist.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'out' => array(object(stdClass)))) in View.php line 135
at View->getContents() in View.php line 106
at View->renderContents() in View.php line 80
at View->render() in Response.php line 51
at Response->setContent(object(View)) in Response.php line 198
at Response->__construct(object(View)) in Router.php line 1229
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 113
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(consultController), object(Route), object(Request), 'find') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\consultController', 'find') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 708
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 710
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
at Router->dispatchToRoute(object(Request)) in Router.php line 635
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->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->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->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->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->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->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->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->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->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->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->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->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->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

Controller consultController

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')->where('location','=', $location)
                                       ->where('specialization_group','=', $spec)
                                       ->get();
        return view('pages.doclist')->with('out',$out);
        //return count($out);
    }
}

pages.doclist file

@section('content')

<div class='container-fluid'>
    <div class='row'>
        @if (count($out))
            @foreach($out as $doc)
                @include('includes.doc', $doc)
            @endforeach
        @else
            <p>No Doctor exist with your criteria.</p>
        @endif 
    </div>
</div>

@endsection

includes.doc文件

<div class='col-xs-12'>
    <p> {{ $doc['name'] }}
</div>

1 个答案:

答案 0 :(得分:1)

在控制器中:

public function find(){
    $input = Request::all();
    $location = $input->location;
    $spec = $input->specialization;

    $out = DB::table('doctors')->where('location', $location)
        ->where('specialization_group', $spec)
        ->get();
    return view('pages.doclist',compact('out'));
    //return count($out);
}

在刀片文件中:

@section('content')

<div class='container-fluid'>
    <div class='row'>
        @if (count($out) > 0)
            @foreach($out as $doc)
                <div class='col-xs-12'>
                     {{ $doc->name }}
                </div>
            @endforeach
        @else
            <p>No Doctor exist with your criteria.</p>
        @endif 
    </div>
</div>

@endsection //or you can use @stop. @stop is the latest one.