*/
public function boot()
{
+ $resourcesDir = __DIR__ . '/../resources';
+
$this->loadTranslationsFrom(realpath(__DIR__ . '/resources/lang'), self::NAMESPACE);
foreach (glob(__DIR__ . '/routes/cubist/backpack/*.php') as $filename) {
$this->loadRoutesFrom($filename);
}
+ $this->publishes([$resourcesDir . '/config/cubist.php' => config_path('cubist.php')], 'config');
$this->loadViewsFrom(realpath(__DIR__ . '/resources/views'), self::NAMESPACE);
Blade::directive('vendor_asset', function ($path) {
namespace Cubist\Backpack\app\Http\Controllers;
+use App\Models\Page;
+use Cubist\Backpack\app\Magic\Models\CMSPage;
use Cubist\Backpack\app\Magic\Models\Settings;
use Illuminate\Routing\Controller as BaseController;
$this->data['global'] = Settings::find(1);
}
+ public function index($slug = 'home')
+ {
+ $class = CMSPage::getPageClass();
+ $page = $class::findBySlug($slug);
+
+ if (!$page) {
+ $this->_404();
+ }
+
+ $this->data['title'] = $page->title;
+ $this->data['page'] = $page->withFakes()->getDecodedAttributes();
+
+ return view('pages.' . $page->template, $this->data);
+ }
+
protected function _404()
{
abort(404, 'Please go back to our <a href="' . url('') . '">homepage</a>.');
}
+
+
}
public function initFromDatabase($id = '#root')
{
+ $class = CMSPage::getPageClass();
/** @var $all CMSPage[] */
- $all = CMSPage::orderBy('lft')->get();
+ $all = $class::orderBy('lft')->get();
$this->setId('#root');
$this->setName($id);
{
return $this->_usedTemplate instanceof Redirection;
}
+
+ public static function getPageClass(){
+ $class = CMSPage::class;
+ $config = config('cubist.page_model', 'Cubist\Backpack\app\Magic\Models\CMSPage');
+ if (class_exists($config)) {
+ $class = $config;
+ }
+ return $class;
+ }
}
--- /dev/null
+<?php
+
+
+namespace Cubist\Backpack\app\Magic;
+
+
+class PageData implements \ArrayAccess
+{
+ protected $_data = [];
+
+ public function __construct($data)
+ {
+ if (is_array($data)) {
+ $this->_data = $data;
+ return;
+ }
+ if (is_object($data)) {
+ foreach ($data as $k => $v) {
+ $this->set($k, $v);
+ }
+ }
+ }
+
+ public function set($offset, $value)
+ {
+ $this->_data[$offset] = $value;
+ }
+
+ public function exists($offset)
+ {
+ return isset($this->_data[$offset]) && null !== $this->_data[$offset];
+ }
+
+ public function unset($offset)
+ {
+ unset($this->_data[$offset]);
+ }
+
+ public function get($offset, $default = null)
+ {
+ if (!$this->exists($offset)) {
+ return $default;
+ }
+ return $this->_data[$offset];
+ }
+
+ public function offsetSet($offset, $value)
+ {
+ $this->set($offset, $value);
+ }
+
+ public function offsetExists($offset)
+ {
+ return $this->exists($offset);
+ }
+
+ public function offsetUnset($offset)
+ {
+ return $this->unset($offset);
+ }
+
+ public function offsetGet($offset)
+ {
+ return $this->get($offset);
+ }
+
+ public function __get($name)
+ {
+ return $this->get($name);
+ }
+
+ public function __set($name, $value)
+ {
+ return $this->set($name, $value);
+ }
+
+ public function __unset($name)
+ {
+ $this->unset($name);
+ }
+}
--- /dev/null
+<?php
+return ['page_model' => '\App\Models\Page'];