How to grab only latest update record from data table in Laravel 5.6?
up vote
1
down vote
favorite
I have following table name as projects like this structure,
id name adtype created_at updated_at
1 gobba 1 2018-02-25 2018-02-25
2 manna 0 2018-04-25 2018-04-25
3 alaya 1 2017-12-28 2017-12-28
I need grab only one result witch related to latest updated record and adtype == 1, I code following controller, for this,
public function showad()
{
$projects = Vehicle::with('uploads')
->where('adtype','=',1)
->latest('updated_at');
return view('vehicles.slider')->withProjects($projects);
but this working but not filtering latest updated records. how can correct this?
php mysql laravel-5
add a comment |
up vote
1
down vote
favorite
I have following table name as projects like this structure,
id name adtype created_at updated_at
1 gobba 1 2018-02-25 2018-02-25
2 manna 0 2018-04-25 2018-04-25
3 alaya 1 2017-12-28 2017-12-28
I need grab only one result witch related to latest updated record and adtype == 1, I code following controller, for this,
public function showad()
{
$projects = Vehicle::with('uploads')
->where('adtype','=',1)
->latest('updated_at');
return view('vehicles.slider')->withProjects($projects);
but this working but not filtering latest updated records. how can correct this?
php mysql laravel-5
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have following table name as projects like this structure,
id name adtype created_at updated_at
1 gobba 1 2018-02-25 2018-02-25
2 manna 0 2018-04-25 2018-04-25
3 alaya 1 2017-12-28 2017-12-28
I need grab only one result witch related to latest updated record and adtype == 1, I code following controller, for this,
public function showad()
{
$projects = Vehicle::with('uploads')
->where('adtype','=',1)
->latest('updated_at');
return view('vehicles.slider')->withProjects($projects);
but this working but not filtering latest updated records. how can correct this?
php mysql laravel-5
I have following table name as projects like this structure,
id name adtype created_at updated_at
1 gobba 1 2018-02-25 2018-02-25
2 manna 0 2018-04-25 2018-04-25
3 alaya 1 2017-12-28 2017-12-28
I need grab only one result witch related to latest updated record and adtype == 1, I code following controller, for this,
public function showad()
{
$projects = Vehicle::with('uploads')
->where('adtype','=',1)
->latest('updated_at');
return view('vehicles.slider')->withProjects($projects);
but this working but not filtering latest updated records. how can correct this?
php mysql laravel-5
php mysql laravel-5
asked Nov 10 at 14:45
John
75110
75110
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Try using ORDER BY
and LIMIT
:
$projects = Vehicle::with('uploads')
->where('adtype', '=', 1)
->orderBy('updated_at', 'desc')
->take(1)
->get();
This should correspond to the following raw MySQL query:
SELECT *
FROM uploads
WHERE adtype = 1
ORDER BY updated_at DESC
LIMIT 1;
I need get latest updated one
– John
Nov 10 at 15:39
...which is what my answer should be doing.
– Tim Biegeleisen
Nov 10 at 15:40
it is working fine
– John
Nov 10 at 15:48
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Try using ORDER BY
and LIMIT
:
$projects = Vehicle::with('uploads')
->where('adtype', '=', 1)
->orderBy('updated_at', 'desc')
->take(1)
->get();
This should correspond to the following raw MySQL query:
SELECT *
FROM uploads
WHERE adtype = 1
ORDER BY updated_at DESC
LIMIT 1;
I need get latest updated one
– John
Nov 10 at 15:39
...which is what my answer should be doing.
– Tim Biegeleisen
Nov 10 at 15:40
it is working fine
– John
Nov 10 at 15:48
add a comment |
up vote
0
down vote
accepted
Try using ORDER BY
and LIMIT
:
$projects = Vehicle::with('uploads')
->where('adtype', '=', 1)
->orderBy('updated_at', 'desc')
->take(1)
->get();
This should correspond to the following raw MySQL query:
SELECT *
FROM uploads
WHERE adtype = 1
ORDER BY updated_at DESC
LIMIT 1;
I need get latest updated one
– John
Nov 10 at 15:39
...which is what my answer should be doing.
– Tim Biegeleisen
Nov 10 at 15:40
it is working fine
– John
Nov 10 at 15:48
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Try using ORDER BY
and LIMIT
:
$projects = Vehicle::with('uploads')
->where('adtype', '=', 1)
->orderBy('updated_at', 'desc')
->take(1)
->get();
This should correspond to the following raw MySQL query:
SELECT *
FROM uploads
WHERE adtype = 1
ORDER BY updated_at DESC
LIMIT 1;
Try using ORDER BY
and LIMIT
:
$projects = Vehicle::with('uploads')
->where('adtype', '=', 1)
->orderBy('updated_at', 'desc')
->take(1)
->get();
This should correspond to the following raw MySQL query:
SELECT *
FROM uploads
WHERE adtype = 1
ORDER BY updated_at DESC
LIMIT 1;
answered Nov 10 at 15:00
Tim Biegeleisen
208k1379127
208k1379127
I need get latest updated one
– John
Nov 10 at 15:39
...which is what my answer should be doing.
– Tim Biegeleisen
Nov 10 at 15:40
it is working fine
– John
Nov 10 at 15:48
add a comment |
I need get latest updated one
– John
Nov 10 at 15:39
...which is what my answer should be doing.
– Tim Biegeleisen
Nov 10 at 15:40
it is working fine
– John
Nov 10 at 15:48
I need get latest updated one
– John
Nov 10 at 15:39
I need get latest updated one
– John
Nov 10 at 15:39
...which is what my answer should be doing.
– Tim Biegeleisen
Nov 10 at 15:40
...which is what my answer should be doing.
– Tim Biegeleisen
Nov 10 at 15:40
it is working fine
– John
Nov 10 at 15:48
it is working fine
– John
Nov 10 at 15:48
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240067%2fhow-to-grab-only-latest-update-record-from-data-table-in-laravel-5-6%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown