本次项目使用 Laravel6.0 + vue.js + elementUI + 微信小程序
实现沃尔玛扫码购
项目设计—接口
本次项目所有接口使用 laravel
框架实现。
项目设计—后台
后台开发使用 laravel
集成 elementUI
模式,页面套用 elementUI
自带样式。
后台模块有:
1、实现后台登录,对接到前端 vue
页面
2、购物袋管理:基本的增删改查,使用模态框实现
3、上传图片:单独建一张表,用来存储所有图片,两种方法实现上传:
使用插件,上传到七牛 (购物袋模块)
后端采用接口返回
token
的方式,前端读取接口,获取token
,判断当前图片是否合格。 (商品模块)
4、商品管理:基本的增删改查,首页增加模糊搜索、分页,是否显示、多选删除、导出Excel
5、优惠券管理
6、订单管理:查出所有用户的订单,并查看详情
项目设计—前台
前台对接微信小程序,页面纯手写。
所有代码根据完成的模块情况,依次提交到 github
远程仓库。提交步骤:
git init
git add .
git commit -m "first commit"
git remote rm origin // 删除远程仓库,此步骤慎用
git remote add origin https://github.com/huangdj/canteen.git
git push -u origin master
一、创建项目
1、依次执行如下命令:
laravel new canteen
composer require laravel/ui
php artisan ui vue --auth // 初始化前端脚手架
cnpm install // 安装前端依赖
npm run dev // 编译前端资源
2、实现后台登录
(1)、在 web.php
中配置路由:
Route::prefix('admin')->namespace('Admin')->group(function () {
Route::get('/', 'DashboardController@index'); //后台首页
});
(2)、创建控制器和方法
php artisan make:controller Admin/DashboardController
public function index()
{
dd('后台首页,当前管理员:' . auth('admin')->user()->name); // 打印当前登录的用户信息
}
(3)、创建管理员(admins)数据表
php artisan make:migration create_admins_table
(4)、修改迁移文件 database/migrations/*_create_admins_table.php
:
public function up()
{
Schema::create('admins', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
php artisan migrate // 运行迁移
手动往数据表 `admins` 里面添加一条数据
(5)、创建模型并添加代码:
php artisan make:model Models/Admin
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class Admin 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',
];
}
(6)、修改路由组,如下:
Route::prefix('admin')->namespace('Admin')->group(function () {
Route::get('login', 'LoginController@showLoginForm')->name('admin.login');
Route::post('login', 'LoginController@login');
Route::post('logout', 'LoginController@logout')->name('admin.logout');
Route::name('admin.')->group(function () {
Route::get('/', 'DashboardController@index');
});
});
(7)、新建管理员登录控制器并添加代码:
php artisan make:controller Admin/LoginController
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
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;
/**
* 改成用户名登录
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()