我有以下设置:

In routes I have:

Route::get('articles', 'ArticlesController@index');

控制器中的索引方法很简单:

public function index()
{
   $articles = Article::all();
   return View('articles.index', compact('articles'));
}

在他们看来:

@extends('../app')
@section('content')
<h1>Articles</h1>
<p>
    @foreach($articles as $article)
    <article>
        <h2><a href="{{action('ArticlesController@show', [$article->id])}}">{{$article->title}}</a></h2>
        <p>{{ $article->body }}</p>
    </article>
    @endforeach
</p>
@stop

我试图替换:

$articles = Article::all();

with

$article = Article::latest()->get();

这样我就可以先展示最新的文章. 我收到错误:

FatalErrorException in Str.php line 322:
Maximum execution time of 30 seconds exceeded

and the call stack is:

in Str.php line 322
at FatalErrorException->__construct() in HandleExceptions.php line 131
at HandleExceptions->fatalExceptionFromError() in HandleExceptions.php line 116
at HandleExceptions->handleShutdown() in HandleExceptions.php line 0
at Str::snake() in helpers.php line 561
at snake_case() in ControllerInspector.php line 105
at ControllerInspector->getVerb() in ControllerInspector.php line 78
at ControllerInspector->getMethodData() in ControllerInspector.php line 39
at ControllerInspector->getRoutable() in Router.php line 251
at Router->controller() in Router.php line 226
at Router->controllers() in Facade.php line 210
at Facade::__callStatic() in routes.php line 21
at Route::controllers() in routes.php line 21
in RouteServiceProvider.php line 40

... 等

我已将控制器方法恢复到原来的状态,但错误仍然存在.

你能告诉我怎样才能解决这个问题吗?

推荐答案

Maximum execution time of 30 seconds exceeded错误与Laravel无关,而与您的PHP配置有关.

Here is how you can fix it. The setting you will need to change is max_execution_time.

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
memory_limit = 8M      ; Maximum amount of memory a script may consume (8MB)

You can change the max_execution_time to 300 seconds like max_execution_time = 300

您可以在Loaded Configuration File部分的phpinfo函数输出中找到PHP配置文件的路径.

Laravel相关问答推荐

导出所有客户端不起作用,文件保存时没有名称和扩展名

如何在 Laravel 的外部 js 文件中包含 csrf_token()?

Laravel 5.3:语法错误或访问冲突:1463 HAVING 子句中使用了非分组字段距离

在 laravel 中动态更改时区

磁盘 [视频] 没有配置的驱动程序

合并两个 Eloquent 集合并删除所有重复项.

使用 Laravel Socialite 登录 Facebook

计算laravel中查询返回的行数

Laravel 5.1 重命名项目

如何使用外部图像生成 html div 的 screenshot截图?

如何在 laravel 中解码 Json 对象并在 laravel 中应用 foreach 循环

如何调试 Laravel 框架?

如何在laravel 5.1中使用url(路由)传递多个参数

是否可以将路由参数传递给 Laravel 中的控制器构造函数?

无法打开laravel.log:无法打开流

Laravel League/flysystem 使用 AWS S3 获取文件 URL

如何在 Laravel 中使用补丁请求?

在 Laravel 中包含 bootstrap 程序

如何使用队列设置高、低和中优先级Electron邮件?

没有Access-Control-Allow-Origin标头 - Laravel