一、创建路由
Route::get('/', function () { return redirect('/admin'); }); //后台分组路由 Route::prefix('admin')->name('admin.')->group(function(){ //后台开发阶段,默认首页跳转至后台 Route::get('/',function(){ return redirect('admin/index'); }); //后台admin登陆 Route::prefix('login')->name('login.')->group(function(){ Route::get('/','AdminLoginController@login')->name('home'); //注册 Route::get('/signup','AdminLoginController@signup')->name('signup'); //注册提交 Route::post('/store','AdminLoginController@store')->name('store'); }); //首页和配置 Route::get('index','AdminIndexController@index')->name('home'); Route::prefix('config')->name('config.')->group(function(){ Route::get('/',function(){ return redirect('/admin/config/index'); }); //后台配置 Route::get('/index','AdminConfigController@config')->name('index'); //站点配置 Route::get('/siteconfig','AdminConfigController@siteconfig')->name('siteconfig'); }); //静态页面关于/帮助/联系我们 Route::get('about','AdminStaticPageController@about')->name('static.about'); Route::get('help','AdminStaticPageController@help')->name('static.help'); Route::get('about','AdminStaticPageController@about')->name('static.about'); //资源路由【管理员、文章】 Route::resource('manager', 'AdminManagerController')->except('index'); Route::resource('article', 'AdminArticleController')->except('index'); });
二、创建控制器
登陆、首页、配置、静态页、管理员、文章
php artisan make:controller AdminLoginController php artisan make:controller AdminIndexController php artisan make:controller AdminConfigController php artisan make:controller AdminStaticPageController php artisan make:controller AdminManagerController -r php artisan make:controller AdminArticleController -r
三、创建Model/Migration(迁移文件)
1、创建迁移文件
php artisan make:model Models/Manager -m php artisan make:model Models/Article -m
2、编辑Migrate文件,设置数据库字段
databaes/migrations/目录下,点击连接参考
3、生成对应数据表
//1、创建前可以pretend命令测试下 php artisan migrate --pretend //2、创建对应数据表 php artisan migrate php artisan migrate:refresh //3、如表结构填错了可执行回滚操作重新创建 php artisan migrate:rollback
4、填充数据前Model修改
//白名单 protected $fillable = ""; //黑名单 protected $guarded = [];
5、生成填充器
php artisan make:seeder ManagersTableSeeder //然后编辑databaes/migrations/seeds/ManagersTableSeeder.php文件
编辑填充器
use AppManager; //============================================= public function run() { // Manager::truncate(); $faker = FakerFactory::create(); for ($i = 0;$i < 50;$i++){ Manager::create([ 'username' => $faker->userName, 'password' => bcrypt('admin888'), 'email' => $faker->email, ]); } }
6、运行填充器命令进行填充表里的数据
php artisan db:seed --class=ArticlesTableSeeder //如果填充多张表的数据填充编辑:databaes/migrations/seeds/DatabaseSeeder.php public function run() { $this->call(ArticlesTableSeeder::class);//填充articles $this->call(ManagersTableSeeder::class);//填充Managers } //然后执行,php artisan db:seed