如何只显示laravel 5.2中的最新帖子,以及没有html<;p>;标签


How to display only latest post in laravel 5.2 and that too without html <p> tag?

我只想显示用户发布的最新帖子(或状态)。问题是所有的帖子都显示了一个<p>标签。我正在接受夏季笔记编辑器的输入。

我正在做的是:

 $accounts=Account::orderBy('updated_at','')->get();

我在视图文件中将其输出为:{{$account->estado}}

这将获得最新的帐户,并根据您的需要限制为特定的否,例如获取最新的5个帖子。

$accounts=Account::orderBy('updated_at','desc')->limit(5)->get();

您可以使用以下命令按日期获取最后一次输入:

$accounts=Account::orderBy('updated_at','desc')->first();

您可以使用->选择("字段1,字段2");在查询中,如果您需要在要检索的字段中具有选择性。

你可以在这里找到更多信息:https://laravel.com/docs/5.2/queries

要去掉这些标签,可以使用strip_tags或类似的方法。

或者存储已删除标记的字符串。

以下是有关刀片模板的一些信息:https://laravel.com/docs/5.2/blade

要删除html标签,可以使用:strip_tags()

echo strip_tags("Hello <b>world!</b>");

结果:

你好,世界!

并且只获取$x最后一个帐户:

$x = 5;
$accounts = Account::orderBy('updated_at','desc')
    ->limit($x)
    ->get();
$accounts=Account::orderBy('updated_at','')->first();

这将只接受您请求的第一个元素。