Laravel 主页加载速度太慢(30 秒)

Laravel HomePage is loading too slow (30s)

我在做社交网站。但是我有一个关于加载主页太慢(30-40 秒)的问题。我可以修理东西吗?请帮帮我。 这是家庭控制器

public function index(Request $request){
        $category_post = Category::orderBy('category_id', 'DESC')->get();
        $post2 = Post::orderBy('tbl_post.created_at','DESC')->paginate(5);
        
        return view('student.page.home')->with(compact('category_post','post2'));
}

我的 foreach

1 部分
@foreach($post2 as $key => $post_info)
<p style="font-size: 20px;" class="widget-box-status-text">{{$post_info->post_title}}</p>
<br>
<p style="white-space: pre-line;" class="read-more widget-box-status-text">{{$post_info->post_content}}</p>
<div class="tag-list">
 <a class="tag-item secondary" style="font-size: 16px" href="{{url('/quest-category/'.$post_info->category_id)}}">{{$post_info->category->category_name}}</a>
</div>
@endforeach

Post型号

class Post extends Model
{
    public $timestamps = FALSE;
    protected $fillable = [
        'post_student_name', 'post_student_email', 'post_title', 'category_id', 'post_content', 'created_at'
    ];
    protected $primaryKey = 'post_id';
    protected $table = 'tbl_post';

    public function student(){
        return $this->belongsTo('App\Models\Student','student_id');
    }
    public function category(){
        return $this->belongsTo('App\Models\Category','category_id');
    }
}

在这里您可以使用预加载优化您的 eloquent 查询:

$post2 = Post::with('category')->orderBy('tbl_post.created_at','DESC')->paginate(5);

还取决于很多其他的东西,比如网络连接,缓存,CSS,还有JS文件,加载的资源等等