Commit 9377f982 authored by jinyonson's avatar jinyonson

文章后台

parent 6a97699f
...@@ -11,5 +11,8 @@ Route::group([ ...@@ -11,5 +11,8 @@ Route::group([
], function (Router $router) { ], function (Router $router) {
$router->get('/', 'HomeController@index'); $router->get('/', 'HomeController@index');
//$router->get('/article', 'ArticleController@index');
$router->resource('/article', 'ArticleController');
$router->resource('/articlecat', 'ArticlecatController');
}); });
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'title', 'articlecats_id', 'message', 'content', 'is_show','click_num','sort_order',
];
public function articlecats()
{
return $this->belongsTo(Articlecat::class);
}
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use DB;
class Articlecat extends Model
{
protected $table = 'articlecats';
protected $fillable = [
'id', 'pid', 'name', 'sort_order',
];
public static function getSelectOptions()
{
$options = DB::table('articlecats')->select('id','name as text')->get();
$selectOption = [];
foreach ($options as $option){
$selectOption[$option->id] = $option->text;
}
return $selectOption;
}
public function articles()
{
return $this->hasOne(articles::class);
}
}
<?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 ArticleController extends Controller
{
use HasResourceActions;
/**
* Index interface.
*
* @param Content $content
* @return Content
*/
public function index(Content $content)
{
return $content
->header('文章管理')
->description('列表')
->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;
}
}
<?php
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;
class ArticlecatController extends Controller
{
use HasResourceActions;
/**
* Index interface.
*
* @param Content $content
* @return Content
*/
public function index(Content $content)
{
return $content
->header('分类管理')
->description('列表')
->body($this->grid());
}
/**
* 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\Api;
use App\Exceptions\BaseException;
use App\Articlecat;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Translation\Tests\Dumper\JsonFileDumperTest;
use Tymon\JWTAuth\JWTAuth;
class ArticlecatController extends Controller
{
}
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
"type": "project", "type": "project",
"require": { "require": {
"php": ">=7.1.3", "php": ">=7.1.3",
"dingo/api": "2.0.0-alpha1",
"encore/laravel-admin": "^1.6", "encore/laravel-admin": "^1.6",
"fideloper/proxy": "~4.0", "fideloper/proxy": "~4.0",
"laravel/framework": "5.6.*", "laravel/framework": "5.6.*",
"laravel/tinker": "~1.0", "laravel/tinker": "~1.0",
"dingo/api": "2.0.0-alpha1", "nwidart/laravel-modules": "^4.0",
"tymon/jwt-auth": "^1.0.0-rc.1" "tymon/jwt-auth": "^1.0.0-rc.1",
"stevenyangecho/laravel-u-editor": "~1.4"
}, },
"require-dev": { "require-dev": {
"filp/whoops": "~2.0", "filp/whoops": "~2.0",
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "3cccb43a9368254c8fe5d621efc61ac2", "content-hash": "da1c3951829aa8201d1e4236d2ea61fa",
"packages": [ "packages": [
{ {
"name": "dingo/api", "name": "dingo/api",
...@@ -1762,6 +1762,82 @@ ...@@ -1762,6 +1762,82 @@
"time": "2018-10-10T09:24:14+00:00" "time": "2018-10-10T09:24:14+00:00"
}, },
{ {
"name": "nwidart/laravel-modules",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/nWidart/laravel-modules.git",
"reference": "d487d9be3bfd6b7365678fd805d9ba5f0dd8295c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nWidart/laravel-modules/zipball/d487d9be3bfd6b7365678fd805d9ba5f0dd8295c",
"reference": "d487d9be3bfd6b7365678fd805d9ba5f0dd8295c",
"shasum": "",
"mirrors": [
{
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.7",
"laravel/framework": "5.7.*",
"mockery/mockery": "~1.0",
"orchestra/testbench": "^3.7",
"phpstan/phpstan": "^0.9.2",
"phpunit/phpunit": "~7.3",
"spatie/phpunit-snapshot-assertions": "^1.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Nwidart\\Modules\\LaravelModulesServiceProvider"
],
"aliases": {
"Module": "Nwidart\\Modules\\Facades\\Module"
}
},
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"autoload": {
"psr-4": {
"Nwidart\\Modules\\": "src"
},
"files": [
"src/helpers.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Widart",
"email": "n.widart@gmail.com",
"homepage": "https://nicolaswidart.com",
"role": "Developer"
}
],
"description": "Laravel Module management",
"keywords": [
"laravel",
"module",
"modules",
"nwidart",
"rad"
],
"time": "2018-09-30T10:02:46+00:00"
},
{
"name": "paragonie/random_compat", "name": "paragonie/random_compat",
"version": "v9.99.99", "version": "v9.99.99",
"source": { "source": {
...@@ -2219,6 +2295,63 @@ ...@@ -2219,6 +2295,63 @@
"time": "2018-10-13T15:16:03+00:00" "time": "2018-10-13T15:16:03+00:00"
}, },
{ {
"name": "qiniu/php-sdk",
"version": "v7.2.6",
"source": {
"type": "git",
"url": "https://github.com/qiniu/php-sdk.git",
"reference": "305ce1c1c0c71f794661fe45a96facf61ef96c5d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/qiniu/php-sdk/zipball/305ce1c1c0c71f794661fe45a96facf61ef96c5d",
"reference": "305ce1c1c0c71f794661fe45a96facf61ef96c5d",
"shasum": "",
"mirrors": [
{
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~2.3"
},
"type": "library",
"autoload": {
"psr-4": {
"Qiniu\\": "src/Qiniu"
},
"files": [
"src/Qiniu/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Qiniu",
"email": "sdk@qiniu.com",
"homepage": "http://www.qiniu.com"
}
],
"description": "Qiniu Resource (Cloud) Storage SDK for PHP",
"homepage": "http://developer.qiniu.com/",
"keywords": [
"cloud",
"qiniu",
"sdk",
"storage"
],
"time": "2018-05-18T04:37:29+00:00"
},
{
"name": "ramsey/uuid", "name": "ramsey/uuid",
"version": "3.8.0", "version": "3.8.0",
"source": { "source": {
...@@ -2307,6 +2440,59 @@ ...@@ -2307,6 +2440,59 @@
"time": "2018-07-19T23:38:55+00:00" "time": "2018-07-19T23:38:55+00:00"
}, },
{ {
"name": "stevenyangecho/laravel-u-editor",
"version": "v1.4.2",
"source": {
"type": "git",
"url": "https://github.com/stevenyangecho/laravel-u-editor.git",
"reference": "e8612da55f5a7ec1acf76cc2d03e3504ccb3bff9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/stevenyangecho/laravel-u-editor/zipball/e8612da55f5a7ec1acf76cc2d03e3504ccb3bff9",
"reference": "e8612da55f5a7ec1acf76cc2d03e3504ccb3bff9",
"shasum": "",
"mirrors": [
{
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"ext-fileinfo": "*",
"illuminate/support": "5.*",
"php": ">=5.4.0",
"qiniu/php-sdk": "7.*"
},
"type": "library",
"autoload": {
"psr-4": {
"Stevenyangecho\\UEditor\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Steven Yang",
"email": "yqmking@163.com"
}
],
"description": "UEditor for laravel5. Support i18n. UEditor is a Rich Text Web Editor From Baidu.",
"keywords": [
"laravel",
"laravel-u-editor",
"laravel5 web text editor",
"steven yang",
"stevenyangecho",
"ueditor"
],
"time": "2017-06-21T06:29:09+00:00"
},
{
"name": "swiftmailer/swiftmailer", "name": "swiftmailer/swiftmailer",
"version": "v6.1.3", "version": "v6.1.3",
"source": { "source": {
......
...@@ -50,7 +50,7 @@ return [ ...@@ -50,7 +50,7 @@ return [
'prefix' => 'admin', 'prefix' => 'admin',
'namespace' => 'App\\Admin\\Controllers', 'namespace' => 'App\\Http\\Controllers\\Admin',
'middleware' => ['web', 'admin'], 'middleware' => ['web', 'admin'],
], ],
......
...@@ -148,6 +148,7 @@ return [ ...@@ -148,6 +148,7 @@ return [
Illuminate\View\ViewServiceProvider::class, Illuminate\View\ViewServiceProvider::class,
Dingo\Api\Provider\LaravelServiceProvider::class, Dingo\Api\Provider\LaravelServiceProvider::class,
Tymon\JWTAuth\Providers\LaravelServiceProvider::class, Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
Stevenyangecho\UEditor\UEditorServiceProvider::class,
/* /*
* Package Service Providers... * Package Service Providers...
......
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateArticlesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->string('title')->nullable()->comment('标题');
$table->integer('articlecats_id')->default(0)->comment('分类id');
$table->string('message')->nullable()->comment('描述');
$table->text('content')->nullable()->comment('内容');
$table->boolean('is_show')->default(0)->comment('是否显示');
$table->integer('click_num')->default(0)->comment('点击量');
$table->integer('sort_order')->default(0)->comment('排序');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('articles');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateArticlecatsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('articlecats', function (Blueprint $table) {
$table->increments('id');
$table->integer('pid')->default(0)->comment('父id');
$table->string('name')->nullable()->comment('分类名');
$table->integer('sort_order')->default(0)->comment('排序');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('articlecats');
}
}
...@@ -22,8 +22,12 @@ $api->version('v1', function ($api) { ...@@ -22,8 +22,12 @@ $api->version('v1', function ($api) {
$api->group(["namespace" => "App\Http\Controllers\Api",'middleware'=>'auth:api'], function ($api) { $api->group(["namespace" => "App\Http\Controllers\Api",'middleware'=>'auth:api'], function ($api) {
$api->post('decode', 'AccountController@decode'); $api->post('decode', 'AccountController@decode');
}); });
$api->group(["namespace" => "App\Http\Controllers\Api"], function ($api) { $api->group(["namespace" => "App\Http\Controllers\Api"], function ($api) {
$api->post('login', 'UserController@login'); $api->post('login', 'UserController@login');
$api->post('reg', 'UserController@store'); $api->post('reg', 'UserController@store');
}); });
}); });
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