use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateBlogTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('blog_category', function (Blueprint $table) {
$table->bigIncrements('cate_id');
$table->string('cate_name','50');
$table->string('cate_title','255');
$table->smallInteger('cate_order');
$table->Integer('cate_pid');
$table->softDeletes();
$table->timestamps();
});
Schema::create('blog_article', function (Blueprint $table) {
$table->bigIncrements('art_id');
$table->string('art_title','100');
$table->string('art_tag','100');
$table->string('art_description','255');
$table->string('art_thumb','255');
$table->text('art_content');
$table->timestamp('art_time');
$table->string('art_editor','50');
$table->Integer('art_view');
$table->Integer('cate_id');
$table->Integer('cate_status');
$table->Integer('cate_love');
$table->Integer('cate_collect');
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('blog_category');
Schema::dropIfExists('blog_article');
}
}
运行生成的user表的迁移文件
最好是把model放在一个文件夹中比如 我们放入 app下的admin里
php artisan make:model /Admin/Model/Blog
注意这里我们在使用artisan命令 我们的 / 指向的就是app!
:
php artisan admin:make BlogController --model=App\Admin\Model\blog
注意在laravel admin 控制台源代码中有展示,这个linux下两个\ 反斜杠是转义 和路径
所以这里都用两个反斜杠
生成 UserController.php 文件
$router->resource('blogs', BlogController::class);
namespace App\Admin\Controllers;
use App\Admin\Model\blog;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
class BlogController extends AdminController
{
/**
* Title for current resource.
*
* @var string
*/
protected $title = 'App\Admin\Model\blog';
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
$grid = new Grid(new blog);
return $grid;
}
/**
* Make a show builder.
*
* @param mixed $id
* @return Show
*/
protected function detail($id)
{
$show = new Show(blog::findOrFail($id));
return $show;
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
$form = new Form(new blog);
return $form;
}
}
路由:
use Illuminate\Routing\Router;
Admin::routes();
Route::group([
'prefix' => config('admin.route.prefix'),
'namespace' => config('admin.route.namespace'),
'middleware' => config('admin.route.middleware'),
], function (Router $router) {
$router->get('/', 'HomeController@index')->name('admin.home');
$router->resource('users', UserController::class);
$router->resource('blogs', BlogController::class);
});