public function postsImport() { $start = Carbon::now(); $stats = \App\Imports\Post::import(620, 5); $stop = Carbon::now(); $stats['time'] = $start->diffForHumans($stop, true); $content = view('admin.integration.imports.posts-success', $stats)->render(); return Admin::view($content, 'Импорт завершен'); }
/** * Execute the console. * * @return mixed */ public function handle() { $offset = $this->argument('offset') ?: 0; $count = $this->argument('count') ?: 10; $this->info('Начинаю загрузку постов. ' . date('d.m.Y H:i')); $res = \App\Imports\Post::import($offset, $count); $this->info('Загрузка завершена.'); $this->comment('Запрос: offset -> ' . $offset . '; count -> ' . $count); $this->comment('Всего записей: ' . $res['counts']['all']); $this->comment('Постов: ' . $res['counts']['posts']); $this->comment('Новых постов: ' . $res['counts']['new_posts']); $this->comment('Вложений: ' . $res['counts']['attachments']); $this->comment('Новых вложений: ' . $res['counts']['new_attachments']); }
$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(); }); $secondaryDisplay->columns([Column::checkbox(), Column::string('id'), Column::custom()->label('Картинка')->callback(function ($instance) { $attachment = $instance->attachments()->first();