简体   繁体   中英

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

I want to display only latest post(or status) posted by the user. The problem is all the posts are displayed with a <p> tag. I am taking input in summernote editor.

What I am doing is:

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

I am outputting it in my view file as : {{$account->estado}}

To remove the html tags you can use: strip_tags()

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

Results:

Hello world!

And to get only the $x last account(s):

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

You can get the last input by date using this:

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

And you can use ->select('field1, field2'); in the query too, if you need to be selective in the fields to retrieve.

You can find more info here: https://laravel.com/docs/5.2/queries

To get rid of the tags you can use strip_tags or similar.

Or store the strings with the tags removed.

Here is some information about blade templates: https://laravel.com/docs/5.2/blade

这将获得最新的帐户,并根据需要将其限制为某些否,例如获得最新的5个帖子。

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

这只会占用您请求的第一个元素。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM