从laravel中的关系中删除全局范围 - php

7项目
而且我有这个Voucher_detale模型的全局范围

<?php
namespace App\Scopes;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
class getVouchers implements Scope
{
    public function apply(Builder $builder, Model $model)
    {
        $builder->where('vouchers_detale_state', '=', 1);
    }
}

我有Voucher模型,里面有hasMany这是代码

public function getDetales()
{
    return $this->hasMany('App\Vouchers_detale','vouchers_detale_voucher_id','id')->withTrashed();
}

刀片内我有此代码

@foreach($voucher['getDetales'] as $v)
<tr class='table-warning'>
    <td>
        <a href='/{{$path}}/Vouchers_detales/{{$v["id"]}}'>{{$v['vouchers_detale_user_id']}}</a>

        <div class='selected d-print-none'>
            @foreach($v->getUpdate as $update)
                <span style='color:black'>{{$update['update_history_old_amount']}}</span>
                {{$update['created_at']}}
                {{$update['getUserData']['user_name']}}
                <hr />
            @endforeach
        </div>
    </td>
    <td>{{$v['getUserData']['user_name']}}</td>
    @if($v['vouchers_detale_amount'] > 0)
        <td>{{$v['vouchers_detale_amount']}}</td>
        <td></td>
        @php $total_debt +=  $v['vouchers_detale_amount'] @endphp
    @else
        <td></td>
        <td>{{$v['vouchers_detale_amount'] * -1}}</td>
        @php $total_credit += $v['vouchers_detale_amount'] * -1 @endphp
    @endif
    <td>{{$v['vouchers_detale_desc']}}</td>
</tr>
@endforeach

现在我怎么能在我尝试过的foreach中忽略全局范围

@foreach($voucher['getDetales']->withoutGlobalScopes() as $v)

我加这个错误

Method Illuminate\Database\Eloquent\Collection::withoutGlobalScopes does not exist.

我如何忽略全局范围来自foreach中的关系
谢谢

参考方案

没关系,我刚刚建立了新关系

public function getDetalesWithout()
{
    return $this->hasMany('App\Vouchers_detale','vouchers_detale_voucher_id','id')->withTrashed()->withoutGlobalScope('App\Scopes\getVouchers');
}

谢谢

验证IBAN PHP - php

在设计新平台时,我们尝试集成IBAN编号。我们必须确保IBAN已经过验证,并且存储在数据库中的IBAN始终正确。那么验证数字的正确方法是什么? 参考方案 正如我在其他问题中解释的逻辑一样,我尝试自己创建一个函数。根据Wikipedia文章中解释的逻辑,在下面找到合适的功能。国家特定验证。它适合吗http://en.wikipedia.org/wiki/Int…

PHP PDO组按列名称查询结果 - php

以下PDO查询返回以下结果:$db = new PDO('....'); $sth = $db->prepare('SELECT ...'); 结果如下: name curso ABC stack CDE stack FGH stack IJK stack LMN overflow OPQ overflow RS…

PHP:对数组排序 - php

请如何排序以下数组Array ( 'ben' => 1.0, 'ken' => 2.0, 'sam' => 1.5 ) 至Array ( 'ken' => 2.0, 'sam' => 1.5, 'ben' =&…

我无法发出警报。我想念什么? - php

我无法发出警报。我想念什么?(下面的代码在WP插件内部)<?php wp_enqueue_script('jquery'); ?> <script type="text/javascript"> jQuery('#myTest').click(function(){alert…

php Singleton类实例将在多个会话中保留吗? - php

举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…