Commit f89cac67 authored by jinyonson's avatar jinyonson

文章分类树

parent 9377f982
<?php
return [
'name' => 'Blog'
];
<?php
namespace Modules\Blog\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class BlogDatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
// $this->call("OthersTableSeeder");
}
}
<?php
namespace Modules\Blog\Entities;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $fillable = [];
}
<?php
namespace Modules\Blog\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
class BlogController extends Controller
{
/**
* Display a listing of the resource.
* @return Response
*/
public function index()
{
return view('blog::index');
}
/**
* Show the form for creating a new resource.
* @return Response
*/
public function create()
{
return view('blog::create');
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
}
/**
* Show the specified resource.
* @return Response
*/
public function show()
{
return view('blog::show');
}
/**
* Show the form for editing the specified resource.
* @return Response
*/
public function edit()
{
return view('blog::edit');
}
/**
* Update the specified resource in storage.
* @param Request $request
* @return Response
*/
public function update(Request $request)
{
}
/**
* Remove the specified resource from storage.
* @return Response
*/
public function destroy()
{
}
}
<?php
namespace Modules\Blog\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factory;
class BlogServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->registerFactories();
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->register(RouteServiceProvider::class);
}
/**
* Register config.
*
* @return void
*/
protected function registerConfig()
{
$this->publishes([
__DIR__.'/../Config/config.php' => config_path('blog.php'),
], 'config');
$this->mergeConfigFrom(
__DIR__.'/../Config/config.php', 'blog'
);
}
/**
* Register views.
*
* @return void
*/
public function registerViews()
{
$viewPath = resource_path('views/modules/blog');
$sourcePath = __DIR__.'/../Resources/views';
$this->publishes([
$sourcePath => $viewPath
],'views');
$this->loadViewsFrom(array_merge(array_map(function ($path) {
return $path . '/modules/blog';
}, \Config::get('view.paths')), [$sourcePath]), 'blog');
}
/**
* Register translations.
*
* @return void
*/
public function registerTranslations()
{
$langPath = resource_path('lang/modules/blog');
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, 'blog');
} else {
$this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'blog');
}
}
/**
* Register an additional directory of factories.
*
* @return void
*/
public function registerFactories()
{
if (! app()->environment('production')) {
app(Factory::class)->load(__DIR__ . '/../Database/factories');
}
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [];
}
}
<?php
namespace Modules\Blog\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* The root namespace to assume when generating URLs to actions.
*
* @var string
*/
protected $namespace = 'Modules\Blog\Http\Controllers';
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*
* @return void
*/
public function boot()
{
parent::boot();
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(__DIR__ . '/../Routes/web.php');
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(__DIR__ . '/../Routes/api.php');
}
}
@extends('blog::layouts.master')
@section('content')
<h1>Hello World</h1>
<p>
This view is loaded from module: {!! config('blog.name') !!}
</p>
@stop
<!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 Blog</title>
{{-- Laravel Mix - CSS File --}}
{{-- <link rel="stylesheet" href="{{ mix('css/blog.css') }}"> --}}
</head>
<body>
@yield('content')
{{-- Laravel Mix - JS File --}}
{{-- <script src="{{ mix('js/blog.js') }}"></script> --}}
</body>
</html>
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:api')->get('/blog', function (Request $request) {
return $request->user();
});
\ No newline at end of file
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::prefix('blog')->group(function() {
Route::get('/', 'BlogController@index');
});
Route::get('/blog', '\Modules\Blog\Http\Controllers\BlogController@index');
{
"name": "nwidart/blog",
"description": "",
"authors": [
{
"name": "Nicolas Widart",
"email": "n.widart@gmail.com"
}
],
"extra": {
"laravel": {
"providers": [
"Modules\\Blog\\Providers\\BlogServiceProvider"
],
"aliases": {
}
}
},
"autoload": {
"psr-4": {
"Modules\\Blog\\": ""
}
}
}
{
"name": "Blog",
"alias": "blog",
"description": "",
"keywords": [],
"active": 1,
"order": 0,
"providers": [
"Modules\\Blog\\Providers\\BlogServiceProvider"
],
"aliases": {},
"files": [],
"requires": []
}
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"cross-env": "^5.1.4",
"laravel-mix": "^2.1",
"laravel-mix-merge-manifest": "^0.1.1"
}
}
\ No newline at end of file
const { mix } = require('laravel-mix');
require('laravel-mix-merge-manifest');
mix.setPublicPath('../../public').mergeManifest();
mix.js(__dirname + '/Resources/assets/js/app.js', 'js/blog.js')
.sass( __dirname + '/Resources/assets/sass/app.scss', 'css/blog.css');
if (mix.inProduction()) {
mix.version();
}
\ No newline at end of file
...@@ -18,4 +18,8 @@ ...@@ -18,4 +18,8 @@
* *
*/ */
use App\Admin\Extensions\Form\uEditor;
use Encore\Admin\Form;
Form::extend('ueditor', uEditor::class);
Encore\Admin\Form::forget(['map', 'editor']); Encore\Admin\Form::forget(['map', 'editor']);
...@@ -4,15 +4,26 @@ namespace App; ...@@ -4,15 +4,26 @@ namespace App;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use DB; use DB;
use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
class Articlecat extends Model class Articlecat extends Model
{ {
use ModelTree, AdminBuilder;
protected $table = 'articlecats'; protected $table = 'articlecats';
protected $fillable = [ protected $fillable = [
'id', 'pid', 'name', 'sort_order', 'id', 'pid', 'name', 'sort_order',
]; ];
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->setParentColumn('pid');
$this->setOrderColumn('sort_order');
$this->setTitleColumn('name');
}
public static function getSelectOptions() public static function getSelectOptions()
{ {
...@@ -23,6 +34,7 @@ class Articlecat extends Model ...@@ -23,6 +34,7 @@ class Articlecat extends Model
} }
return $selectOption; return $selectOption;
} }
public function articles() public function articles()
{ {
return $this->hasOne(articles::class); return $this->hasOne(articles::class);
......
...@@ -113,7 +113,8 @@ class ArticleController extends Controller ...@@ -113,7 +113,8 @@ class ArticleController extends Controller
{ {
$form = new Form(new Article); $form = new Form(new Article);
$form->text('title', '标题')->rules('required'); $form->text('title', '标题')->rules('required');
$form->select('articlecats_id','分类')->options(Articlecat::getSelectOptions()); //$form->select('articlecats_id','分类')->options(Articlecat::getSelectOptions());
$form->select('articlecats_id','分类')->options(Articlecat::selectOptions());
$form->text('message', '描述'); $form->text('message', '描述');
//$form->text('content', '内容'); //$form->text('content', '内容');
//$form->ueditor('content', '内容')->rules('required');; //$form->ueditor('content', '内容')->rules('required');;
......
...@@ -2,117 +2,216 @@ ...@@ -2,117 +2,216 @@
namespace App\Http\Controllers\Admin; namespace App\Http\Controllers\Admin;
//use App\Articlecat;
//use App\Http\Controllers\Controller;
//use Encore\Admin\Controllers\HasResourceActions;
//use Encore\Admin\Form;
//use Encore\Admin\Grid;
//use Encore\Admin\Layout\Content;
//use Encore\Admin\Show;
//use Encore\Admin\Controllers\ModelForm;
//use Encore\Admin\Facades\Admin;
//use Encore\Admin\Layout\Column;
//use Encore\Admin\Layout\Row;
//use Encore\Admin\Tree;
//use Encore\Admin\Widgets\Box;
//use Illuminate\Support\Facades\DB;
use App\Articlecat; use App\Articlecat;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form; use Encore\Admin\Form;
use Encore\Admin\Grid; use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content; use Encore\Admin\Layout\Content;
use Encore\Admin\Show; use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Layout\Row;
use Encore\Admin\Tree;
use Encore\Admin\Widgets\Box;
use Illuminate\Support\Facades\DB;
class ArticlecatController extends Controller class ArticlecatController extends Controller
{ {
use HasResourceActions; use ModelForm;
/** protected $header = '文章管理';
* Index interface.
* public function index()
* @param Content $content
* @return Content
*/
public function index(Content $content)
{ {
return $content return Admin::content(function (Content $content) {
->header('分类管理') $content->header($this->header);
->description('列表') $content->description('分类列表');
->body($this->grid()); $content->row(function (Row $row) {
$row->column(6, $this->treeView()->render());
$row->column(6, function (Column $column) {
$form = new \Encore\Admin\Widgets\Form();
$form->action(admin_base_path('/articlecat'));
$form->text('name','类型名称');
$form->number('sort_order','排序序号');
$form->select('pid','父类名称')->options(Articlecat::selectOptions());
$form->hidden('_token')->default(csrf_token());
$column->append((new Box(trans('admin.new'), $form))->style('success'));
});
});
});
} }
/** protected function treeView()
* Show interface.
*
* @param mixed $id
* @param Content $content
* @return Content
*/
public function show($id, Content $content)
{ {
return $content return Articlecat::tree(function (Tree $tree) {
->header('详情') $tree->disableCreate();
->description('分类') return $tree;
->body($this->detail($id)); });
} }
/** /**
* Edit interface. * Edit interface.
* *
* @param mixed $id * @param $id
* @param Content $content
* @return Content * @return Content
*/ */
public function edit($id, Content $content) public function edit($id)
{ {
return $content return Admin::content(function (Content $content) use ($id) {
->header('编辑') $content->header($this->header);
->description('分类') $content->description('编辑类型');
->body($this->form()->edit($id)); $content->body($this->form()->edit($id));
});
} }
/** /**
* Create interface. * Create interface.
* *
* @param Content $content
* @return Content * @return Content
*/ */
public function create(Content $content) public function create()
{ {
return $content return Admin::content(function (Content $content) {
->header('添加') $content->header($this->header);
->description('分类') $content->description('添加类型');
->body($this->form()); $content->body($this->form());
});
} }
/** /**
* Make a grid builder. * Make a form builder.
* *
* @return Grid * @return Form
*/ */
protected function grid() protected function form()
{ {
$grid = new Grid(new Articlecat()); return Admin::form(Articlecat::class, function (Form $form) {
$grid->id('ID')->sortable(); $form->display('id', 'ID');
$grid->pid('父id'); $form->text('name','类型名称');
$grid->name('分类名'); $form->number('sort_order','排序序号');
$grid->sort_order('排序'); $form->select('pid','父类名称')->options(Articlecat::selectOptions());
return $grid; });
} }
/** public function getArticlecatsOptions()
* Make a show builder.
*
* @param mixed $id
* @return Show
*/
protected function detail($id)
{ {
$show = new Show(Articlecat::findOrFail($id)); return DB::table('articlecats')->select('id','name as text')->get();
return $show;
} }
/** /**
* Make a form builder. * Index interface.
* *
* @return Form * @param Content $content
* @return Content
*/ */
protected function form() // public function index(Content $content)
{ // {
$form = new Form(new Articlecat); // return $content
$form->number('pid','父id'); // ->header('分类管理')
$form->text('name','分类名'); // ->description('列表')
$form->number('sort_order','排序'); // ->body($this->grid());
return $form; // }
} //
// /**
// * Show interface.
// *
// * @param mixed $id
// * @param Content $content
// * @return Content
// */
// public function show($id, Content $content)
// {
// return $content
// ->header('详情')
// ->description('分类')
// ->body($this->detail($id));
// }
//
// /**
// * Edit interface.
// *
// * @param mixed $id
// * @param Content $content
// * @return Content
// */
// public function edit($id, Content $content)
// {
// return $content
// ->header('编辑')
// ->description('分类')
// ->body($this->form()->edit($id));
// }
//
// /**
// * Create interface.
// *
// * @param Content $content
// * @return Content
// */
// public function create(Content $content)
// {
// return $content
// ->header('添加')
// ->description('分类')
// ->body($this->form());
// }
//
// /**
// * Make a grid builder.
// *
// * @return Grid
// */
// protected function grid()
// {
// $grid = new Grid(new Articlecat());
// $grid->id('ID')->sortable();
// $grid->pid('父id');
// $grid->name('分类名');
// $grid->sort_order('排序');
// return $grid;
// }
//
// /**
// * Make a show builder.
// *
// * @param mixed $id
// * @return Show
// */
// protected function detail($id)
// {
// $show = new Show(Articlecat::findOrFail($id));
//
//
//
// return $show;
// }
//
// /**
// * Make a form builder.
// *
// * @return Form
// */
// protected function form()
// {
// $form = new Form(new Articlecat);
// $form->number('pid','父id');
// $form->text('name','分类名');
// $form->number('sort_order','排序');
// return $form;
// }
} }
<?php
namespace App\Http\Controllers\Admin;
use App\Article;
use App\Articlecat;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
class HomeController extends Controller
{
use HasResourceActions;
/**
* Index interface.
*
* @param Content $content
* @return Content
*/
public function index(Content $content)
{
return $content
->body($this->grid());
}
/**
* Show interface.
*
* @param mixed $id
* @param Content $content
* @return Content
*/
public function show($id, Content $content)
{
return $content
->header('Detail')
->description('description')
->body($this->detail($id));
}
/**
* Edit interface.
*
* @param mixed $id
* @param Content $content
* @return Content
*/
public function edit($id, Content $content)
{
return $content
->header('Edit')
->description('description')
->body($this->form()->edit($id));
}
/**
* Create interface.
*
* @param Content $content
* @return Content
*/
public function create(Content $content)
{
return $content
->header('添加')
->description('文章')
->body($this->form());
}
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
$grid = new Grid(new Article());
$grid->id('ID')->sortable();
$grid->title('标题');
$grid->column('articlecats.name','分类');
$grid->message('描述');
$grid->is_show('是否显示');
$grid->click_num('点击量');
$grid->sort_order('排序');
return $grid;
}
/**
* Make a show builder.
*
* @param mixed $id
* @return Show
*/
protected function detail($id)
{
$show = new Show(Article::findOrFail($id));
return $show;
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
$form = new Form(new Article);
$form->text('title', '标题')->rules('required');
$form->select('articlecats_id','分类')->options(Articlecat::getSelectOptions());
$form->text('message', '描述');
//$form->text('content', '内容');
//$form->ueditor('content', '内容')->rules('required');;
//$form->editor('content','内容');
$form->switch('is_show', '是否显示');
$form->number('sort_order', '排序');
return $form;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment