当我想运行 php artisan serve 时可能会出现啥问题

Posted

技术标签:

【中文标题】当我想运行 php artisan serve 时可能会出现啥问题【英文标题】:What might be wrong when i want to run php artisan serve当我想运行 php artisan serve 时可能会出现什么问题 【发布时间】:2020-05-28 22:11:15 【问题描述】:

我在尝试运行 php artisan serve 时遇到了这个错误。我下载了这个项目并尝试运行它却遇到了这个错误。

你们有什么可以帮助我的解决方案吗?提前致谢。我正在使用 xampp 作为我的项目的主机服务器。

ErrorException in Builder.php line 1185: count(): Parameter must be an array or an object that implements Countable
    in Builder.php line 1185
    at HandleExceptions->handleError('2', 'count(): Parameter must be an array or an object that implements Countable', 'C:\xampp\htdocs\bootup-master\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php', '1185', array('scope' => object(Closure), 'parameters' => array(object(Builder)), 'query' => object(Builder)))
    at count(null) in Builder.php line 1185
    at Builder->callScope(object(Closure)) in Builder.php line 1216
    at Builder->applyScopes() in Builder.php line 314
    at Builder->get() in HomeController.php line 30
    at HomeController->index()
    at call_user_func_array(array(object(HomeController), 'index'), array()) in Controller.php line 80
    at Controller->callAction('index', array()) in ControllerDispatcher.php line 146
    at ControllerDispatcher->call(object(HomeController), object(Route), 'index') in ControllerDispatcher.php line 94
    at ControllerDispatcher->Illuminate\Routing\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
    at Pipeline->Illuminate\Routing\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
    at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
    at ControllerDispatcher->callWithinStack(object(HomeController), object(Route), object(Request), 'index') in ControllerDispatcher.php line 54
    at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\HomeController', 'index') in Route.php line 174
    at Route->runController(object(Request)) in Route.php line 140
    at Route->run(object(Request)) in Router.php line 724
    at Router->Illuminate\Routing\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
    at Pipeline->Illuminate\Routing\closure(object(Request)) in TagstripMiddleware.php line 19
    at TagstripMiddleware->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(TagstripMiddleware), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
    at Pipeline->Illuminate\Pipeline\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\closure(object(Request)) in VerifyCsrfToken.php line 64
    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 136
    at Pipeline->Illuminate\Pipeline\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\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 136
    at Pipeline->Illuminate\Pipeline\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\closure(object(Request)) in StartSession.php line 64
    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 136
    at Pipeline->Illuminate\Pipeline\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\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 136
    at Pipeline->Illuminate\Pipeline\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\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 136
    at Pipeline->Illuminate\Pipeline\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
    at Pipeline->then(object(Closure)) in Router.php line 726
    at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
    at Router->dispatchToRoute(object(Request)) in Router.php line 675
    at Router->dispatch(object(Request)) in Kernel.php line 246
    at Kernel->Illuminate\Foundation\Http\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
    at Pipeline->Illuminate\Routing\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 136
    at Pipeline->Illuminate\Pipeline\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\closure(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
    at Pipeline->then(object(Closure)) in Kernel.php line 132
    at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
    at Kernel->handle(object(Request)) in index.php line 53
    at require_once('C:\xampp\htdocs\bootup-master\public\index.php') in server.php line 21

【问题讨论】:

你目前使用的是哪个 laravel 版本? 您使用的是哪个版本的 PHP? 这个错误是由于PHP版本造成的。你用的是哪个版本? php版本为7.3.11 和你的 laravel 版本? 【参考方案1】:

此错误是由PHP 版本引起的。很可能是PHP 7.2 版本。见下文:

Document changes of PHP 7.2

解决这个问题:

将您的PHP 版本升级

修改1185的行 vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php文件

$originalWhereCount = count ($ query-> wheres);

$originalWhereCount = 0;
if (is_array ($ query-> wheres) || is_object ($ query-> wheres)) 
    $originalWhereCount = count ($ query-> wheres);

【讨论】:

以上是关于当我想运行 php artisan serve 时可能会出现啥问题的主要内容,如果未能解决你的问题,请参考以下文章

PhpStorm:运行 php artisan serve 未定义索引:REQUEST_URI [重复]

当我在终端中键入 php artisan serve 时,我收到“需要 Mcrypt PHP 扩展”

php artisan serve - 如何让mysql运行

我的 laravel 项目在 xampp 上运行良好,但是当我尝试使用 php artisan serve 运行它时,它会超时

Laravel 项目在 Ubuntu 16.04 上未运行 php artisan serve 时无法运行

php artisan serve [ErrorException] laravel