Search larger field in a table with Eloquent

Asked

Viewed 305 times

1

I’m using Laravel for an API

In my comic book I have a table called tbmanifestacao and in this table I have a column called nrmanifestacao

I would like in my controller return the biggest nrmanifestacao

I tried so:

$nr = DB::select('select MAX(nrmanifestacao) from tbmanifestacao', [1]);

But it did not work, beyond that I know it is not the correct to use SQL, but rather the Eloquent

How could I do this search?

  • 1

    A way to do: DB::table('tbmanifestacao')->max('nrmanifestacao');

  • 1

    You should probably own a model of tbmanifestacao, then you could do it using eloquent: seuModel::max('nrmanifestacao');

  • @Marceloboni that second worked

  • @Marceloboni the first now tbm, but I had to put use Illuminate\Support\Facades\DB;

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.