diff --git a/modules/StaticPages/Http/Controllers/Admin/CreateNewStaticPage.php b/modules/StaticPages/Http/Controllers/Admin/CreateNewStaticPage.php index da6a4c43..1f8fb202 100644 --- a/modules/StaticPages/Http/Controllers/Admin/CreateNewStaticPage.php +++ b/modules/StaticPages/Http/Controllers/Admin/CreateNewStaticPage.php @@ -1,10 +1,46 @@ []]); + } + + /** + * Save new static page + * + * @param CreateNewStaticPageRequest $request + * + * @return \Illuminate\Http\RedirectResponse + */ + public function postNew(CreateNewStaticPageRequest $request) + { + $page = new Content(); + + // @todo add module_handler + + $page->user_id = \Auth::user()->id; + $page->title = $request->title; + $page->published_from = $request->publishedFrom; + $page->published_to = $request->publishedTo; + $page->meta_keywords = $request->meta_description; + $page->meta_description = $request->meta_description; + $page->content = $request->pageContent; + + $page->save(); + + return redirect() + ->route('staticpages.new') + ->with('success', trans('admin.successfullyCreated')); } } \ No newline at end of file diff --git a/modules/StaticPages/Http/Requests/CreateNewStaticPageRequest.php b/modules/StaticPages/Http/Requests/CreateNewStaticPageRequest.php new file mode 100644 index 00000000..6db5f5d7 --- /dev/null +++ b/modules/StaticPages/Http/Requests/CreateNewStaticPageRequest.php @@ -0,0 +1,25 @@ + 'required', + 'url' => 'required|unique:contents,url', + 'published_from' => 'date', + 'published_to' => 'date', + 'title_photo' => 'exists:files,id', + 'module_settings' => 'json', + 'status' => 'required|in:draft,protected,public' + ]; + } +} diff --git a/modules/StaticPages/Http/routes.php b/modules/StaticPages/Http/routes.php index 70629721..f729916b 100644 --- a/modules/StaticPages/Http/routes.php +++ b/modules/StaticPages/Http/routes.php @@ -15,10 +15,20 @@ Route::group([ 'prefix' => 'admin/pages', 'namespace' => 'Modules\StaticPages\Http\Controllers\Admin' ], function () { + + // list of all static pages Route::get('overview', 'StaticPageOverview@getOverview') ->name('staticpage.overview'); + + // form for creating new static page Route::get('new', 'CreateNewStaticPage@getNew') ->name('staticpage.new'); + + // form for editing existing static page Route::get('edit/{id}', 'EditStaticPage@getEdit') ->name('staticpage.edit'); + + // post method for creating new static page + Route::post('new', 'CreateNewStaticPage@getNew') + ->name('staticpage.newPost'); }); \ No newline at end of file diff --git a/modules/StaticPages/Providers/StaticPagesServiceProvider.php b/modules/StaticPages/Providers/StaticPagesServiceProvider.php index 8352f756..5020d69b 100644 --- a/modules/StaticPages/Providers/StaticPagesServiceProvider.php +++ b/modules/StaticPages/Providers/StaticPagesServiceProvider.php @@ -1,99 +1,95 @@ registerTranslations(); + $this->registerConfig(); + $this->registerViews(); - /** - * Boot the application events. - * - * @return void - */ - public function boot() - { - $this->registerTranslations(); - $this->registerConfig(); - $this->registerViews(); + // register links in admin menu + $menu = \Menu::instance('mainMenu'); + $menu->dropdown(trans('staticpages::adminMenu.staticPages'), function ($submenu) { + $submenu->route('staticpage.new', trans('staticpages::adminMenu.new')); + $submenu->route('staticpage.overview', trans('staticpages::adminMenu.overview')); + }, 15, ['icon' => 'fa fa-newspaper-o']); + } - // register links in admin menu - $menu = \Menu::instance('mainMenu'); - $menu->dropdown(trans('staticpages::adminMenu.staticPages'), function($submenu) { - $submenu->route('staticpage.new', trans('staticpages::adminMenu.new')); - $submenu->route('staticpage.overview', trans('staticpages::adminMenu.overview')); - }, 15, ['icon' => 'fa fa-newspaper-o']); - } + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + // + } - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - // - } + /** + * Register config. + * + * @return void + */ + protected function registerConfig() + { + $this->publishes([ + __DIR__ . '/../Config/config.php' => config_path('staticpages.php'), + ]); + $this->mergeConfigFrom(__DIR__ . '/../Config/config.php', 'staticpages'); + } - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - __DIR__.'/../Config/config.php' => config_path('staticpages.php'), - ]); - $this->mergeConfigFrom( - __DIR__.'/../Config/config.php', 'staticpages' - ); - } + /** + * Register views. + * + * @return void + */ + public function registerViews() + { + $viewPath = base_path('resources/views/modules/staticpages'); - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = base_path('resources/views/modules/staticpages'); + $sourcePath = __DIR__ . '/../Resources/views'; - $sourcePath = __DIR__.'/../Resources/views'; + $this->publishes([ + $sourcePath => $viewPath + ]); - $this->publishes([ - $sourcePath => $viewPath - ]); + $this->loadViewsFrom(array_merge(array_map(function ($path) { + return $path . '/modules/staticpages'; + }, \Config::get('view.paths')), [$sourcePath]), 'staticpages'); + } - $this->loadViewsFrom(array_merge(array_map(function ($path) { - return $path . '/modules/staticpages'; - }, \Config::get('view.paths')), [$sourcePath]), 'staticpages'); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'staticpages'); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array(); - } + /** + * Register translations. + * + * @return void + */ + public function registerTranslations() + { + $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'staticpages'); + } + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return []; + } } diff --git a/modules/StaticPages/Resources/lang/en/admin.php b/modules/StaticPages/Resources/lang/en/admin.php index be77c359..77ca7463 100644 --- a/modules/StaticPages/Resources/lang/en/admin.php +++ b/modules/StaticPages/Resources/lang/en/admin.php @@ -1,5 +1,7 @@ 'List of all static pages', - 'new' => 'Create new static page' + 'new' => 'Create new static page', + 'content' => 'Page content', + 'save' => 'Save new page' ]; \ No newline at end of file diff --git a/modules/StaticPages/Resources/views/admin/new.blade.php b/modules/StaticPages/Resources/views/admin/new.blade.php new file mode 100644 index 00000000..e0a2d47f --- /dev/null +++ b/modules/StaticPages/Resources/views/admin/new.blade.php @@ -0,0 +1,15 @@ +@extends('admin.layout') + +@section('pageName', @trans('staticpages::admin.new')) + +@section('content') + +
+

@lang('staticpages::admin.new')

+ +
+ +
+ @include('staticpages::admin.newForm') +
+@stop \ No newline at end of file diff --git a/modules/StaticPages/Resources/views/admin/newForm.blade.php b/modules/StaticPages/Resources/views/admin/newForm.blade.php new file mode 100644 index 00000000..f0ecad59 --- /dev/null +++ b/modules/StaticPages/Resources/views/admin/newForm.blade.php @@ -0,0 +1,121 @@ +@if (session('success')) +
+ {{ session('success') }} +
+@endif + +@if (session('error')) +
+ {{ session('error') }} +
+@endif + +
+ {!! csrf_field() !!} + + + +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+
+
+
+
+ +
+ +
+ +
+
+
+ +
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
\ No newline at end of file diff --git a/modules/StaticPages/Resources/views/index.blade.php b/modules/StaticPages/Resources/views/index.blade.php deleted file mode 100644 index 3c5ecc9d..00000000 --- a/modules/StaticPages/Resources/views/index.blade.php +++ /dev/null @@ -1,11 +0,0 @@ -@extends('staticpages::layouts.master') - -@section('content') - -

Hello World

- -

- This view is loaded from module: {!! config('staticpages.name') !!} -

- -@stop \ No newline at end of file