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.
eloquent laravel-5.7
add a comment |
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.
eloquent laravel-5.7
add a comment |
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.
eloquent laravel-5.7
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
eloquent laravel-5.7
asked yesterday
Md. Azharul Islam
97
97
add a comment |
add a comment |
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.
@Daniel Chen i have do that but displaying first record ofDeposittable not last record. but i need last record .
– Md. Azharul Islam
20 mins ago
add a comment |
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.
@Amir Helmyi want to display last record ofDeposittable table not onlytotal_amountbut also the column depend on my need.
– Md. Azharul Islam
28 mins ago
add a comment |
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.
@Daniel Chen i have do that but displaying first record ofDeposittable not last record. but i need last record .
– Md. Azharul Islam
20 mins ago
add a comment |
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.
@Daniel Chen i have do that but displaying first record ofDeposittable not last record. but i need last record .
– Md. Azharul Islam
20 mins ago
add a comment |
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.
Try $member->deposit->first()->total_amount.
$member->deposit returns a collection of all deposits of the member, even if there is only one.
answered yesterday
Daniel Chen
446
446
@Daniel Chen i have do that but displaying first record ofDeposittable not last record. but i need last record .
– Md. Azharul Islam
20 mins ago
add a comment |
@Daniel Chen i have do that but displaying first record ofDeposittable not last record. but i need last record .
– Md. Azharul Islam
20 mins ago
@Daniel Chen i have do that but displaying first record of
Deposit table not last record. but i need last record .– Md. Azharul Islam
20 mins ago
@Daniel Chen i have do that but displaying first record of
Deposit table not last record. but i need last record .– Md. Azharul Islam
20 mins ago
add a comment |
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.
@Amir Helmyi want to display last record ofDeposittable table not onlytotal_amountbut also the column depend on my need.
– Md. Azharul Islam
28 mins ago
add a comment |
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.
@Amir Helmyi want to display last record ofDeposittable table not onlytotal_amountbut also the column depend on my need.
– Md. Azharul Islam
28 mins ago
add a comment |
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.
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.
answered 16 hours ago
Amir Helmy
713
713
@Amir Helmyi want to display last record ofDeposittable table not onlytotal_amountbut also the column depend on my need.
– Md. Azharul Islam
28 mins ago
add a comment |
@Amir Helmyi want to display last record ofDeposittable table not onlytotal_amountbut also the column depend on my need.
– Md. Azharul Islam
28 mins ago
@Amir Helmy i want to display last record of Deposit table table not only total_amount but also the column depend on my need.– Md. Azharul Islam
28 mins ago
@Amir Helmy i want to display last record of Deposit table table not only total_amount but also the column depend on my need.– Md. Azharul Islam
28 mins ago
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
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
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
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
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