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?










share|improve this question


























    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?










    share|improve this question
























      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?










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 14:45









      John

      75110




      75110
























          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;





          share|improve this answer





















          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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

























          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;





          share|improve this answer





















          • 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















          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;





          share|improve this answer





















          • 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













          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;





          share|improve this answer












          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;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation