YaSh Chaudhary
YaSh Chaudhary

Reputation: 2725

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}}

Upvotes: 0

Views: 1390

Answers (4)

Yosvel Quintero
Yosvel Quintero

Reputation: 19080

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();

Upvotes: 1

Salvador P.
Salvador P.

Reputation: 1489

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

Upvotes: 1

Mohamed Akram
Mohamed Akram

Reputation: 2117

this will get latest account and limit to certain no as you want, for example get latest 5 post.

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

Upvotes: 1

jeanj
jeanj

Reputation: 2176

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

This will only take the first element of your request.

Upvotes: 0

Related Questions