gpt4 book ai didi

php - 使用 Laravel 和 Eloquent 从表中全选

转载 作者:IT老高 更新时间:2023-10-28 23:46:15 25 4
gpt4 key购买 nike

我正在使用Laravel 4来设置我的第一个型号,以从名为 posts 的表中拉出所有行。

在标准mysql中,我将使用:

SELECT * FROM posts;

如何在Laravel 4模型中实现这一目标?

有关我完整的模型源代码:

,请参见下文
<?php

class Blog extends Eloquent
{

/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'posts';

public function getAllPosts()
{

}

}

最佳答案

你只需调用

Blog::all();

//example usage.
$posts = Blog::all();

$posts->each(function($post) // foreach($posts as $post) { }
{
//do something
}

从您应用程序的任何位置。

阅读documentation会有很大帮助。

关于php - 使用 Laravel 和 Eloquent 从表中全选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21891815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com