/**
  * @return void
  */
 public function boot()
 {
     $this->getEvents()->listen('router.before', function () {
         $pages = PageModel::whereEnabled(true)->get();
         foreach ($pages as $value) {
             if ($this->getSetting()->get('site.home') !== 'page_' . $value->id) {
                 if ($value->alias) {
                     $page = new Page($value->id);
                     $this->getRouter()->get($page->getRouting(), function () use($page) {
                         return $this->app->call('Notadd\\Page\\Controllers\\PageController@show', ['id' => $page->getPageId()]);
                     });
                 }
             }
         }
     });
     $this->getRouter()->group(['namespace' => 'Notadd\\Page\\Controllers'], function () {
         $this->getRouter()->group(['middleware' => 'auth.admin', 'namespace' => 'Admin', 'prefix' => 'admin'], function () {
             $this->getRouter()->resource('page', 'PageController');
             $this->getRouter()->post('page/{id}/delete', 'PageController@delete');
             $this->getRouter()->get('page/{id}/move', 'PageController@move');
             $this->getRouter()->post('page/{id}/moving', 'PageController@moving');
             $this->getRouter()->post('page/{id}/restore', 'PageController@restore');
             $this->getRouter()->get('page/{id}/sort', 'PageController@sort');
             $this->getRouter()->post('page/{id}/sorting', 'PageController@sorting');
         });
         $this->getRouter()->resource('page', 'PageController');
     });
     $this->loadViewsFrom($this->app->basePath() . '/resources/views/pages/', 'page');
 }
 /**
  * @return \Illuminate\Contracts\View\View
  */
 public function getSite()
 {
     $this->share('title', $this->setting->get('site.title'));
     $this->share('domain', $this->setting->get('site.domain'));
     $this->share('beian', $this->setting->get('site.beian'));
     $this->share('email', $this->setting->get('site.email'));
     $this->share('statistics', $this->setting->get('site.statistics'));
     $this->share('copyright', $this->setting->get('site.copyright'));
     $this->share('company', $this->setting->get('site.company'));
     $this->share('message', $this->session->get('message'));
     $this->share('home', $this->setting->get('site.home'));
     $this->share('pages', Page::all());
     return $this->view('config.site');
 }
 /**
  * @return void
  */
 public function boot()
 {
     $this->getRouter()->get('/', function () {
         $home = $this->getSetting()->get('site.home', 'default');
         $page_id = 0;
         if ($home != 'default' && Str::contains($home, 'page_')) {
             $page_id = Str::substr($home, 5);
         }
         if ($page_id && Page::whereEnabled(true)->whereId($page_id)->count()) {
             return $this->app->call('Notadd\\Page\\Controllers\\PageController@show', ['id' => $page_id]);
         }
         $this->app->make('view')->share('logo', file_get_contents(realpath($this->app->frameworkPath() . '/views/install') . DIRECTORY_SEPARATOR . 'logo.svg'));
         return $this->app->make('view')->make('default::index');
     });
 }
Exemple #4
0
 /**
  * @return \Notadd\Foundation\Database\Eloquent\Collection|static[]
  */
 public function all()
 {
     return Model::all();
 }
Exemple #5
0
 /**
  * @return mixed
  */
 public function getTitle()
 {
     return $this->model->getAttribute('title');
 }
 /**
  * @param \Notadd\Page\Requests\PageEditRequest $request
  * @param $id
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function update(PageEditRequest $request, $id)
 {
     $page = Page::findOrFail($id);
     if ($request->hasFile('thumb_image') && $request->file('thumb_image')->isValid()) {
         $file_name = Str::random() . '.' . $request->file('thumb_image')->getClientOriginalExtension();
         $request->file('thumb_image')->move('uploads/pages/thumbs/', $file_name);
         $request->offsetSet('thumb_image', 'uploads/pages/thumbs/' . $file_name);
     }
     $request->files->replace();
     if ($page->update($request->all())) {
         return $this->redirect->to('admin/page/' . $id . '/edit');
     } else {
         return $this->redirect->back()->withInput()->withErrors('保存失败!');
     }
 }