【问题标题】:how to change value change text in laravel如何在laravel中更改值更改文本
【发布时间】:2021-07-29 08:51:27
【问题描述】:

我想在更改 TVA 值时更改文本但最后结果相同 它们在两种情况下都显示为“NET TTC”

功能:

    public function invoice()
    {
        return $this->belongsTo(Invoice::class, 'invoice_id', 'id');
    }
    public function tvaText(){ 
        if( $this->TVA_value == 0 ){
            $this->tva_text='NET TTC';
        }elseif($this->TVA_value != 0){
            $this->tva_text='Total TTC';
        }
        return $this->tva_text;
    }

显示:

            @foreach($invoice->details as $item)
                            <tr>
                                <td>{{ $loop->iteration }}</td>
                                <td>{{ $item->product_name }}</td>
                                <td>{{ $item->quantity }}</td>
                                <td>{{ $item->unit_price }}</td>
                                <td>{{ $item->row_sub_total }}</td>
                            </tr>
                           

                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="3"></td>
                                <th colspan="2">TVA value </th>
                                <td>{{ $invoice->TVA_value }}</td>
                            </tr>
                            <tr>
                                <td colspan="3"></td>
                                <th colspan="2">sub total</th>
                                <td>{{ $invoice->sub_total }}</td>
                            </tr>
                            
                            <tr>
                                <td colspan="3"></td>
                                <th colspan="2">TVA total</th>
                                <td>{{ $invoice->TVA_total }}</td>
                            </tr>
                            <tr>
                                <td colspan="3"></td>
                                <th colspan="2">{{ $item->**tvaText()** }}</th>
                                <td>{{ $invoice->TTC_total }}</td>
                            </tr>
            @endforeach

请查看图片,以便您清楚我的意思 有谁知道如何更改文本或任何其他方法来实现?

【问题讨论】:

  • 你能添加代码来改变 $this->tva_text 的值吗?您显示 tvaText 的逻辑是正确的,但似乎值没有更新,您应该检查值

标签: laravel laravel-blade


【解决方案1】:

你可以在刀片上轻松做到这一点。

 @if($invoice->TVA_value == 0 )         
      <td>NET TTC</td>         
@else
      <td> Total TTC </td>        
@endif

【讨论】:

    猜你喜欢
    • 2020-07-27
    • 2019-04-11
    • 2012-05-28
    • 2018-09-03
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    相关资源
    最近更新 更多