firstpush
This commit is contained in:
81
app/Admin/Controllers/Advert/IndexController.php
Normal file
81
app/Admin/Controllers/Advert/IndexController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Advert;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Category;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
class IndexController extends AdminController
|
||||
{
|
||||
|
||||
protected $title = '图片位管理';
|
||||
|
||||
protected function grid()
|
||||
{
|
||||
$grid = new Grid(new Advert);
|
||||
|
||||
$grid->actions(function ($actions) {
|
||||
$actions->disableView();
|
||||
});
|
||||
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->like('title', '图片名称');
|
||||
$filter->like('category.id', '分类名称')->select(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1)->where('type', Category::TYPE_ADVERT);
|
||||
}, '所有分类'));
|
||||
});
|
||||
$filter->disableIdFilter();
|
||||
});
|
||||
|
||||
$grid->column('id');
|
||||
$grid->column('cover', '图片')->image('', 60, 60);
|
||||
$grid->column('category.title', '分类名称');
|
||||
$grid->column('title', '图片名称');
|
||||
$grid->column('url', '地址');
|
||||
$grid->column('sort', '排序');
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$form = new Form(new Advert);
|
||||
|
||||
$form->text('title', '图片名称')->required();
|
||||
$form->select('category_id', '所属分类')
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1)->where('type', Category::TYPE_ADVERT);
|
||||
}, '选择分类'))
|
||||
->rules('required|min:1', [
|
||||
'required' => '必须选择所属分类',
|
||||
'min' => '必须选择所属分类',
|
||||
]);
|
||||
$form->image('cover', '封面图片')
|
||||
->rules(function ($form) {
|
||||
if ($form->model()->cover != []) {
|
||||
return 'nullable|image';
|
||||
} else {
|
||||
return 'required';
|
||||
}
|
||||
})
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->text('url', '链接地址');
|
||||
$form->number('sort', '排序')
|
||||
->default(1)
|
||||
->required()
|
||||
->help('数字越大越靠前');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
65
app/Admin/Controllers/Article/ArticleController.php
Normal file
65
app/Admin/Controllers/Article/ArticleController.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Article;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
class ArticleController extends AdminController
|
||||
{
|
||||
protected $title = '内容管理';
|
||||
|
||||
public function grid()
|
||||
{
|
||||
$grid = new Grid(new Article);
|
||||
$grid->model()->orderBy('id', 'desc');
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->like('title', '文章标题');
|
||||
$filter->like('category.id', '所属分类')->select(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1)->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
|
||||
}, '所有分类'));
|
||||
});
|
||||
|
||||
$filter->disableIdFilter();
|
||||
});
|
||||
|
||||
$grid->column('id', '#ID#');
|
||||
$grid->column('cover', '封面图片')->image('', 100);
|
||||
$grid->column('category.title', '所属分类');
|
||||
$grid->column('title', '文章标题');
|
||||
$grid->column('sort', '序号');
|
||||
$grid->column('created_at', '创建时间');
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
$form = new Form(new Article);
|
||||
|
||||
$form->text('title', '文章标题')->rules('min:2');
|
||||
$form->select('category_id', '所属分类')
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
|
||||
}, '选择分类'))
|
||||
->rules('required|min:1', [
|
||||
'required' => '必须选择所属分类',
|
||||
'min' => '必须选择所属分类',
|
||||
]);
|
||||
$form->text('keywords', '关键词')->rules('nullable');
|
||||
$form->textarea('description', '内容简介')->rules('max:350');
|
||||
$form->image('cover', '封面')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->ueditor('content', '文章内容')->rules('required', ['required' => '详情不能为空']);
|
||||
$form->number('sort', '序号')->default(0)->rules('required', ['required' => '序号必须填写'])->help('倒序优先');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
54
app/Admin/Controllers/Article/PictureController.php
Normal file
54
app/Admin/Controllers/Article/PictureController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Article;
|
||||
|
||||
use App\Models\ArticlePicture;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
class PictureController extends AdminController
|
||||
{
|
||||
protected $title = '随手拍';
|
||||
|
||||
public function grid()
|
||||
{
|
||||
$grid = new Grid(new ArticlePicture);
|
||||
$grid->model()->orderBy('id', 'desc');
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->like('title', '文章标题');
|
||||
});
|
||||
|
||||
$filter->disableIdFilter();
|
||||
});
|
||||
|
||||
$grid->column('id', '#ID#');
|
||||
$grid->column('cover')->display(function () {
|
||||
return $this->one_picture_path;
|
||||
})->image('', 100);
|
||||
$grid->column('category.title', '所属分类');
|
||||
$grid->column('title', '文章标题');
|
||||
$grid->column('sort', '序号');
|
||||
$grid->column('created_at', '创建时间');
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
$form = new Form(new ArticlePicture);
|
||||
|
||||
$form->text('title', '文章标题')->rules('min:2');
|
||||
$form->hidden('category_id')->value(6);
|
||||
$form->multipleImage('pictures', '封面')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
|
||||
$form->number('sort', '序号')->default(0)->rules('required', ['required' => '序号必须填写'])->help('倒序优先');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
10
app/Admin/Controllers/AuthController.php
Normal file
10
app/Admin/Controllers/AuthController.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Encore\Admin\Controllers\AuthController as BaseAuthController;
|
||||
|
||||
class AuthController extends BaseAuthController
|
||||
{
|
||||
|
||||
}
|
||||
149
app/Admin/Controllers/Category/IndexController.php
Normal file
149
app/Admin/Controllers/Category/IndexController.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Category;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Layout\Column;
|
||||
use Encore\Admin\Layout\Row;
|
||||
use Encore\Admin\Tree;
|
||||
use Encore\Admin\Widgets\Box;
|
||||
use Encore\Admin\Widgets\Form as WidgetsForm;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
class IndexController extends AdminController
|
||||
{
|
||||
|
||||
protected $title = '分类管理';
|
||||
|
||||
/**
|
||||
* Index interface.
|
||||
* @return \Closure
|
||||
*/
|
||||
public function grid()
|
||||
{
|
||||
return function (Row $row) {
|
||||
$row->column(6, $this->treeView());
|
||||
|
||||
$row->column(6, function (Column $column) {
|
||||
$form = new WidgetsForm();
|
||||
|
||||
$form->select('parent_id', '上级分类')
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1);
|
||||
}, '一级分类'))
|
||||
;
|
||||
$form->text('title', '分类名称')->rules('required');
|
||||
$form->select('type', '分类类型')
|
||||
->options(Category::TYPES)
|
||||
->when('show', function (WidgetsForm $form) {
|
||||
$form->select('article_id', '关联文章')
|
||||
->options(function ($option, $info) {
|
||||
return Article::whereHas('category', function ($q) {
|
||||
$q->where('type', 'show');
|
||||
})->pluck('title', 'id');
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
})
|
||||
->required();
|
||||
$form->textarea('description', '分类简介')
|
||||
->rules('nullable');
|
||||
$form->text('keywords', '关键词')->rules('nullable');
|
||||
|
||||
$form->image('cover', 'Logo')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->number('order', '排序')->default(0);
|
||||
$form->switch('top_show', '顶部导航显示')->states()->default(1);
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
$form->action(admin_url('categories'));
|
||||
|
||||
$column->append((new Box('新增分类', $form))->style('success'));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Tree
|
||||
*/
|
||||
protected function treeView()
|
||||
{
|
||||
return Category::tree(function (Tree $tree) {
|
||||
$tree->disableCreate();
|
||||
|
||||
$tree->branch(function ($branch) {
|
||||
if ($branch['status'] == 1) {
|
||||
$payload = "<i class='fa fa-eye text-primary'></i> ";
|
||||
} else {
|
||||
$payload = "<i class='fa fa-eye text-gray'></i> ";
|
||||
}
|
||||
$payload .= " [ID:{$branch['id']}] - ";
|
||||
$payload .= " <strong>{$branch['title']}</strong> ";
|
||||
$payload .= " <small>{$branch['type']}</small> ";
|
||||
$payload .= " <small style='color:#999'>{$branch['description']}</small>";
|
||||
|
||||
return $payload;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$form = new Form(new Category);
|
||||
|
||||
$form->select('parent_id', '上级分类')->options(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1);
|
||||
}, '一级分类'));
|
||||
$form->text('title', '分类名称')->rules('required');
|
||||
$form->select('type', '分类类型')
|
||||
->options(Category::TYPES)
|
||||
->when('show', function (Form $form) {
|
||||
$form->select('article_id', '关联文章')
|
||||
->options(function ($option, $info) {
|
||||
return Article::whereHas('category', function ($q) {
|
||||
$q->where('type', 'show');
|
||||
})->pluck('title', 'id');
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
})
|
||||
->required();
|
||||
$form->textarea('description', '分类简介')->rows(4)->rules('nullable');
|
||||
$form->text('keywords', '关键词')->rules('nullable');
|
||||
$form->image('cover', 'Logo')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->number('order', '排序')->default(0)->help('正序优先');
|
||||
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
$form->switch('top_show', '顶部导航显示')->states();
|
||||
|
||||
$form->saving(function (Form $form) {
|
||||
|
||||
if (request()->has('title')) {
|
||||
if (request()->type == Category::TYPE_SHOW && empty(request()->article_id)) {
|
||||
$error = new MessageBag([
|
||||
'title' => '错误',
|
||||
'message' => '文章类型是文章详情的时候需要选择关联文章',
|
||||
]);
|
||||
|
||||
return back()->withInput()->with(compact('error'));
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return $this->form()->destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
67
app/Admin/Controllers/ExampleController.php
Normal file
67
app/Admin/Controllers/ExampleController.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
use Encore\Admin\Show;
|
||||
|
||||
class ExampleController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Title for current resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = 'Example controller';
|
||||
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
$grid = new Grid(new ExampleModel);
|
||||
|
||||
$grid->column('id', __('ID'))->sortable();
|
||||
$grid->column('created_at', __('Created at'));
|
||||
$grid->column('updated_at', __('Updated at'));
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
$show = new Show(ExampleModel::findOrFail($id));
|
||||
|
||||
$show->field('id', __('ID'));
|
||||
$show->field('created_at', __('Created at'));
|
||||
$show->field('updated_at', __('Updated at'));
|
||||
|
||||
return $show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$form = new Form(new ExampleModel);
|
||||
|
||||
$form->display('id', __('ID'));
|
||||
$form->display('created_at', __('Created At'));
|
||||
$form->display('updated_at', __('Updated At'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
34
app/Admin/Controllers/HomeController.php
Normal file
34
app/Admin/Controllers/HomeController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Encore\Admin\Controllers\Dashboard;
|
||||
use Encore\Admin\Layout\Column;
|
||||
use Encore\Admin\Layout\Content;
|
||||
use Encore\Admin\Layout\Row;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function index(Content $content)
|
||||
{
|
||||
return $content
|
||||
->title('Dashboard')
|
||||
->description('Description...')
|
||||
->row(Dashboard::title())
|
||||
->row(function (Row $row) {
|
||||
|
||||
$row->column(4, function (Column $column) {
|
||||
$column->append(Dashboard::environment());
|
||||
});
|
||||
|
||||
$row->column(4, function (Column $column) {
|
||||
$column->append(Dashboard::extensions());
|
||||
});
|
||||
|
||||
$row->column(4, function (Column $column) {
|
||||
$column->append(Dashboard::dependencies());
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
37
app/Admin/Controllers/Link/IndexController.php
Normal file
37
app/Admin/Controllers/Link/IndexController.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Link;
|
||||
|
||||
use App\Models\Link;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
class IndexController extends AdminController
|
||||
{
|
||||
|
||||
protected $title = '友情链接';
|
||||
|
||||
public function grid()
|
||||
{
|
||||
$grid = new Grid(new Link);
|
||||
|
||||
$grid->column('id', '#ID#');
|
||||
$grid->column('title', '标题');
|
||||
$grid->column('url', '地址');
|
||||
$grid->column('created_at', '创建时间');
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
$form = new Form(new Link);
|
||||
|
||||
$form->text('title', '标题')->required();
|
||||
$form->text('url', '地址')->required();
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
12
app/Admin/Routes/advert.php
Normal file
12
app/Admin/Routes/advert.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
|
||||
Route::group([
|
||||
'prefix' => config('admin.route.prefix'),
|
||||
'namespace' => config('admin.route.namespace') . '\\Advert',
|
||||
'middleware' => config('admin.route.middleware'),
|
||||
], function (Router $router) {
|
||||
$router->resource('adverts', 'IndexController');
|
||||
|
||||
});
|
||||
12
app/Admin/Routes/article.php
Normal file
12
app/Admin/Routes/article.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
|
||||
Route::group([
|
||||
'prefix' => config('admin.route.prefix'),
|
||||
'namespace' => config('admin.route.namespace') . '\\Article',
|
||||
'middleware' => config('admin.route.middleware'),
|
||||
], function (Router $router) {
|
||||
$router->resource('articles', 'ArticleController');
|
||||
$router->resource('pictures', 'PictureController');
|
||||
});
|
||||
12
app/Admin/Routes/category.php
Normal file
12
app/Admin/Routes/category.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
|
||||
Route::group([
|
||||
'prefix' => config('admin.route.prefix'),
|
||||
'namespace' => config('admin.route.namespace') . '\\Category',
|
||||
'middleware' => config('admin.route.middleware'),
|
||||
], function (Router $router) {
|
||||
$router->resource('categories', 'IndexController');
|
||||
|
||||
});
|
||||
12
app/Admin/Routes/link.php
Normal file
12
app/Admin/Routes/link.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
|
||||
Route::group([
|
||||
'prefix' => config('admin.route.prefix'),
|
||||
'namespace' => config('admin.route.namespace') . '\\Link',
|
||||
'middleware' => config('admin.route.middleware'),
|
||||
], function (Router $router) {
|
||||
$router->resource('links', 'IndexController');
|
||||
|
||||
});
|
||||
29
app/Admin/bootstrap.php
Normal file
29
app/Admin/bootstrap.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
Form::forget(['map', 'editor']);
|
||||
|
||||
Form::init(function (Form $form) {
|
||||
$form->disableEditingCheck();
|
||||
$form->disableCreatingCheck();
|
||||
$form->disableViewCheck();
|
||||
$form->tools(function (Form\Tools $tools) {
|
||||
$tools->disableDelete();
|
||||
$tools->disableView();
|
||||
$tools->disableList();
|
||||
});
|
||||
});
|
||||
|
||||
Grid::init(function (Grid $grid) {
|
||||
$grid->disableExport();
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
$actions->disableView();
|
||||
});
|
||||
$grid->disableBatchActions();
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->disableIdFilter();
|
||||
});
|
||||
// $grid->expandFilter();
|
||||
});
|
||||
21
app/Admin/routes.php
Normal file
21
app/Admin/routes.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
|
||||
Admin::routes();
|
||||
|
||||
Route::group([
|
||||
'prefix' => config('admin.route.prefix'),
|
||||
'namespace' => config('admin.route.namespace'),
|
||||
'middleware' => config('admin.route.middleware'),
|
||||
'as' => config('admin.route.prefix') . '.',
|
||||
], function (Router $router) {
|
||||
|
||||
$router->get('/', 'HomeController@index')->name('home');
|
||||
|
||||
});
|
||||
|
||||
require __DIR__ . '/Routes/article.php';
|
||||
require __DIR__ . '/Routes/category.php';
|
||||
require __DIR__ . '/Routes/link.php';
|
||||
require __DIR__ . '/Routes/advert.php';
|
||||
42
app/Console/Kernel.php
Normal file
42
app/Console/Kernel.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')
|
||||
// ->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
57
app/Exceptions/Handler.php
Normal file
57
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of the exception types that are not reported.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed for validation exceptions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* @param \Exception $exception
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function report(Throwable $exception)
|
||||
{
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Exception $exception
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function render($request, Throwable $exception)
|
||||
{
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
}
|
||||
45
app/Http/Controllers/ArticleController.php
Normal file
45
app/Http/Controllers/ArticleController.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\ArticlePicture;
|
||||
use App\Models\Category;
|
||||
|
||||
class ArticleController extends Controller
|
||||
{
|
||||
public function index(Category $category)
|
||||
{
|
||||
$articles = Article::where('category_id', $category->id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate(5);
|
||||
|
||||
return view('articles.index', compact('articles', 'category'));
|
||||
}
|
||||
|
||||
public function show(Article $article)
|
||||
{
|
||||
$category = $article->category;
|
||||
return view('articles.show', compact('article', 'category'));
|
||||
}
|
||||
|
||||
public function category(Category $category)
|
||||
{
|
||||
$article = Article::where('category_id', $category->id)->first();
|
||||
|
||||
return view('articles.show', compact('article'));
|
||||
}
|
||||
|
||||
public function picture(Category $category)
|
||||
{
|
||||
$articles = ArticlePicture::where('category_id', $category->id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate(12);
|
||||
return view('articles.picture', compact('articles', 'category'));
|
||||
}
|
||||
|
||||
public function picshow(ArticlePicture $article)
|
||||
{
|
||||
return view('articles.picshow', compact('article'));
|
||||
}
|
||||
}
|
||||
40
app/Http/Controllers/Auth/ConfirmPasswordController.php
Normal file
40
app/Http/Controllers/Auth/ConfirmPasswordController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\ConfirmsPasswords;
|
||||
|
||||
class ConfirmPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Confirm Password Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password confirmations and
|
||||
| uses a simple trait to include the behavior. You're free to explore
|
||||
| this trait and override any functions that require customization.
|
||||
|
|
||||
*/
|
||||
|
||||
use ConfirmsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users when the intended url fails.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
}
|
||||
22
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
22
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
}
|
||||
40
app/Http/Controllers/Auth/LoginController.php
Normal file
40
app/Http/Controllers/Auth/LoginController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest')->except('logout');
|
||||
}
|
||||
}
|
||||
73
app/Http/Controllers/Auth/RegisterController.php
Normal file
73
app/Http/Controllers/Auth/RegisterController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use App\User;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users as well as their
|
||||
| validation and creation. By default this controller uses a trait to
|
||||
| provide this functionality without requiring any additional code.
|
||||
|
|
||||
*/
|
||||
|
||||
use RegistersUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \App\User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
return User::create([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
30
app/Http/Controllers/Auth/ResetPasswordController.php
Normal file
30
app/Http/Controllers/Auth/ResetPasswordController.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users after resetting their password.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
}
|
||||
42
app/Http/Controllers/Auth/VerificationController.php
Normal file
42
app/Http/Controllers/Auth/VerificationController.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\VerifiesEmails;
|
||||
|
||||
class VerificationController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Email Verification Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling email verification for any
|
||||
| user that recently registered with the application. Emails may also
|
||||
| be re-sent if the user didn't receive the original email message.
|
||||
|
|
||||
*/
|
||||
|
||||
use VerifiesEmails;
|
||||
|
||||
/**
|
||||
* Where to redirect users after verification.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('signed')->only('verify');
|
||||
$this->middleware('throttle:6,1')->only('verify', 'resend');
|
||||
}
|
||||
}
|
||||
21
app/Http/Controllers/CategoryController.php
Normal file
21
app/Http/Controllers/CategoryController.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Category;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 分类下的文章
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/1 9:19
|
||||
* @param \App\Models\Category $category
|
||||
*/
|
||||
public function articles(Category $category)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
36
app/Http/Controllers/Controller.php
Normal file
36
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
use App\Models\Link;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//顶部分类
|
||||
$categorys = Category::where('parent_id', 0)
|
||||
->where('status', 1)
|
||||
->where('top_show', 1)
|
||||
->select('id', 'title', 'type', 'order', 'article_id')
|
||||
->orderBy('order', 'asc')
|
||||
->get();
|
||||
|
||||
$links = Link::get();
|
||||
|
||||
View::share('all_categorys', $categorys);
|
||||
View::share('links', $links);
|
||||
}
|
||||
|
||||
}
|
||||
37
app/Http/Controllers/IndexController.php
Normal file
37
app/Http/Controllers/IndexController.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Article;
|
||||
use App\Models\ArticlePicture;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 首页
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/1 9:11
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$ssp = ArticlePicture::orderBy('sort', 'desc')->take(3)->get(); //随手拍
|
||||
$all_articles = Article::orderBy('sort', 'desc')
|
||||
->whereNotIn('category_id', [20, 21, 22])
|
||||
->take(7)
|
||||
->get(); //最新资讯
|
||||
$danwei = Article::where('category_id', 15)->latest()->first(); //单位概况
|
||||
$ysbj = Article::where('category_id', 12)->latest()->take(3)->get(); //养生保健
|
||||
$dcyfx = Article::where('category_id', 10)->latest()->take(7)->get(); //调研与分析
|
||||
$yyjcyj = Article::where('category_id', 9)->latest()->take(7)->get(); //应用基础研究
|
||||
$jsyt = Article::where('category_id', 11)->latest()->take(7)->get(); //技术研讨
|
||||
$kyyyy = Article::where('category_id', 12)->latest()->take(7)->get(); //科研与应用
|
||||
$qkys = Article::where('category_id', 9)->latest()->take(7)->get(); //全科医学
|
||||
$center_advert = Advert::where('category_id', 18)->first();
|
||||
$qikan_advert = Advert::where('category_id', 19)->take(4)->orderBy('sort', 'desc')->get();
|
||||
|
||||
return view('index.index', compact('ssp', 'all_articles', 'danwei', 'ysbj', 'dcyfx', 'yyjcyj', 'jsyt', 'kyyyy', 'qkys', 'center_advert', 'qikan_advert'));
|
||||
}
|
||||
|
||||
}
|
||||
161
app/Http/Controllers/TestController.php
Normal file
161
app/Http/Controllers/TestController.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
use App\Models\DedeArchive;
|
||||
use App\Models\DedeArctype;
|
||||
use App\Traits\Tree;
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
use Tree;
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function setCateArticle()
|
||||
{
|
||||
$article = [];
|
||||
$lists = Category::where('content', '<>', '')->where('type', 'article')->get();
|
||||
if ($lists->isEmpty()) {
|
||||
dd('没有数据');
|
||||
}
|
||||
foreach ($lists as $key => $cate) {
|
||||
if ($cate->content != ' ') {
|
||||
$data = [
|
||||
'oldid' => 0,
|
||||
'title' => $cate->title,
|
||||
'category_id' => $cate->id,
|
||||
'writer' => 'admin',
|
||||
'source' => '未知',
|
||||
'keywords' => '',
|
||||
'status' => 1,
|
||||
'description' => $cate->description,
|
||||
'content' => $cate->content,
|
||||
];
|
||||
|
||||
$info = Article::create($data);
|
||||
$cate->article_id = $info->id;
|
||||
$cate->type = Category::TYPE_SHOW;
|
||||
$cate->save();
|
||||
$article[] = $info->id;
|
||||
}
|
||||
|
||||
}
|
||||
dump(count($article));
|
||||
}
|
||||
|
||||
public function checkArticle()
|
||||
{
|
||||
$articleids = Article::where('oldid', '>', 0)->pluck('oldid');
|
||||
$oldids = DedeArchive::pluck('id');
|
||||
$diffids = array_diff($oldids->toArray(), $articleids->toArray());
|
||||
dump(count($articleids));
|
||||
dump(count($oldids));
|
||||
dump($diffids);
|
||||
die();
|
||||
$map = [
|
||||
'id' => ['in', $diffids],
|
||||
];
|
||||
$list = DedeArchive::whereIn('id', $diffids)->get();
|
||||
foreach ($list as $key => $article) {
|
||||
$data = [
|
||||
'oldid' => $article->id,
|
||||
'title' => $article->title,
|
||||
'category_id' => $category->id ?? '0',
|
||||
'writer' => $article->writer,
|
||||
'cover' => $article->litpic,
|
||||
'source' => $article->source,
|
||||
'keywords' => $article->keywords,
|
||||
'description' => $article->description,
|
||||
'status' => 1,
|
||||
'content' => $article->info->body ?? '',
|
||||
'created_at' => date('Y-m-d H:i:s', $article->pubdate),
|
||||
];
|
||||
Article::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
//导入文章
|
||||
public function set_article()
|
||||
{
|
||||
$articles = Article::get();
|
||||
if ($articles->count() > 4) {
|
||||
dd('已经导入过数据');
|
||||
}
|
||||
$categorys = Category::get();
|
||||
$error = $success = [];
|
||||
DedeArchive::whereNotNull('litpic')->chunk(200, function ($articles) use ($categorys) {
|
||||
|
||||
foreach ($articles as $article) {
|
||||
|
||||
$category = $categorys->where('oldid', $article->typeid)->first();
|
||||
$id = $category->id ?? 0;
|
||||
if (in_array($id, [9, 10, 11, 12])) {
|
||||
$data = [
|
||||
'oldid' => $article->id,
|
||||
'title' => $article->title,
|
||||
'category_id' => $category->id ?? '0',
|
||||
'writer' => $article->writer,
|
||||
'source' => $article->source,
|
||||
'cover' => $article->litpic,
|
||||
'keywords' => $article->keywords,
|
||||
'description' => $article->description,
|
||||
'status' => 1,
|
||||
'content' => $article->info->body ?? '',
|
||||
'created_at' => date('Y-m-d H:i:s', $article->pubdate),
|
||||
];
|
||||
|
||||
$res = Article::create($data);
|
||||
if (!$res) {
|
||||
$error[] = $article->id;
|
||||
} else {
|
||||
$success[] = $article->id;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
dump($error);
|
||||
dump($success);
|
||||
}
|
||||
|
||||
//导入分类
|
||||
public function set_category()
|
||||
{
|
||||
$categorys = Category::get();
|
||||
if ($categorys->count()) {
|
||||
dd('已经导入过数据');
|
||||
}
|
||||
$lists = DedeArctype::where('ishidden', 0)->select('id', 'reid as parent_id', 'typename as title', 'content')->get();
|
||||
$list = Tree::list2tree($lists->toArray(), 'id', 'parent_id', 'children', 0);
|
||||
|
||||
foreach ($list as $key => $value) {
|
||||
$info = Category::create($this->getData($value));
|
||||
if (isset($value['children']) && count($value['children']) > 0) {
|
||||
foreach ($value['children'] as $key => $children) {
|
||||
$info->children()->create($this->getData($children));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//格式化分类数据
|
||||
public function getData($category)
|
||||
{
|
||||
$data = [
|
||||
'oldid' => $category['id'],
|
||||
'parent_id' => $category['parent_id'],
|
||||
'title' => $category['title'],
|
||||
'content' => $category['content'],
|
||||
'status' => 1,
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
82
app/Http/Kernel.php
Normal file
82
app/Http/Kernel.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\App\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'throttle:60,1',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The priority-sorted list of middleware.
|
||||
*
|
||||
* This forces non-global middleware to always be in the given order.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewarePriority = [
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\Authenticate::class,
|
||||
\Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
\Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\Illuminate\Auth\Middleware\Authorize::class,
|
||||
];
|
||||
}
|
||||
21
app/Http/Middleware/Authenticate.php
Normal file
21
app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
return route('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
17
app/Http/Middleware/CheckForMaintenanceMode.php
Normal file
17
app/Http/Middleware/CheckForMaintenanceMode.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
|
||||
|
||||
class CheckForMaintenanceMode extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
27
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
27
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
18
app/Http/Middleware/TrimStrings.php
Normal file
18
app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
23
app/Http/Middleware/TrustProxies.php
Normal file
23
app/Http/Middleware/TrustProxies.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Fideloper\Proxy\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array|string
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers = Request::HEADER_X_FORWARDED_ALL;
|
||||
}
|
||||
24
app/Http/Middleware/VerifyCsrfToken.php
Normal file
24
app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $addHttpCookie = true;
|
||||
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
15
app/Models/Advert.php
Normal file
15
app/Models/Advert.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasOneCover;
|
||||
use App\Models\Traits\OrderByIdDesc;
|
||||
use App\Scopes\SortScope;
|
||||
|
||||
class Advert extends Model
|
||||
{
|
||||
|
||||
use HasOneCover,
|
||||
BelongsToCategory;
|
||||
}
|
||||
11
app/Models/Article.php
Normal file
11
app/Models/Article.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasOneCover;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
use HasOneCover, BelongsToCategory;
|
||||
}
|
||||
33
app/Models/ArticlePicture.php
Normal file
33
app/Models/ArticlePicture.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ArticlePicture extends Model
|
||||
{
|
||||
use BelongsToCategory;
|
||||
|
||||
public function setPicturesAttribute($pictures)
|
||||
{
|
||||
if (is_array($pictures)) {
|
||||
$this->attributes['pictures'] = json_encode($pictures);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPicturesAttribute($pictures)
|
||||
{
|
||||
return json_decode($pictures, true);
|
||||
}
|
||||
|
||||
public function getOnePicturePathAttribute(): string
|
||||
{
|
||||
$cover = $this->pictures;
|
||||
if (empty($cover)) {
|
||||
return '';
|
||||
} else {
|
||||
return Storage::disk('public')->url($cover[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
57
app/Models/Category.php
Normal file
57
app/Models/Category.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Encore\Admin\Traits\AdminBuilder;
|
||||
use Encore\Admin\Traits\ModelTree;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use AdminBuilder, ModelTree;
|
||||
|
||||
public const TYPES = [
|
||||
'article' => '文章列表',
|
||||
'show' => '文章详情',
|
||||
'advert' => '广告',
|
||||
'picture' => '图册',
|
||||
];
|
||||
|
||||
public const TYPE_SHOW = 'show';
|
||||
public const TYPE_ARTICLE = 'article';
|
||||
public const TYPE_ADVERT = 'advert';
|
||||
public const TYPE_PICTURE = 'picture';
|
||||
|
||||
/**
|
||||
* 关联的数据
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function relations()
|
||||
{
|
||||
switch ($this->type) {
|
||||
case self::TYPE_SHOW:
|
||||
return $this->hasOne(Article::class,'id','article_id');
|
||||
break;
|
||||
case self::TYPE_ARTICLE:
|
||||
return $this->hasMany(Article::class);
|
||||
break;
|
||||
case self::TYPE_ADVERT:
|
||||
return $this->hasMany(Advert::class);
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(__CLASS__)->withDefault(['name' => '顶级分类']);
|
||||
}
|
||||
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(__CLASS__, 'parent_id');
|
||||
}
|
||||
|
||||
}
|
||||
7
app/Models/DedeAddonarticle.php
Normal file
7
app/Models/DedeAddonarticle.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class DedeAddonarticle extends Model
|
||||
{
|
||||
}
|
||||
11
app/Models/DedeArchive.php
Normal file
11
app/Models/DedeArchive.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class DedeArchive extends Model
|
||||
{
|
||||
public function info()
|
||||
{
|
||||
return $this->hasOne(DedeAddonarticle::class, 'aid');
|
||||
}
|
||||
}
|
||||
11
app/Models/DedeArctype.php
Normal file
11
app/Models/DedeArctype.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Encore\Admin\Traits\AdminBuilder;
|
||||
use Encore\Admin\Traits\ModelTree;
|
||||
|
||||
class DedeArctype extends Model
|
||||
{
|
||||
use AdminBuilder, ModelTree;
|
||||
}
|
||||
8
app/Models/Link.php
Normal file
8
app/Models/Link.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Link extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
22
app/Models/Model.php
Normal file
22
app/Models/Model.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
|
||||
class Model extends Eloquent
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 为数组 / JSON 序列化准备日期。
|
||||
*
|
||||
* @param \DateTimeInterface $date
|
||||
* @return string
|
||||
*/
|
||||
protected function serializeDate(DateTimeInterface $date)
|
||||
{
|
||||
return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
}
|
||||
21
app/Models/Traits/BelongsToCategory.php
Normal file
21
app/Models/Traits/BelongsToCategory.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Traits;
|
||||
|
||||
use App\Models\Category;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
trait BelongsToCategory
|
||||
{
|
||||
|
||||
/**
|
||||
* 关联分类表
|
||||
* @author 玄尘 2020-03-05
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class)->withDefault();
|
||||
}
|
||||
|
||||
}
|
||||
24
app/Models/Traits/HasOneCover.php
Normal file
24
app/Models/Traits/HasOneCover.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
trait HasOneCover
|
||||
{
|
||||
|
||||
/**
|
||||
* 拼接图片全地址
|
||||
* @author 玄尘 2020-03-05
|
||||
* @return string
|
||||
*/
|
||||
public function getCoverPathAttribute(): ?string
|
||||
{
|
||||
if ($this->cover) {
|
||||
return Storage::url($this->cover);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
36
app/Providers/AppServiceProvider.php
Normal file
36
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Encore\Admin\Config\Config;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
//add fixed sql
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
Schema::defaultStringLength(191); //add fixed sql
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$table = config('admin.extensions.config.table', 'admin_config');
|
||||
if (Schema::hasTable($table)) {
|
||||
Config::load();
|
||||
}
|
||||
Paginator::defaultView('pagination::customize');
|
||||
}
|
||||
}
|
||||
30
app/Providers/AuthServiceProvider.php
Normal file
30
app/Providers/AuthServiceProvider.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The policy mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $policies = [
|
||||
// 'App\Model' => 'App\Policies\ModelPolicy',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies();
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
21
app/Providers/BroadcastServiceProvider.php
Normal file
21
app/Providers/BroadcastServiceProvider.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
||||
34
app/Providers/EventServiceProvider.php
Normal file
34
app/Providers/EventServiceProvider.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event listener mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
80
app/Providers/RouteServiceProvider.php
Normal file
80
app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* This namespace is applied to your controller routes.
|
||||
*
|
||||
* In addition, it is set as the URL generator's root namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'App\Http\Controllers';
|
||||
|
||||
/**
|
||||
* The path to the "home" route for your application.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/home';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @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(base_path('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(base_path('routes/api.php'));
|
||||
}
|
||||
}
|
||||
90
app/Traits/Tree.php
Normal file
90
app/Traits/Tree.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// | http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace App\Traits;
|
||||
|
||||
/**
|
||||
* 生成多层树状下拉选框的工具
|
||||
*/
|
||||
trait Tree
|
||||
{
|
||||
|
||||
/**
|
||||
* 用于树型数组完成递归格式的全局变量
|
||||
*/
|
||||
private static $formatTree;
|
||||
|
||||
/**
|
||||
* 生成多层树,供下拉选框使用
|
||||
*/
|
||||
public static function toFormatTree($list, $title = 'title', $pk = 'id', $pid = 'pid', $root = 0)
|
||||
{
|
||||
$list = self::list2tree($list, $pk, $pid, '_child', $root);
|
||||
|
||||
self::$formatTree = [];
|
||||
self::_toFormatTree($list, 0, $title);
|
||||
return self::$formatTree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把数据集转换成Tree
|
||||
* @param array $list 要转换的数据集
|
||||
* @param string $pk [description]
|
||||
* @param string $pid [description]
|
||||
* @param string $child [description]
|
||||
* @param integer $root [description]
|
||||
* @return array
|
||||
*/
|
||||
public static function list2tree($list, $pk = 'id', $pid = 'pid', $child = 'children', $root = 0)
|
||||
{
|
||||
$tree = [];
|
||||
if (is_array($list)) {
|
||||
$refer = [];
|
||||
foreach ($list as $key => $data) {
|
||||
$refer[$data[$pk]] = &$list[$key];
|
||||
}
|
||||
foreach ($list as $key => $data) {
|
||||
$parentId = $data[$pid];
|
||||
if ($root == $parentId) {
|
||||
$tree[] = &$list[$key];
|
||||
} else {
|
||||
if (isset($refer[$parentId])) {
|
||||
$parent = &$refer[$parentId];
|
||||
$parent[$child][] = &$list[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将格式数组转换为树
|
||||
* @param array $list
|
||||
* @param integer $level 进行递归时传递用的参数
|
||||
* @author 小陈叔叔 <Jason.Chen[cjango.com]>
|
||||
*/
|
||||
private static function _toFormatTree($list, $level = 0, $title = 'title')
|
||||
{
|
||||
foreach ($list as $key => $val) {
|
||||
$tmp_str = str_repeat(" ", $level * 4);
|
||||
$tmp_str .= "└ ";
|
||||
$val['level'] = $level;
|
||||
$val['title_show'] = $level == 0 ? $val[$title] . " " : $tmp_str . $val[$title];
|
||||
if (!array_key_exists('_child', $val)) {
|
||||
array_push(self::$formatTree, $val);
|
||||
} else {
|
||||
$tmp_ary = $val['_child'];
|
||||
unset($val['_child']);
|
||||
array_push(self::$formatTree, $val);
|
||||
self::_toFormatTree($tmp_ary, $level + 1, $title); //进行下一层递归
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
39
app/User.php
Normal file
39
app/User.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user