本文整理汇总了PHP中Column::custom方法的典型用法代码示例。如果您正苦于以下问题:PHP Column::custom方法的具体用法?PHP Column::custom怎么用?PHP Column::custom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Column
的用法示例。
在下文中一共展示了Column::custom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: use
<?php
/** @var \SleepingOwl\Admin\Model\ModelConfiguration $model */
$model = Admin::model(\App\HistoryEvent::class);
$model->title('История – события');
$model->display(function () {
$display = AdminDisplay::datatables();
$display->with('date');
$display->columns([Column::checkbox(), Column::string('date.title')->label('Дата'), Column::custom()->label('Заголовок')->callback(function ($instance) {
$res = $instance->title;
if ($instance->more) {
$res .= '<br><div class="label label-primary">Кнопка – подробней</div>';
}
return $res;
}), Column::datetime('date_event')->format('d.m.Y')->label('Точная дата события'), Column::datetime('created_at')->label('Создан')->format('d.m.Y в H:i')]);
$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', 'Заголовок'), FormItem::image('image', 'Картинка'), FormItem::select('history_date_id', 'Дата')->model(\App\HistoryDate::class)->display('title')->required(), FormItem::ckeditor('description', 'Описание')->required(), FormItem::date('date_event', 'Точная дата события'), FormItem::checkbox('more', 'Показать кнопку – подробней')]);
return $form;
});
示例2: foreach
})]);
$mainDisplay->order([3, 'desc']);
$secondaryDisplay = AdminDisplay::datatables();
$secondaryDisplay->apply(function ($query) {
$query->onlyTrashed();
});
$secondaryDisplay->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::datetime('date')->label('Создан')->format('d.m.Y в H:i'), Column::datetime('created_at')->label('Импортирован')->format('d.m.Y в H:i'), Column::datetime('deleted_at')->label('Удален')->format('d.m.Y в H:i')]);
$secondaryDisplay->actions([Column::action('post_restore')->value('Восстановить записи')->icon('fa-refresh')->callback(function (\Illuminate\Database\Eloquent\Collection $collections) {
if ($collections) {
/** @var \App\Post $collection */
foreach ($collections as $collection) {
$collection->restore();
}
}
})]);
$tabs = [];
$tabs[] = AdminDisplay::tab($mainDisplay)->label('Активные записи')->active(true);
$tabs[] = AdminDisplay::tab($secondaryDisplay)->label('Удаленные записи');
return $tabs;
});
示例3: is_null
<?php
Admin::model('App\\Models\\Order')->title('')->display(function () {
$display = AdminDisplay::datatables();
$display->with();
$display->filters([]);
$display->columns([Column::custom()->label('Команда')->callback(function ($instance) {
$product = \App\Models\Product::all()->where('id', $instance->product_id)->first();
return is_null($product) ? 'Неизвестный' : $product->title;
}), Column::string('sum')->label('Сумма'), Column::custom()->label('Статус')->callback(function ($instance) {
if ($instance->status == 0) {
return '<p class="text-warning">Не оплачен</p>';
} elseif ($instance->status == 1) {
return '<p class="text-danger">Ошибка</p>';
} else {
return '<p class="text-success">Оплачен</p>';
}
})]);
return $display;
})->createAndEdit(function () {
return null;
});
示例4:
<?php
Admin::model(App\Product::class)->title('Управление товарами')->display(function () {
$display = AdminDisplay::datatables();
$display->with('category');
$display->filters([Filter::related('category_id')->model(App\Category::class)]);
$display->columns([Column::string('name')->label('Название'), Column::string('price')->label('Цена'), Column::image('image')->label('Изображение'), Column::string('category.title')->label('Категория')->append(Column::filter('category_id')), Column::custom()->label('Топ')->callback(function ($instance) {
return $instance->active ? 'да' : 'нет';
}), Column::string('product_rest')->label('Остаток')]);
return $display;
})->createAndEdit(function () {
$form = AdminForm::form();
$form->items([FormItem::text('name', 'Название'), FormItem::text('slug', 'Slug'), FormItem::text('price', 'Цена'), FormItem::image('image', 'Изображение'), FormItem::select('category_id', 'Категория')->model(App\Category::class)->display('title'), FormItem::checkbox('active', 'Топ'), FormItem::ckeditor('description', 'Описание'), FormItem::text('product_rest', 'Количество товара')->defaultValue('0')]);
return $form;
});
示例5:
<?php
/*
* This is a simple example of the main features.
* For full list see documentation.
*/
Admin::model('App\\Models\\Webpage')->title('Webpages')->alias('webpage')->display(function () {
$display = AdminDisplay::datatablesAsync();
$display->order([[4, 'desc']]);
$display->columns([Column::string('host')->label('Domain'), Column::string('path')->label('Path'), Column::custom()->label('Evaluations')->callback(function ($instance) {
return $instance->evaluations()->count();
}), Column::custom()->label('Enabled')->callback(function ($instance) {
return $instance->is_enabled ? '✓' : '✗';
}), Column::datetime('created_at')->format('d-m-Y h:i:s')->label('Created')]);
$display->columnFilters([ColumnFilter::text()->placeholder('Domain'), ColumnFilter::text()->placeholder('Path'), null, null, ColumnFilter::range()->from(ColumnFilter::date()->format('d.m.Y')->placeholder('From Date'))->to(ColumnFilter::date()->format('d.m.Y')->placeholder('To Date'))]);
return $display;
})->createAndEdit(function () {
$form = AdminForm::form();
$form->items([FormItem::checkbox('is_enabled', 'Enabled'), FormItem::text('url', 'URL')->required(), FormItem::ckeditor('description', 'Description')]);
return $form;
})->delete(null);
示例6:
if ($instance->active) {
return ' <span><i class="fa fa-chevron-down" data-toggle="tooltip" title="" data-original-title="Active"></i></span>';
}
})->orderable(false)]);
return $display;
})->createAndEdit(function () {
$form = AdminForm::form();
$form->ajax_validation(true);
$form->items([FormItem::columns()->columns([[FormItem::text('lable', 'lable'), FormItem::bsselect('user_id', 'User')->model('App\\User')->display('email')->defaultValue(Sentinel::getUser()->id), FormItem::icheckbox('active')->label('Active')->skin('flat')], [FormItem::text('comment_id', 'Page ID'), FormItem::text('comment_type')]]), FormItem::ckeditor('content', 'Content')]);
return $form;
});
/**
* Sitemaps
*/
Admin::model('App\\Sitemap')->title('Sitemap')->alias('sitemaps')->display(function () {
$display = AdminDisplay::table();
$display->filters([Filter::field('loc')->title(function ($value) {
return 'URL:' . $value;
})]);
$display->columns([Column::checkbox(), Column::string('loc')->label('loc'), Column::string('lastmod')->label('lastmod'), Column::string('changefreq')->label('changefreq'), Column::string('priority')->label('priority'), Column::string('updated_at')->label('updated_at'), Column::custom()->label('in_sitemap')->callback(function ($instance) {
if ($instance->in_sitemap) {
return ' <span><i class="fa fa-chevron-down" data-toggle="tooltip" title="" data-original-title="Active"></i></span>';
}
})->orderable(false)]);
return $display;
})->createAndEdit(function () {
$form = AdminForm::form();
$form->ajax_validation(true);
$form->items([FormItem::columns()->columns([[FormItem::text('loc', 'loc')->required(), FormItem::timestamp('lastmod', 'lastmod')->required(), FormItem::select('changefreq', 'changefreq')->enum(['always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never'])->required(), FormItem::text('priority', 'priority')->required(), FormItem::icheckbox('in_sitemap')->label('In sitemap')]])]);
return $form;
});
示例7:
<?php
Admin::model(\App\Models\Post::class)->title('Блог')->display(function () {
$display = AdminDisplay::datatables();
$display->columns([Column::string('id')->label('#'), Column::string('title')->label('Заголовок'), Column::custom()->label('Опубликован')->callback(function ($instance) {
return $instance->published ? 'Да' : 'Нет';
}), Column::datetime('created_at')->label('Дата создания')]);
return $display;
})->createAndEdit(function () {
$form = AdminForm::form();
$form->items([FormItem::columns()->columns([[FormItem::checkbox('published', 'Опубликован')->defaultValue(1), FormItem::text('title', 'Заголовок')->required(), FormItem::ckeditor('body', 'Текст')->required()]])]);
return $form;
});
示例8: 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
}
}
}
示例9:
<?php
/*
* This is a simple example of the main features.
* For full list see documentation.
*/
Admin::model('App\\Models\\License')->title('Licenses')->alias('license')->display(function () {
$display = AdminDisplay::datatablesAsync();
$display->order([[0, 'asc']]);
$display->columns([Column::string('name')->label('Name'), Column::string('duration')->label('Duration'), Column::custom()->label('Enabled')->callback(function ($instance) {
return $instance->is_enabled ? '✓' : '-';
}), Column::custom()->label('Payed version')->callback(function ($instance) {
return $instance->needs_validation ? '✓' : '-';
}), Column::datetime('created_at')->format('d-m-Y h:i:s')->label('Created'), Column::datetime('updated_at')->format('d-m-Y h:i:s')->label('Updated')]);
$display->columnFilters([ColumnFilter::text()->placeholder('Name'), null, null, null, ColumnFilter::range()->from(ColumnFilter::date()->format('d.m.Y')->placeholder('From Date'))->to(ColumnFilter::date()->format('d.m.Y')->placeholder('To Date')), ColumnFilter::range()->from(ColumnFilter::date()->format('d.m.Y')->placeholder('From Date'))->to(ColumnFilter::date()->format('d.m.Y')->placeholder('To Date'))]);
return $display;
})->edit(function () {
$form = AdminForm::form();
$form->items([FormItem::custom()->display(function ($instance) {
return '<div class="form-group ">
<label for="key">Key</label><br/>
' . $instance->key . '
</div>';
}), FormItem::text('name', 'Name')->required(), FormItem::text('duration', 'Duration')->required(), FormItem::checkbox('is_enabled', 'Enabled'), FormItem::checkbox('needs_validation', 'Payed version'), FormItem::ckeditor('description', 'Description')]);
return $form;
})->create(function () {
$form = AdminForm::form();
$form->items([FormItem::text('name', 'Name')->required(), FormItem::text('duration', 'Duration')->required(), FormItem::checkbox('is_enabled', 'Enabled'), FormItem::checkbox('needs_validation', 'Payed version'), FormItem::ckeditor('description', 'Description')]);
return $form;
});
示例10:
<?php
/*
* This is a simple example of the main features.
* For full list see documentation.
*/
Admin::model('App\\Models\\Member')->title('Members')->alias('member')->display(function () {
$display = AdminDisplay::datatablesAsync();
$display->order([[0, 'asc']]);
$display->columns([Column::checkbox(), Column::string('organization.name')->label('Organization'), Column::string('status')->label('Status'), Column::string('type')->label('Type'), Column::string('title')->label('Function'), Column::string('first_name')->label('Firstname'), Column::string('last_name')->label('Lastname'), Column::string('email')->label('Email'), Column::custom()->label('Enabled')->callback(function ($instance) {
return $instance->is_enabled ? '✓' : '-';
}), Column::datetime('created_at')->format('d-m-Y h:i:s')->label('Created')]);
$display->columnFilters([null, ColumnFilter::text()->placeholder('Organization'), null, null, null, null, null, ColumnFilter::text()->placeholder('Email'), null, ColumnFilter::range()->from(ColumnFilter::date()->format('d.m.Y')->placeholder('From Date'))->to(ColumnFilter::date()->format('d.m.Y')->placeholder('To Date'))]);
return $display;
})->edit(function () {
$form = AdminForm::form();
$form->items([FormItem::checkbox('is_enabled', 'Enabled'), FormItem::select('organization_id', 'Organization')->model('App\\Models\\Organization')->display('name'), FormItem::text('first_name', 'Firstname'), FormItem::text('last_name', 'Lastname'), FormItem::text('email', 'Email')->unique(), FormItem::text('phone', 'Phone'), FormItem::text('url', 'Website'), FormItem::text('title', 'Function'), FormItem::custom()->display(function ($instance) {
return '<div class="form-group ">
<label for="key">Key</label><br/>
' . $instance->key . '
</div>';
}), FormItem::custom()->display(function ($instance) {
return '<div class="form-group ">
<label for="key">Status</label><br/>
' . $instance->status . '
</div>';
}), FormItem::custom()->display(function ($instance) {
return '<div class="form-group ">
<label for="key">Type</label><br/>
' . $instance->type . '
</div>';
示例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
/*
* This is a simple example of the main features.
* For full list see documentation.
*/
Admin::model('App\\Models\\Organization')->title('Organizations')->alias('organization')->display(function () {
$display = AdminDisplay::datatablesAsync();
$display->order([[0, 'asc']]);
$display->columns([Column::checkbox(), Column::string('sector.name')->label('Sector'), Column::string('status')->label('Status'), Column::string('name')->label('Name'), Column::string('kvk')->label('Kvk number'), Column::string('url')->label('Website'), Column::custom()->label('Enabled')->callback(function ($instance) {
return $instance->is_enabled ? '✓' : '-';
}), Column::datetime('created_at')->format('d-m-Y h:i:s')->label('Created')]);
$display->columnFilters([null, ColumnFilter::text()->placeholder('Sector'), ColumnFilter::text()->placeholder('Name'), null, null, null, null, ColumnFilter::range()->from(ColumnFilter::date()->format('d.m.Y')->placeholder('From Date'))->to(ColumnFilter::date()->format('d.m.Y')->placeholder('To Date'))]);
return $display;
})->edit(function () {
$form = AdminForm::form();
$form->items([FormItem::checkbox('is_enabled', 'Enabled'), FormItem::select('sector_id', 'Sector')->model('App\\Models\\Sector')->display('name'), FormItem::text('name', 'Name')->required(), FormItem::text('kvk', 'Kvk Number')->unique(), FormItem::text('phone', 'Phone'), FormItem::text('email', 'Email'), FormItem::text('url', 'Website'), FormItem::custom()->display(function ($instance) {
return '<div class="form-group ">
<label for="key">Address</label><br/>
' . $instance->locations->first()->location->street . '
</div>';
}), FormItem::custom()->display(function ($instance) {
return '<div class="form-group ">
<label for="key">Zipcode</label><br/>
' . $instance->locations->first()->location->postal_code . '
</div>';
}), FormItem::custom()->display(function ($instance) {
return '<div class="form-group ">
<label for="key">City</label><br/>
' . $instance->locations->first()->location->city . '
</div>';
示例13:
<?php
\Admin::model('App\\Landing')->title('Landing')->alias('landing')->display(function () {
$display = AdminDisplay::table();
$display->with('blocks');
$display->columns([Column::checkbox(), Column::string('id')->label('#'), Column::string('title')->label('Загаловок'), Column::string('active_status')->label('Статус'), Column::custom()->label('Блоки')->callback(function ($instance) {
return '<a href="/admin/landing-blocks?landing_id=' . $instance->id . '">Редактировать</a>';
})]);
return $display;
})->edit(function ($id) {
$form = AdminForm::tabbed();
$fields = [];
$fields['Main'] = [FormItem::columns()->columns([[FormItem::text('title', 'Загаловок')->required()->unique(), FormItem::textarea('description', 'Описание')->required(), FormItem::timestamp('publish', 'Дата и время публикации')->defaultValue(Carbon\Carbon::now()), FormItem::timestamp('publish_end', 'Дата и время олкончания публикация')->defaultValue(Carbon\Carbon::now()), FormItem::text('redirect', 'Редирект'), FormItem::icheckbox('active', 'Статус')->defaultValue(true)], [FormItem::text('alias', 'Алиас')->unique(), FormItem::text('name', 'Название')->required()->unique(), FormItem::image('image', 'Картинка')]])];
$model = App\Landing::find($id);
if ($model) {
$path = base_path('App/AdminLanding/' . $model->name . '.php');
if (is_file($path)) {
$fields2 = (require_once $path);
$fields = array_merge($fields, $fields2);
}
}
$form->items($fields);
return $form;
})->create(function ($id) {
$form = AdminForm::tabbed();
$fields = [];
$fields['Main'] = [FormItem::columns()->columns([[FormItem::text('title', 'Загаловок')->required()->unique(), FormItem::textarea('description', 'Описание')->required(), FormItem::timestamp('publish', 'Дата и время публикации')->defaultValue(Carbon\Carbon::now()), FormItem::timestamp('publish_end', 'Дата и время олкончания публикация')->defaultValue(Carbon\Carbon::now()), FormItem::text('redirect', 'Редирект'), FormItem::icheckbox('active', 'Статус')->defaultValue(true)], [FormItem::text('alias', 'Алиас')->unique(), FormItem::text('name', 'Название')->required()->unique(), FormItem::image('image', 'Картинка')]])];
$form->items($fields);
return $form;
});
示例14:
<?php
Admin::model('App\\Models\\Product')->title('')->display(function () {
$display = AdminDisplay::datatables();
$display->with();
$display->filters([]);
$display->columns([Column::string('title')->label('Title'), Column::image('image')->label('Title'), Column::string('m_desc')->label('Description'), Column::string('price')->label('Price'), Column::string('discount')->label('Discount'), Column::custom()->label('Active')->callback(function ($instance) {
return $instance->active ? '✓' : '-';
})]);
return $display;
})->createAndEdit(function () {
$form = AdminForm::form();
$form->items([FormItem::text('title', 'Title')->required(), FormItem::text('slug', 'Slug')->required(), FormItem::text('m_desc', 'Mini Description')->required(), FormItem::ckeditor('f_desc', 'Full Description')->required(), FormItem::image('image', 'Image')->required(), FormItem::select('server_id', 'Server')->model('App\\Models\\Server')->display('name')->required(), FormItem::text('command', 'Command')->required(), FormItem::text('price', 'Price')->required(), FormItem::text('discount', 'Discount')->defaultValue(0)->required()->validationRule(['numeric', 'max:99']), FormItem::checkbox('countable', 'Countable'), FormItem::checkbox('active', 'Active')]);
return $form;
});
示例15: strlen
$display = AdminDisplay::tabbed();
$display->tabs(function () {
$tabs = [];
$columns = [Column::string('title')->label('Title'), Column::datetime('date')->label('Date')->format('d.m.Y'), Column::custom()->label('Published')->callback(function ($instance) {
return $instance->published ? '✓' : '-';
})];
$main = AdminDisplay::table();
$main->columns($columns);
$tabs[] = AdminDisplay::tab($main)->label('Main')->active(true);
$withScope = AdminDisplay::table();
$withScope->scope('last');
$withScope->columns($columns);
$tabs[] = AdminDisplay::tab($withScope)->label('With Scope');
$otherColumns = AdminDisplay::table();
$otherColumns->apply(function ($query) {
$query->orderBy('title', 'asc');
});
$otherColumns->columns([Column::string('title')->label('Title'), Column::custom()->label('Title Length')->callback(function ($instance) {
return strlen($instance->title);
})]);
$tabs[] = AdminDisplay::tab($otherColumns)->label('Other Columns and Order');
$otherDisplay = Admin::model('App\\Page')->display();
$tabs[] = AdminDisplay::tab($otherDisplay)->label('Display from Other Model');
return $tabs;
});
return $display;
})->createAndEdit(function () {
$form = AdminForm::form();
$form->items([FormItem::text('title', 'Title')->required(), FormItem::date('date', 'Date')->required()->format('d.m.Y'), FormItem::checkbox('published', 'Published'), FormItem::ckeditor('text', 'Text')]);
return $form;
});