FEATURE: add basic form for adding new category
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Modules\Categories\Entities;
|
||||
|
||||
use Franzose\ClosureTable\Models\Entity;
|
||||
|
||||
class Category extends Entity implements CategoryInterface
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'categories';
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* ClosureTable model instance.
|
||||
*
|
||||
* @var categoryClosure
|
||||
*/
|
||||
protected $closure = 'Modules\Categories\Entities\CategoryClosure';
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace Modules\Categories\Entities;
|
||||
|
||||
use Franzose\ClosureTable\Models\ClosureTable;
|
||||
|
||||
class CategoryClosure extends ClosureTable implements CategoryClosureInterface
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'category_closure';
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Modules\Categories\Entities;
|
||||
|
||||
use Franzose\ClosureTable\Contracts\ClosureTableInterface;
|
||||
|
||||
interface CategoryClosureInterface extends ClosureTableInterface
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace App;namespace Modules\Categories\Entities;
|
||||
use Franzose\ClosureTable\Contracts\EntityInterface;
|
||||
|
||||
interface CategoryInterface extends EntityInterface
|
||||
{
|
||||
}
|
||||
@@ -30,8 +30,10 @@ class Categories extends BaseHandler
|
||||
|
||||
// register links in admin menu
|
||||
$menu = \Menu::instance('mainMenu');
|
||||
// $menu->route('content.new', trans('staticpages::adminMenu.new'), ['moduleId' => self::getModuleId()], 10, ['icon' => 'fa fa-plus']);
|
||||
// $menu->route('content.overview', trans('staticpages::adminMenu.overview'), ['moduleId' => self::getModuleId()], 20, ['icon' => 'fa fa-list']);
|
||||
$menu->dropdown(trans('categories::categories.name'), function ($sub) {
|
||||
$sub->route('categories.new', trans('categories::categories.new'), [], 10, ['icon' => 'fa fa-fw fa-plus']);
|
||||
$sub->route('categories.overview', trans('categories::categories.overview'), [], 30, ['icon' => 'fa fa-fw fa-tags']);
|
||||
}, 70, ['icon' => 'fa fa-fw fa-tags']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<?php namespace Modules\Categories\Http\Controllers;
|
||||
|
||||
use Pingpong\Modules\Routing\Controller;
|
||||
|
||||
class CategoriesController extends Controller {
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('categories::index');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php namespace Modules\Categories\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Module;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Categories\Entities\Category;
|
||||
use Pingpong\Modules\Routing\Controller;
|
||||
|
||||
class CreateNewCategory extends Controller
|
||||
{
|
||||
/**
|
||||
* Display form for new category
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function getNew()
|
||||
{
|
||||
$category = new Category();
|
||||
$categories = Category::getTree();
|
||||
$modules = Module::where('enabled', true)
|
||||
->get();
|
||||
|
||||
|
||||
return view('categories::admin.new', [
|
||||
'category' => $category,
|
||||
'categories' => $categories,
|
||||
'modules' => $modules
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new category
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postNew(Request $request)
|
||||
{
|
||||
$category = new Category();
|
||||
$category->user_id = Auth::user()->id;
|
||||
$category->module_id = $request->moduleId;
|
||||
$category->name = $request->name;
|
||||
$category->url = Str::slug($request->url);
|
||||
$category->description = $request->description;
|
||||
|
||||
if ((int)$request->parentCategory) {
|
||||
$category->parent_id = $request->parentCategory;
|
||||
}
|
||||
|
||||
$category->save();
|
||||
|
||||
return redirect()
|
||||
->route('categories.overview')
|
||||
->with('success', trans('categories::categories.saveSuccessfull'));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,15 @@
|
||||
<?php
|
||||
|
||||
Route::group(['middleware' => 'web', 'prefix' => 'categories', 'namespace' => 'Modules\Categories\Http\Controllers'], function()
|
||||
{
|
||||
Route::get('/', 'CategoriesController@index');
|
||||
Route::group([
|
||||
'middleware' => ['web', 'auth', 'adminMenu'],
|
||||
'prefix' => 'admin/categories',
|
||||
'namespace' => 'Modules\Categories\Http\Controllers'
|
||||
], function () {
|
||||
Route::get('/', 'CategoriesOverview@getOverview')->name('categories.overview');
|
||||
|
||||
Route::get('/new', 'CreateNewCategory@getNew')->name('categories.new');
|
||||
Route::post('/new', 'CreateNewCategory@postNew')->name('categories.postNew');
|
||||
|
||||
Route::get('/edit/{id}', 'EditCategory@getEdit')->name('categories.edit');
|
||||
Route::post('/edit/{id}', 'EditCategory@postEdit')->name('categories.postEdit');
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
return [
|
||||
'name' => 'Categories',
|
||||
'description' => 'Module for category management and content categorization.',
|
||||
'new' => 'New category',
|
||||
'overview' => 'All categories',
|
||||
];
|
||||
@@ -0,0 +1,7 @@
|
||||
@extends('admin.layout')
|
||||
|
||||
@section('content')
|
||||
<h2>@lang('categories::categories.edit')</h2>
|
||||
|
||||
@include('categories::admin.form', ['action' => route('categories.postEdit', ['id' => $category->id])])
|
||||
@endsection
|
||||
@@ -0,0 +1,46 @@
|
||||
<form action="{{$action}}" method="post">
|
||||
{!! csrf_field() !!}
|
||||
<div class="row">
|
||||
|
||||
<label>
|
||||
@lang('categories::categories.fields.name')
|
||||
|
||||
<input type="text" name="name" value="{{old('name', $category->name)}}">
|
||||
</label>
|
||||
|
||||
<label>
|
||||
@lang('categories::categories.fields.url')
|
||||
|
||||
<input type="text" name="url" value="{{old('url', $category->url)}}">
|
||||
</label>
|
||||
|
||||
<label>
|
||||
@lang('categories::categories.fields.description')
|
||||
|
||||
<textarea name="description">{{old('description', $category->description)}}</textarea>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
@lang('categories::categories.fields.module')
|
||||
<select name="moduleId">
|
||||
@foreach($modules as $module)
|
||||
<option @if($module->id == $category->module_id) selected
|
||||
@endif value="{{$module->id}}">{{trans($module->name)}}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
@lang('categories::categories.fields.parentCategory')
|
||||
<select name="parentCategory">
|
||||
<option value=""> ---</option>
|
||||
@foreach($categories as $parentCategory)
|
||||
<option @if($parentCategory->id == $category->parent_id) selected
|
||||
@endif value="{{$parentCategory->id}}">{{$parentCategory->name}}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="button primary">@lang('categories::categories.fields.save')</button>
|
||||
</form>
|
||||
@@ -0,0 +1,7 @@
|
||||
@extends('admin.layout')
|
||||
|
||||
@section('content')
|
||||
<h2>@lang('categories::categories.new')</h2>
|
||||
|
||||
@include('categories::admin.form', ['action' => route('categories.postNew')])
|
||||
@endsection
|
||||
@@ -1,12 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Module Categories</title>
|
||||
</head>
|
||||
<body>
|
||||
@yield('content')
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user