使用! 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
是一個“訪問器”方法?;旧希粫吹?code>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 關注
- 159 瀏覽
添加回答
舉報
0/150
提交
取消