FEATURE #1370: add form for creating new static page
This commit is contained in:
@@ -1,10 +1,46 @@
|
||||
<?php
|
||||
namespace Modules\StaticPages\Http\Controllers\Admin;
|
||||
|
||||
use App\Models\Content;
|
||||
use Modules\StaticPages\Http\Requests\CreateNewStaticPageRequest;
|
||||
|
||||
class CreateNewStaticPage extends Controller
|
||||
{
|
||||
/**
|
||||
* Display form for new static page
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function getNew()
|
||||
{
|
||||
return view('staticpages::index');
|
||||
return view('staticpages::admin.new', ['contentStates' => []]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Modules\StaticPages\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class CreateNewStaticPageRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'title' => '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'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
});
|
||||
Reference in New Issue
Block a user