简体   繁体   中英

get data by id in different table laravel

i have 3 table

evaluation

id | pks_id | ksb_id | problem | status

1      1        0       test      test
2      0        1      test      test
2      2        0      test      test
2      0        2     test      test

PKS

id|description|part_1 | part_2 | part_3
1    test1      pks1     pks2   pks3
2    test2      pks2     pks2   pks3

KSB

id|description|part_1 | part_2 | part_3
1    test1      ksb1     ksb2    ksb3
2    test2      ksb1     ksb2    ksb3

blade view:

@foreach($evaluation as $dt)
<tr>
<td class="text-center"> 
@if($dt->pks_id == '0')
KSB {{ Helper::getDetail('ksb', $dt->ksb_id,'description','id')  }}
@elseif($dt->ksb_id == '0')
PKS {{ Helper::getDetail('pks', $dt->pks_id,'description','id')  }}</td>

<td class="text-center">Part 1</td> // show data pks_id "0" and ksb_id "1" or otherwise

<td class="text-center">Part 2,3</td> show data pks_id "0" and ksb_id "1" or otherwise 
</tr>
@endforeach

part 1, part 2 and part 3 related to pks and ksb table.

how to show data if pks_id "0" or ksb_id "1" or pks_id "1" or ksb_id "0"

(pks_id and ksb_id will have not only "1" value)

i want show data like this

name     |      part        | 

pks test1|  pks1 | pks2,pks3

ksb test1  | ksb1 | ksb2,ksb3

pks test2|  pks1 | pks2,pks3

ksb test2  | ksb1 | ksb2,ksb3

thank you!!

Just use &&

@elseif($dt->pks_id == '0' && $dt->ksb_id == '1')

However, you have to use it before @if($dt->pks_id == '0') , or else it is going to return true in this statement before.

Is that what you want to achieve?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM