How to get and display last row value form many table in one to Many relationship











up vote
0
down vote

favorite












My two table Member and Deposit there has one to many relationship one member has multiple deposit in Deposit table i want to display last record of deposit table when i call all Member or a single Member.



This is my Member Table



1.id,
2.name,
3.phone,
4.account_no,
5.ac_open_date,
6.ac_close_date,
7.status,
8........


My Deposit Table



1.meber_id,
2.deposit_date,
3.deposit_amount,
4.total_amount,
5..........


My Controller Code



$member = Member::with(['Deposit'=>function($query){$query->select('*')->latest('deposit_date')->limit(1);}])->where('status','ready')->get();


if i return $member variable then show my aspect data ok. but when i show this in my blade file this way ...



blade section



<td>{{ $member->name }}</td>
<td>{{ $member->account_no }}</td>
<td>{{ $member->phone }}</td>
<td>{{ $member->deposit->total_amount}}</td>


when i call the Deposit model to display to deposit table last row records then show the error.




"Property [total_amount] does not exist on this collection instance. (View: C:xampphtdocs........




what can i do .please help me anyone.










share|improve this question


























    up vote
    0
    down vote

    favorite












    My two table Member and Deposit there has one to many relationship one member has multiple deposit in Deposit table i want to display last record of deposit table when i call all Member or a single Member.



    This is my Member Table



    1.id,
    2.name,
    3.phone,
    4.account_no,
    5.ac_open_date,
    6.ac_close_date,
    7.status,
    8........


    My Deposit Table



    1.meber_id,
    2.deposit_date,
    3.deposit_amount,
    4.total_amount,
    5..........


    My Controller Code



    $member = Member::with(['Deposit'=>function($query){$query->select('*')->latest('deposit_date')->limit(1);}])->where('status','ready')->get();


    if i return $member variable then show my aspect data ok. but when i show this in my blade file this way ...



    blade section



    <td>{{ $member->name }}</td>
    <td>{{ $member->account_no }}</td>
    <td>{{ $member->phone }}</td>
    <td>{{ $member->deposit->total_amount}}</td>


    when i call the Deposit model to display to deposit table last row records then show the error.




    "Property [total_amount] does not exist on this collection instance. (View: C:xampphtdocs........




    what can i do .please help me anyone.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      My two table Member and Deposit there has one to many relationship one member has multiple deposit in Deposit table i want to display last record of deposit table when i call all Member or a single Member.



      This is my Member Table



      1.id,
      2.name,
      3.phone,
      4.account_no,
      5.ac_open_date,
      6.ac_close_date,
      7.status,
      8........


      My Deposit Table



      1.meber_id,
      2.deposit_date,
      3.deposit_amount,
      4.total_amount,
      5..........


      My Controller Code



      $member = Member::with(['Deposit'=>function($query){$query->select('*')->latest('deposit_date')->limit(1);}])->where('status','ready')->get();


      if i return $member variable then show my aspect data ok. but when i show this in my blade file this way ...



      blade section



      <td>{{ $member->name }}</td>
      <td>{{ $member->account_no }}</td>
      <td>{{ $member->phone }}</td>
      <td>{{ $member->deposit->total_amount}}</td>


      when i call the Deposit model to display to deposit table last row records then show the error.




      "Property [total_amount] does not exist on this collection instance. (View: C:xampphtdocs........




      what can i do .please help me anyone.










      share|improve this question













      My two table Member and Deposit there has one to many relationship one member has multiple deposit in Deposit table i want to display last record of deposit table when i call all Member or a single Member.



      This is my Member Table



      1.id,
      2.name,
      3.phone,
      4.account_no,
      5.ac_open_date,
      6.ac_close_date,
      7.status,
      8........


      My Deposit Table



      1.meber_id,
      2.deposit_date,
      3.deposit_amount,
      4.total_amount,
      5..........


      My Controller Code



      $member = Member::with(['Deposit'=>function($query){$query->select('*')->latest('deposit_date')->limit(1);}])->where('status','ready')->get();


      if i return $member variable then show my aspect data ok. but when i show this in my blade file this way ...



      blade section



      <td>{{ $member->name }}</td>
      <td>{{ $member->account_no }}</td>
      <td>{{ $member->phone }}</td>
      <td>{{ $member->deposit->total_amount}}</td>


      when i call the Deposit model to display to deposit table last row records then show the error.




      "Property [total_amount] does not exist on this collection instance. (View: C:xampphtdocs........




      what can i do .please help me anyone.







      eloquent laravel-5.7






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      Md. Azharul Islam

      97




      97
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          Try {{ $member->deposit->first()->total_amount}}.



          $member->deposit returns a collection of all deposits of the member, even if there is only one.






          share|improve this answer




























            up vote
            0
            down vote













            I understand that you update the total_amount for every transaction for a member with the total Deposits till now, if so, I suggest to add new attribute for the Member table and save this value on it, so you can get it easily, and you can update it when needed.






            share|improve this answer





















              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%2f53237850%2fhow-to-get-and-display-last-row-value-form-many-table-in-one-to-many-relationshi%23new-answer', 'question_page');
              }
              );

              Post as a guest
































              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              Try {{ $member->deposit->first()->total_amount}}.



              $member->deposit returns a collection of all deposits of the member, even if there is only one.






              share|improve this answer

























                up vote
                0
                down vote













                Try {{ $member->deposit->first()->total_amount}}.



                $member->deposit returns a collection of all deposits of the member, even if there is only one.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Try {{ $member->deposit->first()->total_amount}}.



                  $member->deposit returns a collection of all deposits of the member, even if there is only one.






                  share|improve this answer












                  Try {{ $member->deposit->first()->total_amount}}.



                  $member->deposit returns a collection of all deposits of the member, even if there is only one.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  Daniel Chen

                  446




                  446
























                      up vote
                      0
                      down vote













                      I understand that you update the total_amount for every transaction for a member with the total Deposits till now, if so, I suggest to add new attribute for the Member table and save this value on it, so you can get it easily, and you can update it when needed.






                      share|improve this answer

























                        up vote
                        0
                        down vote













                        I understand that you update the total_amount for every transaction for a member with the total Deposits till now, if so, I suggest to add new attribute for the Member table and save this value on it, so you can get it easily, and you can update it when needed.






                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          I understand that you update the total_amount for every transaction for a member with the total Deposits till now, if so, I suggest to add new attribute for the Member table and save this value on it, so you can get it easily, and you can update it when needed.






                          share|improve this answer












                          I understand that you update the total_amount for every transaction for a member with the total Deposits till now, if so, I suggest to add new attribute for the Member table and save this value on it, so you can get it easily, and you can update it when needed.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 10 hours ago









                          Amir Helmy

                          713




                          713






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237850%2fhow-to-get-and-display-last-row-value-form-many-table-in-one-to-many-relationshi%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest




















































































                              Popular posts from this blog

                              Full-time equivalent

                              Bicuculline

                              さくらももこ