callResolving(); if ($callback instanceof Closure) { $callback($this); } } /** * Create a content instance. * * @param mixed ...$params * * @return $this */ public static function make(...$params) { return new static(...$params); } /** * @param string $header * * @return $this */ public function header($header = '') { return $this->title($header); } /** * Set title of content. * * @param string $title * * @return $this */ public function title($title) { $this->title = $title; return $this; } /** * Set description of content. * * @param string $description * * @return $this */ public function description($description = '') { $this->description = $description; return $this; } /** * Disable navbar and sidebar. * * @return $this */ public function simple() { $this->view = 'admin::contents.simple'; Admin::$disableSkinCss = true; return $this; } /** * Set breadcrumb of content. * * exp: * $this->breadcrumb('Menu', 'auth/menu', 'fa fa-align-justify'); * $this->breadcrumb([ * ['text' => 'Menu', 'url' => 'auth/menu', 'icon' => 'fa fa-align-justify'] * ]); * * @param array ...$breadcrumb * * @return $this */ public function breadcrumb(...$breadcrumb) { $this->formatBreadcrumb($breadcrumb); $this->breadcrumb = array_merge($this->breadcrumb, $breadcrumb); return $this; } /** * @param array $breadcrumb * * @throws \Exception * * @return void */ protected function formatBreadcrumb(array &$breadcrumb) { if (! $breadcrumb) { throw new \Exception('Breadcrumb format error!'); } $notArray = false; foreach ($breadcrumb as &$item) { $isArray = is_array($item); if ($isArray && ! isset($item['text'])) { throw new \Exception('Breadcrumb format error!'); } if (! $isArray && $item) { $notArray = true; } } if (! $breadcrumb) { throw new \Exception('Breadcrumb format error!'); } if ($notArray) { $breadcrumb = [ [ 'text' => $breadcrumb[0] ?? null, 'url' => $breadcrumb[1] ?? null, 'icon' => $breadcrumb[2] ?? null, ], ]; } } /** * Alias of method row. * * @param mixed $content * * @return Content */ public function body($content) { return $this->row($content); } /** * Add one row for content body. * * @param $content * * @return $this */ public function row($content) { if ($content instanceof Closure) { $row = new Row(); call_user_func($content, $row); $this->addRow($row); } else { $this->addRow(new Row($content)); } return $this; } /** * @param $content * * @return $this */ public function prepend($content) { if ($content instanceof Closure) { $row = new Row(); call_user_func($content, $row); $this->prependRow($row); } else { $this->prependRow(new Row($content)); } return $this; } protected function prependRow(Row $row) { array_unshift($this->rows, $row); } /** * Add Row. * * @param Row $row */ protected function addRow(Row $row) { $this->rows[] = $row; } /** * Build html of content. * * @return string */ public function build() { $html = ''; foreach ($this->rows as $row) { $html .= $row->render(); } return $html; } /** * Set success message for content. * * @param string $title * @param string $message * * @return $this */ public function withSuccess($title = '', $message = '') { admin_success($title, $message); return $this; } /** * Set error message for content. * * @param string $title * @param string $message * * @return $this */ public function withError($title = '', $message = '') { admin_error($title, $message); return $this; } /** * Set warning message for content. * * @param string $title * @param string $message * * @return $this */ public function withWarning($title = '', $message = '') { admin_warning($title, $message); return $this; } /** * Set info message for content. * * @param string $title * @param string $message * * @return $this */ public function withInfo($title = '', $message = '') { admin_info($title, $message); return $this; } /** * Set content view. * * @param null|string $view * * @return $this */ public function view(?string $view) { $this->view = $view; return $this; } /** * Setup styles. */ protected function setupStyles() { if ( $this->view !== 'admin::contents.simple' && in_array('fixed', (array) config('admin.layout')) ) { Admin::style( <<<'CSS' #nprogress .spinner{position:fixed!important;top:75px;}#nprogress .bar{top:61px;}.fixed-solution .sticky-table-header{top:61px!important} CSS ); } } protected function shareDefaultErrors() { if (! session()->all()) { view()->share(['errors' => new ViewErrorBag()]); } } /** * Render this content. * * @return string */ public function render() { $this->callComposing(); $this->setupStyles(); $this->shareDefaultErrors(); $items = [ 'header' => $this->title, 'description' => $this->description, 'breadcrumb' => $this->breadcrumb, 'content' => $this->build(), ]; return view($this->view, $items)->render(); } }