使用! is_admin()将限制此过滤器仅在前端使用,以避免后端出现许多问题:// Only show products in the front-end search resultsadd_filter('pre_get_posts','lw_search_filter_pages');function lw_search_filter_pages($query) { // Frontend search only if ( ! is_admin() && $query->is_search() ) { $query->set('post_type', 'product'); $query->set( 'wc_query', 'product_query' ); } return $query;}这是观点的一部分。<div class="row"> @if($events->count()) @if($eventListView == "grid") <div class="col-sm-12 grid-search"> <div class="col-sm-offset-6 col-sm-6"> <div class="pull-right lh-2"> Search: <input class="form-control pull-right input-sm grid-filter"> </div> </div> </div> @foreach($events as $key => $event) <div class="col-md-6 col-sm-6 col-xs-12 data-event-block" data-event-block="{{ $key+1 }}" style="display: {{ $key <= 9 ? 'block' : 'none' }}"> @include('ManageEmsPro.Partials.EventPanel') </div> @endforeach @elseif($eventListView == "table") <div class="col-md-12"> @include('ManageEmsPro.Partials.EventTable') </div> @endif @else @if($search['q']) @include('Shared.Partials.NoSearchResults') @else @include('ManageEmsPro.Partials.EventsBlankSlate') @endif @endif </div>
1 回答
回首忆惘然
TA贡献1847条经验 获得超11个赞
getPackagesSoldAttribute
是一个“访问器”方法。基本上,您不会看到getPackagesSoldAttribute
直接调用,而是当代码$model->packages_sold
在后台调用时,laravel 实际上会$model->getPackagesSoldAttribute
动态调用并返回其响应作为该值。
例如,如果您想调试或测试此方法,您可以执行以下操作:
$event = ProEvent::find($someId);
$packagesSold = $event->packages_sold; // this line will call the `getPackagesSoldAttribute` and set `$packagesSold` to the value it returns.
另外值得注意的是:
这里的模型还定义了一个appends属性packages_sold
protected $appends = array('packages_sold', 'bundles_sold');
这将导致packages_sold
每当模型表示为数组或序列化时,相关方法都会自动填充该属性。
- 1 回答
- 0 关注
- 109 浏览
添加回答
举报
0/150
提交
取消