本文整理汇总了PHP中Column::count方法的典型用法代码示例。如果您正苦于以下问题:PHP Column::count方法的具体用法?PHP Column::count怎么用?PHP Column::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Column
的用法示例。
在下文中一共展示了Column::count方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
<?php
/*
* This is a simple example of the main features.
* For full list see documentation.
*/
Admin::model('App\\User')->title('Users')->display(function () {
$display = AdminDisplay::datatables();
$display->with('link');
$display->order([[0, 'desc']]);
$display->columns([Column::string('name')->label('Name'), Column::string('lastname')->label('Last Name'), Column::string('email')->label('Email'), Column::count('link')->label('Links count')]);
return $display;
})->createAndEdit(function () {
$form = AdminForm::form();
$form->items([FormItem::text('name', 'Name')->required(), FormItem::text('email', 'Email')->required()->unique()]);
return $form;
});
示例2:
<?php
Admin::model('\\Country')->title('Countries')->with('contacts')->columns(function () {
Column::string('title', 'Title');
Column::count('contacts', 'Contacts')->append(Column::filter('country_id')->model('\\Contact'));
})->form(function () {
FormItem::text('title', 'Title')->required()->unique();
});
示例3:
<?php
Admin::model(\App\Model\Category::class)->title('Категории Блога')->display(function () {
$display = AdminDisplay::datatables();
$display->with('pages');
$display->filters([]);
$display->columns([Column::string('title')->label('Название'), Column::count('pages.id')->label('Количество статей'), Column::action('show')->label('Label')->callback(function ($query) {
return $query->active ? '✓' : '-';
})]);
return $display;
})->createAndEdit(function () {
$form = AdminForm::tabbed();
$form->items(['Main' => [FormItem::hidden('user_id')->defaultValue(AdminAuth::user()->id), FormItem::text('title', 'Заголовок'), FormItem::text('slug', 'Slug - Заполняется автоматически'), FormItem::ckeditor('content', 'Content'), FormItem::textarea('descriptor', 'Краткое описание')]]);
return $form;
});
示例4: str_limit
$model->display(function () {
$display = AdminDisplay::tabbed();
$display->tabs(function () {
$mainDisplay = AdminDisplay::datatables();
$mainDisplay->columns([Column::checkbox(), Column::string('id'), Column::custom()->label('Картинка')->callback(function ($instance) {
$attachment = $instance->attachments()->first();
if (!is_null($attachment)) {
if ($attachment->type === 'album') {
$attachment = $attachment->childs()->first();
}
return "<img class='thumbnail' width='80px' src='{$attachment->srcs['image_small']}'>";
}
return '';
}), Column::custom()->label('Текст')->callback(function ($instance) {
return str_limit($instance->text, 180);
}), Column::count('attachments')->label('Вложений'), Column::datetime('date')->label('Создан')->format('d.m.Y в H:i'), Column::datetime('created_at')->label('Импортирован')->format('d.m.Y в H:i')]);
$mainDisplay->actions([Column::action('post_import')->value('Импортировать последние 10 записей')->icon('fa-share')->callback(function ($collection) {
\App\Imports\Post::import(0, 10);
}), Column::action('post_trashed')->value('Удалить записи')->icon('fa-times')->callback(function (\Illuminate\Database\Eloquent\Collection $collections) {
if ($collections) {
/** @var \App\Post $collection */
foreach ($collections as $collection) {
$collection->delete();
}
}
})]);
$mainDisplay->order([3, 'desc']);
$secondaryDisplay = AdminDisplay::datatables();
$secondaryDisplay->apply(function ($query) {
$query->onlyTrashed();
});
示例5: switch
<?php
use App\Models;
use SleepingOwl\Admin\Models\Form\FormGroup;
Admin::model(\App\Models\Order::class)->title('Orders')->denyCreating(function () {
return true;
})->columns(function () {
Column::string('id', 'Id');
Column::string('customer.login', 'Customer')->inlineEdit(true);
Column::callback('orders_status_id', 'Status')->contentCallback(function ($instance) {
return $instance->status()->first()->getName();
})->inlineEdit(true);
Column::string('total', 'Total')->inlineEdit(true);
Column::count('items', 'Items');
})->inlineEdit(function ($field) {
switch ($field) {
case 'customer.login':
return function () {
InlineEditItem::select('customer_id', NULL)->list(Models\Customer::class);
};
break;
case 'orders_status_id':
return function () {
InlineEditItem::select('orders_status_id', NULL)->list(Models\OrdersStatus::class);
};
break;
case 'total':
return function () {
InlineEditItem::text('total', NULL)->validationRule('required|regexp:\\d');
};
break;
示例6: use
<?php
/** @var \SleepingOwl\Admin\Model\ModelConfiguration $model */
$model = Admin::model(\App\HistoryDate::class);
$model->title('История – даты');
$model->display(function () {
$display = AdminDisplay::datatables();
$display->columns([Column::checkbox(), Column::string('title')->label('Заголовок')->orderable(false), Column::string('description')->label('Описание')->orderable(false), Column::count('events')->label('Событий')->orderable(false), Column::datetime('created_at')->label('Создан')->format('d.m.Y в H:i')->orderable(false), Column::order()->orderable(false)]);
$display->order([[5, 'asc']]);
$display->apply(function (\Illuminate\Database\Eloquent\Builder $query) {
$query->withTrashed();
});
return $display;
})->createAndEdit(function ($id) use($model) {
$model->title($id ? 'Редактировать дату' : 'Создать дату');
$form = AdminForm::form();
$form->items([FormItem::text('title', 'Заголовок')->required(), FormItem::text('description', 'Описание')]);
return $form;
});
示例7: switch
<?php
use SleepingOwl\Admin\Models\Form\FormGroup;
Admin::model(\App\Models\Customer::class)->title('Customers')->denyEditingAndDeleting(function ($instance) {
return false;
})->columns(function () {
Column::string('id', 'Id');
Column::string('name', 'Name')->inlineEdit(true);
Column::string('second_name', 'Second Name')->inlineEdit(true);
Column::string('last_name', 'Last Name')->inlineEdit(true);
Column::string('email', 'Email');
Column::string('login', 'Login');
Column::count('photos', 'Photos');
Column::count('addresses', 'Addresses');
})->inlineEdit(function ($field) {
switch ($field) {
case 'name':
return function () {
InlineEditItem::text('name', NULL)->validationRule('required|regex:/^[a-zA-Z0-9_@]{3,100}$/');
};
break;
case 'second_name':
return function () {
InlineEditItem::text('second_name', NULL)->validationRule('required|regex:/^[a-zA-Z0-9_@]{3,100}$/');
};
break;
case 'last_name':
return function () {
InlineEditItem::text('last_name', NULL)->validationRule('required|regex:/^[a-zA-Z0-9_@]{3,100}$/');
};
break;
示例8:
<?php
Admin::model('App\\Country')->title('Countries (orderable)')->display(function () {
$display = AdminDisplay::table();
$display->apply(function ($query) {
$query->orderBy('order', 'asc');
});
$display->columns([Column::string('title')->label('Title'), Column::count('contacts')->label('Contacts')->append(Column::filter('country_id')->model('App\\Contact')), Column::order()]);
return $display;
})->createAndEdit(function () {
$form = AdminForm::form();
$form->items([FormItem::text('title', 'Title')->required()->unique()]);
return $form;
});
示例9:
<?php
Admin::model('App\\Category')->title('Categories')->display(function () {
$display = AdminDisplay::datatables();
$display->with('link');
$display->filters([]);
$display->columns([Column::string('name')->label('Name'), Column::count('link')->label('Links count')]);
return $display;
})->createAndEdit(function () {
$form = AdminForm::form();
$form->items([FormItem::text('name', 'Name')]);
return $form;
});
示例10: config
<?php
/*
* This is a simple example of the main features.
* For full list see documentation.
*/
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Input;
use App\Product;
use App\UserProduct;
Admin::model('App\\User')->title('Пользователи')->display(function () {
$display = AdminDisplay::datatables();
$display->columns([Column::checkbox(), Column::string('id')->label('ID'), Column::string('name')->label('Имя'), Column::custom()->label('Актив.')->callback(function ($instance) {
return $instance->is_active ? '✓' : '-';
}), Column::string('email')->label('Email'), Column::count('products')->label('Товаров')->orderable(true), Column::count('list_active_products')->label('Акт. товаров')->orderable(true), Column::string('balance')->label('Баланс')]);
$display->columnFilters([null, ColumnFilter::select()->model('App\\User')->display('name'), null, null, null, null]);
$display->actions([Column::action('export')->value('Раздать товары')->icon('fa-share')->callback(function ($collection) {
$max_products_per_user = config('main.max_products_per_user', 3);
foreach ($collection as $key => $user) {
$active_products = $user->list_active_products;
$count_active_products = count($active_products);
if ($count_active_products >= 0 && $count_active_products < $max_products_per_user) {
$random_product = Product::orderByRaw("RAND()")->first();
try {
$user_product = UserProduct::create(['user_id' => $user->id, 'product_id' => $random_product->id]);
} catch (QueryException $e) {
//Nothing
}
}
}
示例11: dd
<?php
Admin::model('App\\Contact')->title('Contacts')->display(function () {
$display = AdminDisplay::table();
$display->with('country', 'companies');
$display->filters([Filter::related('country_id')->model('App\\Country')]);
$display->columns([Column::image('photo')->label('Photo<br/><small>(image)</small>'), Column::string('fullName')->label('Name<br/><small>(string with accessor)</small>'), Column::datetime('birthday')->label('Birthday<br/><small>(datetime)</small>')->format('d.m.Y'), Column::string('country.title')->label('Country<br/><small>(string from related model)</small>')->append(Column::filter('country_id')), Column::count('companies')->label('Companies<br/><small>(count)</small>'), Column::lists('companies.title')->label('Companies<br/><small>(lists)</small>'), Column::custom()->label('Has Photo?<br/><small>(custom)</small>')->callback(function ($instance) {
return $instance->photo ? '✓' : '-';
}), Column::action('my_action')->label('<small>(action)</small>')->value('Custom action')->target('_blank')->callback(function ($instance) {
dd('Custom action called with instance:', $instance->toArray());
})]);
return $display;
})->createAndEdit(null)->delete(null);
示例12:
<?php
Admin::model('App\\Category')->title('Categorias')->display(function () {
$display = AdminDisplay::table();
$display->apply(function ($query) {
$query->orderBy('order', 'asc');
});
$display->columns([Column::string('name')->label('Nombre'), Column::count('products')->label('Productos'), Column::order()]);
return $display;
})->createAndEdit(function () {
$form = AdminForm::form();
$form->items([FormItem::text('name', 'Nombre'), FormItem::image('banner', 'Banner'), FormItem::ckeditor('description', 'Descripcion')]);
return $form;
});
示例13:
<?php
Admin::model('App\\Models\\Server')->title(trans('admin::pages.servers.title'))->display(function () {
$display = AdminDisplay::datatables();
$display->with();
$display->filters([]);
$display->columns([Column::string('name')->label('Name'), Column::string('ip')->label('Ip'), Column::string('port')->label('Port'), Column::string('engine')->label('Engine'), Column::count('products')->label('Товаров')]);
return $display;
})->createAndEdit(function () {
$form = AdminForm::form();
$form->items([FormItem::text('name', 'Name')->required(), FormItem::text('ip', 'Ip')->required(), FormItem::text('port', 'Port')->required(), FormItem::text('rcon_password', 'RCON password'), FormItem::select('engine', 'Engine')->options([0 => 'CS 1.6', 1 => 'Counter-Strike: Source', 2 => 'Counter-Strike: Global Offensive'])->required(), FormItem::checkbox('active', 'Active')]);
return $form;
});