我有以下设置:
在路线中,我有:
Route::get(‘articles’, ‘ArticlesController@index’);
控制器中的 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();
和
$article = Article::latest()->get();
这样我实际上可以首先显示最新的文章。我得到了错误:
FatalErrorException in Str.php line 322:
Maximum execution time of 30 seconds exceeded
调用堆栈是:
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
… ETC
我已将控制器方法恢复到原来的样子,但错误仍然存在。
你能告诉我如何解决这个问题吗?
原文由 Geordie Gadgie 发布,翻译遵循 CC BY-SA 4.0 许可协议
超过 30 秒的最大执行时间 错误与 Laravel 无关,而与您的 PHP 配置有关。
这是您可以解决的方法。您需要更改的设置是
max_execution_time
。您可以将
max_execution_time
更改为300
秒,如max_execution_time = 300
您可以在
Loaded Configuration File
部分的phpinfo
函数的输出中找到 PHP 配置文件的路径。