first-commit

This commit is contained in:
fangzesheng 2018-12-16 11:38:44 +08:00
commit d5ce3b46eb
607 changed files with 144898 additions and 0 deletions

33
.env.example Normal file
View File

@ -0,0 +1,33 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
/node_modules
/public/storage
/vendor
/storage
/.idea
Homestead.json
Homestead.yaml
.env
composer.lock

40
app/Console/Kernel.php Normal file
View File

@ -0,0 +1,40 @@
<?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 Closure based commands for the application.
*
* @return void
*/
protected function commands()
{
require base_path('routes/console.php');
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
\Illuminate\Auth\AuthenticationException::class,
\Illuminate\Auth\Access\AuthorizationException::class,
\Symfony\Component\HttpKernel\Exception\HttpException::class,
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
\Illuminate\Session\TokenMismatchException::class,
\Illuminate\Validation\ValidationException::class,
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
return redirect()->guest(route('login'));
}
}

20
app/Helpers/functions.php Normal file
View File

@ -0,0 +1,20 @@
<?php
/**
* 判断是否为不可操作id
*
* @param number $id 参数id
* @param string $configName 配置名
* @param bool $emptyRetValue
* @param string $split 分隔符
* @return bool
*/
if (!function_exists('is_config_id')) {
function is_config_id($id, $configName, $emptyRetValue = false, $split = ",")
{
if (empty($configName)) return $emptyRetValue;
$str = trim(config($configName, ""));
if (empty($str)) return $emptyRetValue;
$ids = explode($split, $str);
return in_array($id, $ids);
}
}

View File

@ -0,0 +1,32 @@
<?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;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}

View File

@ -0,0 +1,61 @@
<?php
/**
* 用户登陆
*
* @author fzs
* @Time: 2017/07/14 15:57
* @version 1.0 版本号
*/
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\Log;
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 {authenticated as oriAuthenticated;}
use AuthenticatesUsers {login as doLogin;}
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function login(Request $request)
{
if($request->input('verity')==session('code'))return $this->doLogin($request);
else return redirect('/login')->withErrors([trans('fzs.login.false_verify')]);
}
public function username()
{
return 'username';
}
protected function authenticated(Request $request, $user)
{
Log::addLogs(trans('fzs.login.login_info'),'/login',$user->id);
return $this->oriAuthenticated($request, $user);
}
}

View File

@ -0,0 +1,71 @@
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
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 = '/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:6|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' => bcrypt($data['password']),
]);
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
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 = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}

View File

@ -0,0 +1,27 @@
<?php
/**
* 基础控制器,目前只加入一个公共方法,可以拓展
*
* @author fzs
* @Time: 2017/07/14 15:57
* @version 1.0 版本号
*/
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class BaseController extends Controller
{
/**
* 返回自定义标准json格式
*
* @access protected
* @param string $lang 语言包
* @param number $res 结果code
* @return json
*/
protected function resultJson($lang,$res)
{
return strstr($lang,'fzs')?['status'=>$res,'msg'=>trans($lang)]:['status'=>$res,'msg'=>$lang];
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

View File

@ -0,0 +1,70 @@
<?php
/**
* 用户登陆过后首页以及一些公共方法
*
* @author fzs
* @Time: 2017/07/14 15:57
* @version 1.0 版本号
*/
namespace App\Http\Controllers;
use App\Models\Admin;
use Gregwar\Captcha\CaptchaBuilder;
use Gregwar\Captcha\PhraseBuilder;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
class HomeController extends BaseController
{
/**
* 后台首页
*/
public function index() {
$menu = new Admin();
return view('admin.index',['menus'=>$menu->menus(),'mid'=>$menu->getMenuId(),'parent_id'=>$menu->getParentMenuId()]);
}
/**
* 验证码
*/
public function verify(){
$phrase = new PhraseBuilder;
$code = $phrase->build(4);
$builder = new CaptchaBuilder($code, $phrase);
$builder->setBackgroundColor(255, 255, 255);
$builder->build(130,40);
$phrase = $builder->getPhrase();
Session::flash('code', $phrase); //存储验证码
return response($builder->output())->header('Content-type','image/jpeg');
}
/**
* 欢迎首页
*/
public function welcome(){
return view('admin.welcome',['sysinfo'=>$this->getSysInfo()]);
}
/**
* 排序
*/
public function changeSort(Request $request){
$data = $request->all();
if(is_numeric($data['id'])){
$res = DB::table('admin_'.$data['name'])->where('id',$data['id'])->update(['order'=>$data['val']]);
if($res)return $this->resultJson('fzs.common.success', 1);
else return $this->resultJson('fzs.common.fail', 0);
}else{
return $this->resultJson('fzs.common.wrong', 0);
}
}
/**
* 获取系统信息
*/
protected function getSysInfo(){
$sys_info['ip'] = GetHostByName($_SERVER['SERVER_NAME']);
$sys_info['phpv'] = phpversion();
$sys_info['web_server'] = $_SERVER['SERVER_SOFTWARE'];
$sys_info['time'] = date("Y-m-d H:i:s");
$sys_info['domain'] = $_SERVER['HTTP_HOST'];
$mysqlinfo = DB::select("SELECT VERSION() as version");
$sys_info['mysql_version'] = $mysqlinfo[0]->version;
return $sys_info;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* 日志管理
*
* @author fzs
* @Time: 2017/07/14 15:57
* @version 1.0 版本号
*/
namespace App\Http\Controllers;
use App\Models\Log;
use Illuminate\Http\Request;
class LogController extends Controller
{
/**
* 日志列表
*/
public function index(Request $request)
{
return $this->show($request);
}
/**
* 根据条件日志列表查询
*/
public function show(Request $request)
{
$sql = Log::with('user.roles');
$sql->leftJoin(config('admin.user_table') . " as users", "users.id" , "=", "admin_logs.admin_id");
if(true == $request->has('title')&&true == $request->has('status')) {
$sql->where('admin_logs.'.$request->input('status'), 'LIKE', '%'.trim($request->input('title')).'%');
}
if(true == $request->has('begin')) {
$sql->where('admin_logs.log_time', '>=', trim($request->input('begin')));
}
$sql->select('admin_logs.*');
$pager = $sql->orderBy('admin_logs.id', 'desc')->paginate()->appends($request->all());
return view('logs.list', ['pager'=>$pager,'input'=>$request->all()]);
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* 菜单管理
*
* @author fzs
* @Time: 2017/07/14 15:57
* @version 1.0 版本号
*/
namespace App\Http\Controllers;
use App\Http\Requests\StoreRequest;
use App\Models\Log;
use App\Service\DataService;
use App\Models\Role;
use App\Models\Menu;
class MenuController extends BaseController
{
/**
* 菜单列表
*/
public function index()
{
return view('menus.list', ['menus'=>Menu::toTree(),'roles'=>Role::all()]);
}
/**
* 菜单增加保存
*/
public function store(StoreRequest $request){
$model = new Menu();
$menu = DataService::handleDate($model,$request->all(),'menus-add_or_update');
if($menu['status']==1)Log::addLogs(trans('fzs.menus.handle_menu').trans('fzs.common.success'),'/menus/story');
else Log::addLogs(trans('fzs.menus.handle_menu').trans('fzs.common.fail'),'/menus/destroy');
return $menu;
}
/**
* 菜单编辑页面
*/
public function edit($id=0)
{
$menu = ($id > 0) ? Menu::findByRoleId($id) : [];
return view('menus.edit', ['id'=>$id,'menu'=>$menu,'menus'=>Menu::toTree(),'roles'=>Role::all()]);
}
/**
* 菜单删除
*/
public function destroy($id)
{
if (is_config_id($id, "admin.menu_table_cannot_manage_ids", false))return $this->resultJson('fzs.menus.notdel', 0);
$model = new Menu();
$menu = DataService::handleDate($model,['id'=>$id],'menus-delete');
if($menu['status']==1)Log::addLogs(trans('fzs.menus.del_menu').trans('fzs.common.success'),'/menus/destroy/'.$id);
else Log::addLogs(trans('fzs.menus.del_menu').trans('fzs.menus.fail'),'/menus/destroy/'.$id);
return $menu;
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* 权限管理
*
* @author fzs
* @Time: 2017/07/14 15:57
* @version 1.0 版本号
*/
namespace App\Http\Controllers;
use App\Http\Requests\StoreRequest;
use App\Models\Log;
use App\Models\Permission;
use App\Models\Role;
use App\Service\DataService;
use Illuminate\Http\Request;
class PermissionController extends BaseController
{
/**
* 权限列表
*/
public function index(){
return view('permissions.list',['list'=>Permission::get()->toArray()]);
}
/**
* 权限编辑列表
*/
public function edit($id=0)
{
$info = $id?Permission::find($id):[];
$role = $info?$info->roleToIds():[];
return view('permissions.edit', ['id'=>$id,'info'=>$info,'roles'=>Role::all(),'rolelist'=>$role]);
}
/**
* 权限增加保存
*/
public function store(StoreRequest $request){
$model = new Permission();
$permission = DataService::handleDate($model,$request->all(),'permissions-add_or_update');
if($permission['status']==1)Log::addLogs(trans('fzs.permissions.handle_permission').trans('fzs.common.success'),'/permissions/story');
else Log::addLogs(trans('fzs.permissions.handle_permission').trans('fzs.common.fail'),'/permissions/destroy');
return $permission;
}
/**
* 权限删除
*/
public function destroy($id)
{
if (is_config_id($id, "admin.permission_table_cannot_manage_ids", false))return $this->resultJson('fzs.permissions.notdel', 0);
$model = new Permission();
$permission = DataService::handleDate($model,['id'=>$id],'permissions-delete');
if($permission['status']==1)Log::addLogs(trans('fzs.permissions.del_permission').trans('fzs.common.success'),'/permissions/destroy/'.$id);
else Log::addLogs(trans('fzs.permissions.del_permission').trans('fzs.common.fail'),'/permissions/destroy/'.$id);
return $permission;
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* 角色管理
*
* @author fzs
* @Time: 2017/07/14 15:57
* @version 1.0 版本号
*/
namespace App\Http\Controllers;
use App\Models\Permission;
use App\Models\Role;
use App\Service\DataService;
use App\Http\Requests\StoreRequest;
use App\Models\Log;
class RoleController extends BaseController
{
/**
* 角色列表
*/
public function index(){
return view('roles.list',['list'=>Role::get()->toArray()]);
}
/**
* 角色编辑
*/
public function edit($id=0)
{
$permission = Permission::get()->toArray();
$delId = explode(',',config('admin')['permission_table_cannot_manage_ids']);
foreach ($permission as $k => $v){
if(in_array($v['id'],$delId))unset($permission[$k]);
}
$info = $id?Role::find($id):[];
return view('roles.edit', ['id'=>$id,'info'=>$info,'permission'=>$permission]);
}
/**
* 角色增加保存
*/
public function store(StoreRequest $request){
$model = new Role();
$role = DataService::handleDate($model,$request->all(),'roles-add_or_update');
if($role['status']==1)Log::addLogs(trans('fzs.roles.handle_role').trans('fzs.common.success'),'/roles/story');
else Log::addLogs(trans('fzs.roles.handle_role').trans('fzs.common.fail'),'/roles/destroy');
return $role;
}
/**
* 角色删除
*/
public function destroy($id)
{
if (is_config_id($id, "admin.role_table_cannot_manage_ids", false))return $this->resultJson('fzs.roles.notdel', 0);
$model = new Role();
$role = DataService::handleDate($model,['id'=>$id],'roles-delete');
if($role['status']==1)Log::addLogs(trans('fzs.roles.del_role').trans('fzs.common.success'),'/roles/destroy/'.$id);
else Log::addLogs(trans('fzs.roles.del_role').trans('fzs.menus.fail'),'/roles/destroy/'.$id);
return $role;
}
}

View File

@ -0,0 +1,74 @@
<?php
/**
* 用户管理
*
* @author fzs
* @Time: 2017/07/14 15:57
* @version 1.0 版本号
*/
namespace App\Http\Controllers;
use App\Http\Requests\StoreRequest;
use App\Models\Admin;
use App\Models\Log;
use App\Models\Role;
use App\Models\User;
use App\Service\DataService;
use Illuminate\Http\Request;
class UserController extends BaseController
{
/**
* 用户列表
*/
public function index()
{
return view('users.list', ['list'=>User::with('roles')->get()->toArray()]);
}
/**
*用户编辑页面
*/
public function edit($id=0)
{
$info = $id?User::find($id):[];
return view('users.edit', ['id'=>$id,'roles'=>Role::all(),'info'=>$info]);
}
/**
* 用户增加保存
*/
public function store(StoreRequest $request){
$model = new User();
$user = DataService::handleDate($model,$request->all(),'users-add_or_update');
if($user['status']==1)Log::addLogs(trans('fzs.users.handle_user').trans('fzs.common.success'),'/users/story');
else Log::addLogs(trans('fzs.users.handle_user').trans('fzs.common.fail'),'/users/destroy');
return $user;
}
/**
*用户删除
*/
public function destroy($id)
{
if (is_config_id($id, "admin.user_table_cannot_manage_ids", false))return $this->resultJson('fzs.users.notdel', 0);
$model = new User();
$user = DataService::handleDate($model,['id'=>$id],'users-delete');
if($user['status']==1)Log::addLogs(trans('fzs.users.del_user').trans('fzs.common.success'),'/users/destroy/'.$id);
else Log::addLogs(trans('fzs.users.del_user').trans('fzs.menus.fail'),'/users/destroy/'.$id);
return $user;
}
/**
*用户基本信息编辑页面
*/
public function userInfo(){
$user = new Admin();
return view('users.userinfo',['userinfo'=>$user->user()]);
}
/**
*用户基本信息修改
*/
public function saveInfo(StoreRequest $request,$type){
if($type==1)$kind = 'update_info';
else $kind = 'update_pwd';
$user = DataService::handleDate(new User(),$request->all(),'users-'.$kind);
if($user['status']==1)Log::addLogs(trans('fzs.users.'.$kind).trans('fzs.common.success'),'/saveinfo/'.$type);
else Log::addLogs(trans('fzs.users.'.$kind).trans('fzs.common.fail'),'/saveinfo/'.$type);
return $user;
}
}

61
app/Http/Kernel.php Normal file
View File

@ -0,0 +1,61 @@
<?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 = [
\Illuminate\Foundation\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',
'bindings',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\AuthCheck::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'permission' => \App\Http\Middleware\Permission::class,
];
}

View File

@ -0,0 +1,57 @@
<?php
/**
* 权限检查
*
* @author fzs
* @Time: 2017/07/14 15:57
* @version 1.0 版本号
*/
namespace App\Http\Middleware;
use Illuminate\Http\JsonResponse;
use Closure;
use Illuminate\Contracts\Auth\Guard;
class AuthCheck
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new middleware instance.
*
* @param Guard $auth
* @return void
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if($request->path() == 'logout') {
$this->auth->logout();
return redirect('/');
}
if ($this->auth->guest()) {
if ($request->ajax()) {
return new JsonResponse(['msg'=>trans('fzs.common.no_permission'),'status'=>0], 200);
} else {
return redirect()->guest('/login');
}
}
return $next($request);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncrypter;
class EncryptCookies extends BaseEncrypter
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [
//
];
}

View File

@ -0,0 +1,87 @@
<?php
/**
* rbac管理
*
* @author fzs
* @Time: 2017/07/14 15:57
* @version 1.0 版本号
*/
namespace App\Http\Middleware;
use App\Utils\UrlUtils;
use Closure, Log;
use Illuminate\Http\JsonResponse;
use App\Models\Admin;
class Permission
{
/**
* 权限处理
*
* @access public
* @return mixed
*/
public function handle($request, Closure $next)
{
$admin = new Admin();
$restfulParams = UrlUtils::toRestfulParams();
$url = $restfulParams[UrlUtils::URL];
$controller = $restfulParams[UrlUtils::CONTROLLER];
$method = $restfulParams[UrlUtils::CLASS_METHOD];
$className = $restfulParams[UrlUtils::CLASS_NAME];
$requestMethod = $restfulParams[UrlUtils::REAL_METHOD];
$auth = '';
$menu = [];
$permissionName = '';
$allPermissions = $admin->permissions();
$permissionRules = [
strtolower($controller .'@'. $method),
strtolower($className .'@'. $method),
strtolower($controller .'@'. $requestMethod),
strtolower($className .'@'. $requestMethod),
strtolower($controller),
strtolower($className),
];
foreach ($permissionRules as $p) {
if (isset($allPermissions[$p])) {
$permission = $allPermissions[$p];
$auth = $permission[config('admin.permission_name')];
$permissionName = $permission[config('admin.permission_display_name')];
break;
}
}
$allMenus = $admin->allMenus();
$urlMatchMaxLen = 0;
foreach ($allMenus as $m) {
$params = explode(":", $m['routes']);
if (empty($params[0]) || empty($params[1])) continue;
if (($params[0] == 'url' && starts_with($url, $params[1]))) {
$len = strlen($params[1]);
if ($len > $urlMatchMaxLen) {
$menu = $m;
}
} else if($params[0] == 'controller' && in_array(strtolower($params[1]), $permissionRules) ) {
$menu = $m;
break;
}
}
if (!empty($menu)) {
$pmid = isset($menu[config('admin.menu_table_parent_id_key')]) ? $menu[config('admin.menu_table_parent_id_key')] : 0;
$mid = isset($menu[config('admin.menu_table_id_key')]) ? $menu[config('admin.menu_table_id_key')] : 0;
$admin->setMenuId($pmid, $mid);
}
if ($admin->hasRole(config('admin.role_admin'))) {
return $next($request);
}
if (!empty($auth)) {
if (!$admin->can($auth)) {
if ($request->ajax()) {
return new JsonResponse(['msg'=>trans('fzs.common.no_permission'),'status'=>0], 200);
} else {
exit(trans('fzs.common.no_permission'));
}
}
}
return $next($request);
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Http\Middleware;
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('/home');
}
return $next($request);
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings as BaseTrimmer;
class TrimStrings extends BaseTrimmer
{
/**
* The names of the attributes that should not be trimmed.
*
* @var array
*/
protected $except = [
'password',
'password_confirmation',
];
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
class VerifyCsrfToken extends BaseVerifier
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
//
];
}

View File

@ -0,0 +1,107 @@
<?php
/**
* 对于后台提交的数据进行验证类
*
* @author fzs
* @Time: 2017/07/14 15:57
* @version 1.0 版本号
*/
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
$rules = [];
switch (request()->getPathInfo()) {
case '/menus':
$rules['category'] = 'required';
if($mid = request()->input('id'))$rules['name'] = 'required|alpha|between:2,12|unique:admin_menus,title,'.$mid;
else $rules['name'] = 'required|alpha|between:2,12|unique:admin_menus,title';
$rules['order'] = 'required|numeric';
$rules['icon'] = 'required';
$rules['uri'] = 'required|max:12';
$rules['roles'] = 'required';
break;
case '/users':
if($uid = request()->input('id')){
$rules['user_name'] = 'required|alpha|between:2,12|unique:admin_users,username,'.$uid;
$rules['pwd'] = 'nullable|alpha_num|between:6,12|confirmed';
$rules['email'] = 'required|email|unique:admin_users,email,'.$uid;
}else{
$rules['user_name'] = 'required|alpha|between:2,12|unique:admin_users,username';
$rules['pwd'] = 'required|alpha_num|between:6,12|confirmed';
$rules['email'] = 'required|email|unique:admin_users,email';
$rules['pwd_confirmation'] = 'required';
}
$rules['tel'] = 'required|numeric';
$rules['sex'] = 'required|numeric';
$rules['user_role'] = 'required|numeric';
break;
case '/roles':
if($rid = request()->input('id')){
$rules['role_remark'] = 'required|between:2,12|alpha|unique:admin_roles,name,'.$rid;
$rules['role_name'] = 'required|between:2,12|unique:admin_roles,display_name,'.$rid;
}else{
$rules['role_remark'] = 'required|between:2,12|alpha|unique:admin_roles,name';
$rules['role_name'] = 'required|between:2,12|unique:admin_roles,display_name';
}
$rules['role_desc'] = 'required|between:2,30';
$rules['permission_list'] = 'array';
break;
case '/permissions':
if($rid = request()->input('id')){
$rules['permission_name'] = 'required|between:2,12|unique:admin_permissions,name,'.$rid;
$rules['permission_control'] = 'required|between:2,50|unique:admin_permissions,controllers,'.$rid;
}else{
$rules['permission_name'] = 'required|between:2,12|unique:admin_permissions,display_name';
$rules['permission_control'] = 'required|between:2,50|unique:admin_permissions,controllers';
}
$rules['permission_desc'] = 'required|between:2,30';
$rules['permission_remark'] = 'required|alpha|between:2,30';
$rules['permission_roles'] = 'required|array';
break;
case '/saveinfo/1':
$rules['useremail'] = 'required|email|unique:admin_users,email,'.request()->input('id');
$rules['usertel'] = 'required|numeric';
$rules['usersex'] = 'required|numeric';
break;
case '/saveinfo/2':
$rules['oldpwd'] = 'required|alpha_num|between:6,12|different:pwd';
$rules['pwd'] = 'required|alpha_num|between:6,12|confirmed';
$rules['pwd_confirmation'] = 'required';
break;
}
return $rules;
}
public function response(array $errors)
{
if($errors){
foreach ($errors as $k => $v){
$msg = $v[0];
break;
}
}
if ($this->expectsJson()) {
return response()->json(['status'=>0,'msg'=>$msg]);
}
return $this->redirector->to($this->getRedirectUrl())
->withInput($this->except($this->dontFlash))
->withErrors($errors, $this->errorBag);
}
}

72
app/Models/Admin.php Normal file
View File

@ -0,0 +1,72 @@
<?php
namespace App\Models;
use Auth;
use Illuminate\Database\Eloquent\Model;
class Admin extends Model
{
protected $parentMenuId = 0;
protected $MenuId = 0;
public function can($permission)
{
return static::user()->can($permission);
}
public function user()
{
return Auth::user();
}
public function userId()
{
return Auth::user()['id'];
}
public function userCid()
{
return Auth::user()['cid'];
}
public function menus()
{
$user = $this->user();
return Menu::getUserMenu($user);
}
public function allMenus()
{
return Menu::all();
}
public function permissions()
{
return Permission::controllerPermissions();
}
public function hasRole($roles)
{
return $this->user()->hasRole($roles);
}
public function guest() {
return Auth::guest();
}
public function setMenuId ($pmid, $mid)
{
$this->parentMenuId = $pmid;
$this->MenuId = $mid;
}
public function getParentMenuId()
{
return $this->parentMenuId;
}
public function getMenuId()
{
return $this->MenuId;
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Models\Interfaces;
interface AdminMenuInterface
{
/**
* 与角色的多对多关系
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function roles();
/**
* 与权限的多对多关系
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function perms();
/**
* 保存角色
* @param $roles
*/
public function saveRoles($roles);
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Models\Interfaces;
interface AdminPermissionInterface
{
/**
* 与角色的多对多关系.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function roles();
/**
* 与菜单的多对多关系.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function menus();
/**
* 保存角色
* @param $roles
* @return mixed
*/
public function saveRoles($roles);
/**
* 保存菜单
* @param $menus
* @return mixed
*/
public function saveMenus($menus);
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Models\Interfaces;
interface AdminRoleInterface
{
/**
* 与用户的多对多关系
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function users();
/**
* 与权限的多对多关系
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function perms();
/**
* 与菜单的多对多关系
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function menus();
/**
* 保存权限
*
* @param mixed $inputPermissions
*
* @return void
*/
public function savePermissions($inputPermissions);
}

View File

@ -0,0 +1,39 @@
<?php
namespace App\Models\Interfaces;
interface AdminUsersInterface
{
/**
* 与角色的多对多关系
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function roles();
/**
* 检查用户是是否有角色.
*
* @param string|array $name 角色名.
* @param bool $requireAll 是否有全部请求权限
*
* @return bool
*/
public function hasRole($name, $requireAll = false);
/**
* 检查用户是否有权限
*
* @param string|array $permission 权限名
* @param bool $requireAll 是否有全部请求权限
*
* @return bool
*/
public function can($permission, $requireAll = false);
/**
* 保存角色
*
* @param mixed $roles
*/
public function saveRoles($roles);
}

28
app/Models/Log.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Log extends Model
{
protected $table = 'admin_logs';
public function user()
{
return $this->hasOne(config('auth.providers.users.model'), 'id', 'admin_id');
}
public static function addLogs($content,$url,$id = ''){
if(!$id){
$admin = new Admin();
$id = $admin->userId();
}
$data = [
'admin_id'=>$id,
'log_info'=>$content,
'log_url'=>$url,
'log_ip'=>$_SERVER['REMOTE_ADDR'],
'log_time'=>date('Y-m-d H:i:s',time())
];
Log::insert($data);
}
}

18
app/Models/Menu.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Auth;
use Illuminate\Database\Eloquent\Model;
use App\Models\Interfaces\AdminMenuInterface;
use App\Models\Traits\AdminMenuTrait;
class Menu extends Model implements AdminMenuInterface
{
use AdminMenuTrait;
protected $table = 'admin_menus';
protected $primaryKey = 'id';
protected static $branchOrder = [];
}

43
app/Models/Permission.php Normal file
View File

@ -0,0 +1,43 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Interfaces\AdminPermissionInterface;
use App\Models\Traits\AdminPermissionTrait;
class Permission extends Model implements AdminPermissionInterface
{
use AdminPermissionTrait;
protected $table = 'admin_permissions';
public function roleToIds()
{
$roles =$this->roles;
$ids = [];
if (count($roles) > 0) {
foreach ($roles as $role) {
if (is_object($role)) {
$ids[] = $role->id;
} else if (is_array($role) && isset ($role['id'])) {
$ids[] = $role['id'];
}
}
}
return $ids;
}
public function menuToIds()
{
$menus = $this->menus;
$ids = [];
if (count($menus) > 0) {
foreach ($menus as $menu) {
if (is_object($menu)) {
$ids[] = $menu->id;
} else if (is_array($menu) && isset ($menu['id'])) {
$ids[] = $menu['id'];
}
}
}
return $ids;
}
}

17
app/Models/Role.php Normal file
View File

@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Interfaces\AdminRoleInterface;
use App\Models\Traits\AdminRoleTrait;
use Illuminate\Support\Facades\DB;
class Role extends Model implements AdminRoleInterface
{
use AdminRoleTrait;
protected $table = 'admin_roles';
public function isAbleDel($roleid){
return DB::table('admin_role_user')->where('role_id',$roleid)->get()->toArray()?true:false;
}
}

View File

@ -0,0 +1,227 @@
<?php
namespace App\Models\Traits;
use Illuminate\Support\Facades\Config;
trait AdminMenuTrait
{
/**
* 与角色的多对多关系
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function roles()
{
return $this->belongsToMany(Config::get('admin.role'), Config::get('admin.menu_role_table'),
Config::get('admin.menu_foreign_key'), Config::get('admin.role_foreign_key'));
}
/**
* 与权限的多对多关系
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function perms()
{
return $this->belongsToMany(Config::get('admin.permission'), Config::get('admin.permission_menu_table'),
Config::get('admin.menu_foreign_key'), Config::get('admin.permission_foreign_key'));
}
/**
* 把权限转成角色ID,并放到到数组的roleIds
* @param $menu
* @return mixed
*/
private static function transRoleIds($menu) {
if (!empty($menu['roles'])) {
$menu['roleIds'] = array_map(function ($item){
return $item['id'];
}, $menu['roles']);
}
else
{
$menu['roleIds'] = [];
}
return $menu;
}
/**
* 把权限转成权限ID,并放到到数组的permIds
* @param $menu 菜单数组
* @return mixed
*/
private static function transPermIds($menu) {
if (!empty($menu['perms'])) {
$menu['permIds'] = array_map(function ($item){
return $item['id'];
}, $menu['perms']);
}
else
{
$menu['permIds'] = [];
}
return $menu;
}
/**
* 查找菜单
* @param $id 菜单ID
* @return mixed
*/
public static function find($id)
{
return static::with('roles')->find($id);
}
/**
* 查找带权限的菜单
* @param $id 菜单ID
* @return array|mixed
*/
public static function findByRoleId($id)
{
$menu = [];
$menuObj= static::with('roles')->find($id);
if (!empty($menuObj))
{
$menu = $menuObj->toArray();
$menu = static::transRoleIds($menu);
}
return $menu;
}
/**
* 转成树结构
* @param array $elements 树数组
* @param int $parentId 上级ID
* @param array $roleIds 权限ID
* @return array
*/
public static function toTree(array $elements = [], $parentId = 0, $roleIds = [])
{
$branch = [];
if (empty($elements)) {
$elements = static::with('roles', 'perms')->orderByRaw('`order` = 0,`order`')->get()->toArray();
}
foreach ($elements as $element) {
if ($element['parent_id'] == $parentId) {
$element = static::transRoleIds($element);
$element = static::transPermIds($element);
if (!empty($element['roleIds']) && !empty($roleIds))
{
$_roles = array_intersect($element['roleIds'], $roleIds);
if (empty($_roles)) continue;
}
$children = static::toTree($elements, $element['id'], $roleIds);
if ($children) {
$element['children'] = $children;
}
$branch[] = $element;
}
}
return $branch;
}
/**
* 设计分支排序
*
* @param array $order
*
* @return void
*/
protected static function setBranchOrder(array $order)
{
static::$branchOrder = array_flip(array_flatten($order));
static::$branchOrder = array_map(function ($item) {
return ++$item;
}, static::$branchOrder);
}
/**
* 保存树类菜单
* @param array $tree 树结构
* @param int $parentId 上级ID
*/
public static function saveTree($tree = [], $parentId = 0)
{
if (empty(static::$branchOrder)) {
static::setBranchOrder($tree);
}
foreach ($tree as $branch) {
$node = static::find($branch['id']);
$node->parent_id = $parentId;
$node->order = static::$branchOrder[$branch['id']];
$node->save();
if (isset($branch['children'])) {
static::saveTree($branch['children'], $branch['id']);
}
}
}
/**
* 保存角色
* @param $roles
*/
public function saveRoles($roles)
{
if (!empty($roles)) {
$this->roles()->sync($roles);
} else {
$this->roles()->detach();
}
}
/**
* 删除菜单
* @param array $options
* @return mixed
*/
public function delete(array $options = [])
{
$children = $this->where('parent_id', $this->id)->get();
$this->where('parent_id', $this->id)->delete();
if ($children) {
foreach ($children as $child) {
$child->roles()->detach();
$child->perms()->detach();
}
}
$this->roles()->detach();
$this->perms()->detach();
return parent::delete($options);
}
/**
* 得到用户菜单
* @param $user
* @return array
*/
public static function getUserMenu($user) {
$isAdminHasAllRoles = true;
$isAdmin = $user->hasRole('admin');
$roles = $user->cachedRoles();
$roleIds = [0];
foreach ($roles as $role)
{
$roleIds[] = $role->id;
}
if ($isAdminHasAllRoles && $isAdmin) $roleIds = [];
$menus = static::toTree([], 0, $roleIds);
return $menus;
}
}

View File

@ -0,0 +1,107 @@
<?php
namespace App\Models\Traits;
use Illuminate\Support\Facades\Config;
trait AdminPermissionTrait
{
/**
* 与角色的多对多关系.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function roles()
{
return $this->belongsToMany(Config::get('admin.role'), Config::get('admin.permission_role_table'),
Config::get('admin.permission_foreign_key'), Config::get('admin.role_foreign_key'));
}
/**
* 与菜单的多对多关系.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function menus()
{
return $this->belongsToMany(Config::get('admin.menu'), Config::get('admin.permission_menu_table'),
Config::get('admin.permission_foreign_key'), Config::get('admin.menu_foreign_key'));
}
/**
* 保存角色
* @param $roles
* @return mixed
*/
public function saveRoles($roles)
{
if (!empty($roles)) {
$this->roles()->sync($roles);
} else {
$this->roles()->detach();
}
}
/**
* 保存菜单
* @param $menus
* @return mixed
*/
public function saveMenus($menus)
{
if (!empty($menus)) {
$this->menus()->sync($menus);
} else {
$this->menus()->detach();
}
}
public static function boot()
{
parent::boot();
static::deleting(function($permission) {
if (!method_exists(Config::get('admin.permission'), 'bootSoftDeletes')) {
$permission->roles()->sync([]);
$permission->menus()->sync([]);
}
return true;
});
}
/**
* Controller对应的权限
* @return array
*/
public static function controllerPermissions()
{
$permissions = static::with('menus')->get()->toArray();
$methods = [];
foreach ($permissions as $permission) {
$controllers = $permission[Config::get('admin.permission_controller')];
if (!empty($controllers)) {
$_controllerArr = explode(';', $controllers);
foreach ($_controllerArr as $str) {
$c = explode('@', $str);
$controller = strtolower($c[0]);
$size = count($c);
if ($size > 1) {
for($i = 1; $i < $size; $i++) {
$method = strtolower($c[$i]);
if (empty($method)) {
$methods[$controller] = $permission;
} else {
$methods[$controller.'@'.$method] = $permission;
}
}
} else {
$methods[$controller] = $permission;
}
}
}
}
return $methods;
}
}

View File

@ -0,0 +1,142 @@
<?php
namespace App\Models\Traits;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Cache;
trait AdminRoleTrait
{
public function cachedPermissions()
{
$rolePrimaryKey = $this->primaryKey;
$cacheKey = 'admin_permissions_for_role_'.$this->$rolePrimaryKey;
return Cache::tags(Config::get('admin.permission_role_table'))->remember($cacheKey, Config::get('cache.ttl'), function () {
return $this->perms()->get();
});
}
public function save(array $options = [])
{ //both inserts and updates
$result = parent::save($options);
Cache::tags(Config::get('admin.permission_role_table'))->flush();
return $result;
}
public function delete(array $options = [])
{ //soft or hard
$result = parent::delete($options);
Cache::tags(Config::get('admin.permission_role_table'))->flush();
return $result;
}
public function restore()
{ //soft delete undo's
$result = parent::restore();
Cache::tags(Config::get('admin.permission_role_table'))->flush();
return $result;
}
/**
* 与用户的多对多关系
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function users()
{
return $this->belongsToMany(Config::get('auth.providers.users.model'), Config::get('admin.role_user_table'),
Config::get('admin.role_foreign_key'),Config::get('admin.user_foreign_key'));
}
/**
* 与权限的多对多关系
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function perms()
{
return $this->belongsToMany(Config::get('admin.permission'), Config::get('admin.permission_role_table'));
}
/**
* 与菜单的多对多关系
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function menus()
{
return $this->belongsToMany(Config::get('admin.menu'), Config::get('admin.menu_role_table'),
Config::get('admin.role_foreign_key'), Config::get('admin.menu_foreign_key'));
}
/**
* 当删除的时候,把角色关系也删除
*
* @return void|bool
*/
public static function boot()
{
parent::boot();
static::deleting(function($role) {
if (!method_exists(Config::get('admin.role'), 'bootSoftDeletes')) {
$role->users()->sync([]);
$role->perms()->sync([]);
$role->menus()->sync([]);
}
return true;
});
}
/**
* 检查是否有权限
*
* @param string|array $name 权限名
* @param bool $requireAll All 是否检查全部权限
*
* @return bool
*/
public function hasPermission($name, $requireAll = false)
{
if (is_array($name)) {
foreach ($name as $permissionName) {
$hasPermission = $this->hasPermission($permissionName);
if ($hasPermission && !$requireAll) {
return true;
} elseif (!$hasPermission && $requireAll) {
return false;
}
}
// If we've made it this far and $requireAll is FALSE, then NONE of the permissions were found
// If we've made it this far and $requireAll is TRUE, then ALL of the permissions were found.
// Return the value of $requireAll;
return $requireAll;
} else {
foreach ($this->cachedPermissions() as $permission) {
if ($permission->name == $name) {
return true;
}
}
}
return false;
}
/**
* 保存权限
*
* @param mixed $inputPermissions
*
* @return void
*/
public function savePermissions($inputPermissions)
{
if (!empty($inputPermissions)) {
$this->perms()->sync($inputPermissions);
} else {
$this->perms()->detach();
}
}
}

View File

@ -0,0 +1,159 @@
<?php
namespace App\Models\Traits;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config;
trait AdminUsersTrait
{
public function cachedRoles()
{
$userPrimaryKey = $this->primaryKey;
$cacheKey = 'admin_roles_for_user_'.$this->$userPrimaryKey;
return Cache::tags(Config::get('admin.role_user_table'))->remember($cacheKey, Config::get('admin.cache.ttl'), function () {
return $this->roles()->get();
});
}
public function save(array $options = [])
{ //both inserts and updates
$result = parent::save($options);
Cache::tags(Config::get('admin.role_user_table'))->flush();
return $result;
}
public function delete(array $options = [])
{ //soft or hard
$result = parent::delete($options);
Cache::tags(Config::get('admin.role_user_table'))->flush();
return $result;
}
public function restore()
{ //soft delete undo's
$result = parent::restore();
Cache::tags(Config::get('admin.role_user_table'))->flush();
return $result;
}
/**
* 与角色的多对多关系
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function roles()
{
return $this->belongsToMany(Config::get('admin.role'), Config::get('admin.role_user_table'),
Config::get('admin.user_foreign_key'), Config::get('admin.role_foreign_key'));
}
/**
* 当删除的时候,把用户关系也删除
*
* @return void|bool
*/
public static function boot()
{
parent::boot();
static::deleting(function($user) {
if (!method_exists(Config::get('auth.providers.users.model'), 'bootSoftDeletes')) {
$user->roles()->sync([]);
}
return true;
});
}
/**
* 检查用户是是否有角色.
*
* @param string|array $name 角色名.
* @param bool $requireAll 是否有全部请求权限
*
* @return bool
*/
public function hasRole($name, $requireAll = false)
{
if (is_array($name)) {
foreach ($name as $roleName) {
$hasRole = $this->hasRole($roleName);
if ($hasRole && !$requireAll) {
return true;
} elseif (!$hasRole && $requireAll) {
return false;
}
}
// If we've made it this far and $requireAll is FALSE, then NONE of the roles were found
// If we've made it this far and $requireAll is TRUE, then ALL of the roles were found.
// Return the value of $requireAll;
return $requireAll;
} else {
foreach ($this->cachedRoles() as $role) {
if ($role->name == $name) {
return true;
}
}
}
return false;
}
/**
* 检查用户是否有权限
*
* @param string|array $permission 权限名
* @param bool $requireAll 是否有全部请求权限
*
* @return bool
*/
public function can($permission, $requireAll = false)
{
if (is_array($permission)) {
foreach ($permission as $permName) {
$hasPerm = $this->can($permName);
if ($hasPerm && !$requireAll) {
return true;
} elseif (!$hasPerm && $requireAll) {
return false;
}
}
// If we've made it this far and $requireAll is FALSE, then NONE of the perms were found
// If we've made it this far and $requireAll is TRUE, then ALL of the perms were found.
// Return the value of $requireAll;
return $requireAll;
} else {
foreach ($this->cachedRoles() as $role) {
// Validate against the Permission table
foreach ($role->cachedPermissions() as $perm) {
if (str_is( $permission, $perm->name) ) {
return true;
}
}
}
}
return false;
}
/**
* 保存角色
*
* @param mixed $roles
*/
public function saveRoles($roles)
{
if (!empty($roles)) {
$this->roles()->sync($roles);
} else {
$this->roles()->detach();
}
}
}

18
app/Models/User.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use App\Models\Interfaces\AdminUsersInterface;
use App\Models\Traits\AdminUsersTrait;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, AdminUsersInterface
{
use Authenticatable, CanResetPassword, AdminUsersTrait;
protected $table = 'admin_users';
protected $fillable = ['username', 'email', 'mobile', 'password'];
protected $hidden = ['password', 'remember_token'];
protected $userInfo;
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
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();
//
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes();
require base_path('routes/channels.php');
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'App\Events\Event' => [
'App\Listeners\EventListener',
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
parent::boot();
//
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
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';
/**
* 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'));
}
}

201
app/Service/DataService.php Normal file
View File

@ -0,0 +1,201 @@
<?php
namespace App\Service;
use App\Models\Admin;
use App\Models\Role;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
class DataService{
public static function handleDate(Model $model, Array $inputs,$kind){
$kind = explode('-',$kind);
switch ($kind[0]){
case 'menus':
switch ($kind[1]){
case 'add_or_update':
$model->parent_id = $inputs['category'];
$model->title = $inputs['name'];
$model->icon = $inputs['icon'];
$model->uri = $inputs['uri'];
$model->order = $inputs['order'];
$model->routes = 'url:'.$inputs['uri'];
$roles = $inputs['roles'];
if($inputs['id']){
if (is_config_id($inputs['id'], "admin.menu_table_cannot_manage_ids", false))return ['status'=>0,'msg'=>trans('fzs.menus.notedit')];
$model->exists = true;
$model->id = $inputs['id'];
}
try{
if (!$model->save()) {
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
foreach ($roles as $k => $role) {
if (empty($role)) unset($roles[$k]);
}
$model->saveRoles($roles);
}catch (\Exception $e){
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
return ['status'=>1,'msg'=>trans('fzs.common.success')];
break;
case 'delete':
$model->id = $inputs['id'];
$model->exists = true;
if($model->delete())return ['status'=>1,'msg'=>trans('fzs.common.success')];
else return ['status'=>0,'msg'=>trans('fzs.common.fail')];
break;
default:
return ['status'=>0,'msg'=>trans('fzs.common.wrong')];
}
break;
case 'users':
switch ($kind[1]){
case 'add_or_update':
$model->username = $inputs['user_name'];
$model->email = $inputs['email'];
$model->mobile = $inputs['tel'];
$model->sex = $inputs['sex'];
if($inputs['pwd'])$model->password = bcrypt($inputs['pwd']);
if($inputs['id']){
if(is_config_id($inputs['id'], "admin.user_table_cannot_manage_ids", false))return ['status'=>0,'msg'=>trans('fzs.users.notedit')];
$model->exists = true;
$model->id = $inputs['id'];
}
try{
if (!$model->save()) {
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
$model->saveRoles($inputs['user_role']);
}catch (\Exception $e){
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
return ['status'=>1,'msg'=>trans('fzs.common.success')];
break;
case 'update_pwd':
$userinfo = new Admin();
$userinfo = $userinfo->user();
if(!App::make('hash')->check($inputs['oldpwd'],$userinfo['password']))return ['status'=>0,'msg'=>trans('fzs.users.pwd_false')];
$model->password = bcrypt($inputs['pwd']);
$model->exists = true;
$model->id = $inputs['id'];
try{
if (!$model->save()) {
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
}catch (\Exception $e){
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
return ['status'=>1,'msg'=>trans('fzs.common.success')];
break;
case 'update_info':
$model->email = $inputs['useremail'];
$model->mobile = $inputs['usertel'];
$model->sex = $inputs['usersex'];
$model->exists = true;
$model->id = $inputs['id'];
try{
if (!$model->save()) {
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
}catch (\Exception $e){
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
return ['status'=>1,'msg'=>trans('fzs.common.success')];
break;
case 'delete':
$model->id = $inputs['id'];
$model->exists = true;
if($model->delete())return ['status'=>1,'msg'=>trans('fzs.common.success')];
else return ['status'=>0,'msg'=>trans('fzs.common.fail')];
break;
default:
return ['status'=>0,'msg'=>trans('fzs.common.wrong')];
}
break;
case 'roles':
switch ($kind[1]){
case 'add_or_update':
$model->name = $inputs['role_remark'];
$model->display_name = $inputs['role_name'];
$model->description = $inputs['role_desc'];
if($inputs['id']){
if(is_config_id($inputs['id'], "admin.role_table_cannot_manage_ids", false))return ['status'=>0,'msg'=>trans('fzs.roles.notedit')];
$model->exists = true;
$model->id = $inputs['id'];
}
try{
if (!$model->save()) {
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
$role = new Role();
$role = $role->find($model->id);
$role->savePermissions(isset($inputs['permission_list'])?$inputs['permission_list']:'');
if (!$role->save()) {
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
}catch (\Exception $e){
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
return ['status'=>1,'msg'=>trans('fzs.common.success')];
break;
case 'delete':
if($model->isAbleDel($inputs['id']))return ['status'=>0,'msg'=>trans('fzs.roles.have_user')];
$model->id = $inputs['id'];
$model->exists = true;
if($model->delete())return ['status'=>1,'msg'=>trans('fzs.common.success')];
else return ['status'=>0,'msg'=>trans('fzs.common.fail')];
break;
default:
return ['status'=>0,'msg'=>trans('fzs.common.wrong')];
}
break;
case 'permissions':
switch ($kind[1]){
case 'add_or_update':
$model->name = $inputs['permission_remark'];
$model->display_name = $inputs['permission_name'];
$model->description = $inputs['permission_desc'];
$model->controllers = $inputs['permission_control'];
if($inputs['id']){
if (is_config_id($inputs['id'], "admin.permission_table_cannot_manage_ids", false))return ['status'=>0,'msg'=>trans('fzs.menus.notedit')];
$model->exists = true;
$model->id = $inputs['id'];
}
try{
if (!$model->save()) {
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
$roles = $inputs['permission_roles'];
if (!empty($roles)) {
foreach ($roles as $k => $role) {
if (empty($role)) unset($roles[$k]);
}
}
$model->saveRoles($roles);
}catch (\Exception $e){
return ['status'=>0,'msg'=>trans('fzs.common.fail')];
}
return ['status'=>1,'msg'=>trans('fzs.common.success')];
break;
case 'delete':
$model->id = $inputs['id'];
$model->exists = true;
if($model->delete())return ['status'=>1,'msg'=>trans('fzs.common.success')];
else return ['status'=>0,'msg'=>trans('fzs.common.fail')];
break;
default:
return ['status'=>0,'msg'=>trans('fzs.common.wrong')];
}
break;
default:
return ['status'=>0,'msg'=>trans('fzs.common.wrong')];
}
}
}

29
app/User.php Normal file
View File

@ -0,0 +1,29 @@
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
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',
];
}

50
app/Utils/UrlUtils.php Normal file
View File

@ -0,0 +1,50 @@
<?php
/**
* User: HUANGXIANG
* Date: 2017-06-26 16:47
*/
namespace App\Utils;
use Request;
class UrlUtils
{
const URL = 'url';
const ACTION = 'action';
const CONTROLLER = 'controller';
const CLASS_NAME = 'class_name';
const CLASS_METHOD = 'class_method';
const METHOD = 'method';
const REAL_METHOD = 'real_method';
public static function toRestfulParams()
{
$params = [];
// 如: App\Http\Controllers\IndexController@getIndex
$action = (Request::route()->getActionName());
// 如: [App\Http\Controllers\IndexController, getIndex]
$tmp = explode("@", $action);
// 如: App\Http\Controllers\IndexController
$controller = $tmp[0];
// 如: getIndex
$classMethod = count($tmp) > 1 ? $tmp[1] : '';
$paths = explode("\\", $controller);
// 如: IndexController
$className = $paths[count($paths) - 1];
// 如: GET | POST | PUT | DELETE , PUT跟DELETE方法可以通过_method参数传
$method = Request::getMethod();
// 如: GET | POST
$realMethod = Request::getRealMethod();
$url = Request::getRequestUri();
$params[static::ACTION] = $action;
$params[static::CONTROLLER] = $controller;
$params[static::CLASS_NAME] = $className;
$params[static::CLASS_METHOD] = $classMethod;
$params[static::METHOD] = $method;
$params[static::REAL_METHOD] = $realMethod;
$params[static::URL] = $url;
return $params;
}
}

51
artisan Normal file
View File

@ -0,0 +1,51 @@
#!/usr/bin/env php
<?php
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);
/*
|--------------------------------------------------------------------------
| Shutdown The Application
|--------------------------------------------------------------------------
|
| Once Artisan has finished running, we will fire off the shutdown events
| so that any final work may be done by the application before we shut
| down the process. This is the last thing to happen to the request.
|
*/
$kernel->terminate($input, $status);
exit($status);

55
bootstrap/app.php Normal file
View File

@ -0,0 +1,55 @@
<?php
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/
return $app;

17
bootstrap/autoload.php Normal file
View File

@ -0,0 +1,17 @@
<?php
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so we do not have to manually load any of
| our application's PHP classes. It just feels great to relax.
|
*/
require __DIR__.'/../vendor/autoload.php';

2
bootstrap/cache/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

55
composer.json Normal file
View File

@ -0,0 +1,55 @@
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"gregwar/captcha": "1.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
},
"files":[
"app/Helpers/functions.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}

49
config/admin.php Normal file
View File

@ -0,0 +1,49 @@
<?php
/**
* Created by PhpStorm.
* User: FZS
* Time: 2018/10/11 11:10
*/
return [
//user
'user_table' => 'admin_users',
'user_table_cannot_manage_ids' => '1',
//role
'role' => 'App\Models\Role',
'role_table' => 'admin_roles',
'role_user_table' => 'admin_role_user',
'role_foreign_key' => 'role_id',
'user_foreign_key' => 'user_id',
'role_admin' => 'admin',
'role_auth_page' => 'errors.role',
'role_table_cannot_manage_ids' => '1',
//permission
'permission' => 'App\Models\Permission',
'permission_table' => 'admin_permissions',
'permission_role_table' => 'admin_permission_role',
'permission_name' => 'name',
'permission_display_name' => 'display_name',
'permission_controller' => 'controllers',
'permission_menu_table' => 'admin_permission_menu',
'permission_foreign_key' => 'permission_id',
'permission_table_cannot_manage_ids' => '1,2,3,4,5,6,7,8,9',
//menu
'menu' => 'App\Models\Menu',
'menu_table' => 'admin_menus',
'menu_role_table' => 'admin_role_menu',
'menu_foreign_key' => 'menu_id',
'menu_table_id_key' => 'id',
'menu_table_parent_id_key' => 'parent_id',
'menu_table_cannot_manage_ids' => '1,2,3,4,5,6,7',
'db_log' => env('DB_LOG', false),
//cache
'admin_permissions_for_role_id' =>'ap_id',
//cannot del
'cannot_del_admin_ids' => '1',
'cannot_del_admin_ids' => '1',
];

231
config/app.php Normal file
View File

@ -0,0 +1,231 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Application Name
|--------------------------------------------------------------------------
|
| This value is the name of your application. This value is used when the
| framework needs to place the application's name in a notification or
| any other location as required by the application or its packages.
*/
'name' => env('APP_NAME', 'Laravel'),
/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| This value determines the "environment" your application is currently
| running in. This may determine how you prefer to configure various
| services your application utilizes. Set this in your ".env" file.
|
*/
'env' => env('APP_ENV', 'production'),
/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/
'debug' => env('APP_DEBUG', false),
/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| your application so that it is used when running Artisan tasks.
|
*/
'url' => env('APP_URL', 'http://localhost'),
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'Asia/Shanghai',
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
'locale' => 'zh',
/*
|--------------------------------------------------------------------------
| Application Fallback Locale
|--------------------------------------------------------------------------
|
| The fallback locale determines the locale to use when the current one
| is not available. You may change the value to correspond to any of
| the language folders that are provided through your application.
|
*/
'fallback_locale' => 'en',
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| This key is used by the Illuminate encrypter service and should be set
| to a random, 32 character string, otherwise these encrypted strings
| will not be safe. Please do this before deploying an application!
|
*/
'key' => env('APP_KEY'),
'cipher' => 'AES-256-CBC',
/*
|--------------------------------------------------------------------------
| Logging Configuration
|--------------------------------------------------------------------------
|
| Here you may configure the log settings for your application. Out of
| the box, Laravel uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Settings: "single", "daily", "syslog", "errorlog"
|
*/
'log' => env('APP_LOG', 'single'),
'log_level' => env('APP_LOG_LEVEL', 'debug'),
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
Illuminate\Hashing\HashServiceProvider::class,
Illuminate\Mail\MailServiceProvider::class,
Illuminate\Notifications\NotificationServiceProvider::class,
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Pipeline\PipelineServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
Illuminate\Redis\RedisServiceProvider::class,
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
Illuminate\Session\SessionServiceProvider::class,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
/*
* Package Service Providers...
*/
Laravel\Tinker\TinkerServiceProvider::class,
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
],
/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/
'aliases' => [
'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
'Blade' => Illuminate\Support\Facades\Blade::class,
'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
'Bus' => Illuminate\Support\Facades\Bus::class,
'Cache' => Illuminate\Support\Facades\Cache::class,
'Config' => Illuminate\Support\Facades\Config::class,
'Cookie' => Illuminate\Support\Facades\Cookie::class,
'Crypt' => Illuminate\Support\Facades\Crypt::class,
'DB' => Illuminate\Support\Facades\DB::class,
'Eloquent' => Illuminate\Database\Eloquent\Model::class,
'Event' => Illuminate\Support\Facades\Event::class,
'File' => Illuminate\Support\Facades\File::class,
'Gate' => Illuminate\Support\Facades\Gate::class,
'Hash' => Illuminate\Support\Facades\Hash::class,
'Lang' => Illuminate\Support\Facades\Lang::class,
'Log' => Illuminate\Support\Facades\Log::class,
'Mail' => Illuminate\Support\Facades\Mail::class,
'Notification' => Illuminate\Support\Facades\Notification::class,
'Password' => Illuminate\Support\Facades\Password::class,
'Queue' => Illuminate\Support\Facades\Queue::class,
'Redirect' => Illuminate\Support\Facades\Redirect::class,
'Redis' => Illuminate\Support\Facades\Redis::class,
'Request' => Illuminate\Support\Facades\Request::class,
'Response' => Illuminate\Support\Facades\Response::class,
'Route' => Illuminate\Support\Facades\Route::class,
'Schema' => Illuminate\Support\Facades\Schema::class,
'Session' => Illuminate\Support\Facades\Session::class,
'Storage' => Illuminate\Support\Facades\Storage::class,
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
],
];

102
config/auth.php Normal file
View File

@ -0,0 +1,102 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],
];

58
config/broadcasting.php Normal file
View File

@ -0,0 +1,58 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Broadcaster
|--------------------------------------------------------------------------
|
| This option controls the default broadcaster that will be used by the
| framework when an event needs to be broadcast. You may set this to
| any of the connections defined in the "connections" array below.
|
| Supported: "pusher", "redis", "log", "null"
|
*/
'default' => env('BROADCAST_DRIVER', 'null'),
/*
|--------------------------------------------------------------------------
| Broadcast Connections
|--------------------------------------------------------------------------
|
| Here you may define all of the broadcast connections that will be used
| to broadcast events to other systems or over websockets. Samples of
| each available type of connection are provided inside this array.
|
*/
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
//
],
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
'null' => [
'driver' => 'null',
],
],
];

91
config/cache.php Normal file
View File

@ -0,0 +1,91 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Cache Store
|--------------------------------------------------------------------------
|
| This option controls the default cache connection that gets used while
| using this caching library. This connection is used when another is
| not explicitly specified when executing a given caching function.
|
| Supported: "apc", "array", "database", "file", "memcached", "redis"
|
*/
'default' => env('CACHE_DRIVER', 'file'),
/*
|--------------------------------------------------------------------------
| Cache Stores
|--------------------------------------------------------------------------
|
| Here you may define all of the cache "stores" for your application as
| well as their drivers. You may even define multiple stores for the
| same cache driver to group types of items stored in your caches.
|
*/
'stores' => [
'apc' => [
'driver' => 'apc',
],
'array' => [
'driver' => 'array',
],
'database' => [
'driver' => 'database',
'table' => 'cache',
'connection' => null,
],
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache/data'),
],
'memcached' => [
'driver' => 'memcached',
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
'sasl' => [
env('MEMCACHED_USERNAME'),
env('MEMCACHED_PASSWORD'),
],
'options' => [
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
],
'servers' => [
[
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
'port' => env('MEMCACHED_PORT', 11211),
'weight' => 100,
],
],
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
],
/*
|--------------------------------------------------------------------------
| Cache Key Prefix
|--------------------------------------------------------------------------
|
| When utilizing a RAM based store such as APC or Memcached, there might
| be other applications utilizing the same cache. So, we'll specify a
| value to get prefixed to all our keys so we can avoid collisions.
|
*/
'prefix' => 'laravel',
];

120
config/database.php Normal file
View File

@ -0,0 +1,120 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];

68
config/filesystems.php Normal file
View File

@ -0,0 +1,68 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Filesystem Disk
|--------------------------------------------------------------------------
|
| Here you may specify the default filesystem disk that should be used
| by the framework. The "local" disk, as well as a variety of cloud
| based disks are available to your application. Just store away!
|
*/
'default' => env('FILESYSTEM_DRIVER', 'local'),
/*
|--------------------------------------------------------------------------
| Default Cloud Filesystem Disk
|--------------------------------------------------------------------------
|
| Many applications store files both locally and in the cloud. For this
| reason, you may specify a default "cloud" driver here. This driver
| will be bound as the Cloud disk implementation in the container.
|
*/
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
/*
|--------------------------------------------------------------------------
| Filesystem Disks
|--------------------------------------------------------------------------
|
| Here you may configure as many filesystem "disks" as you wish, and you
| may even configure multiple disks of the same driver. Defaults have
| been setup for each driver as an example of the required options.
|
| Supported Drivers: "local", "ftp", "s3", "rackspace"
|
*/
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
];

123
config/mail.php Normal file
View File

@ -0,0 +1,123 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Mail Driver
|--------------------------------------------------------------------------
|
| Laravel supports both SMTP and PHP's "mail" function as drivers for the
| sending of e-mail. You may specify which one you're using throughout
| your application here. By default, Laravel is setup for SMTP mail.
|
| Supported: "smtp", "sendmail", "mailgun", "mandrill", "ses",
| "sparkpost", "log", "array"
|
*/
'driver' => env('MAIL_DRIVER', 'smtp'),
/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Mailgun mail service which will provide reliable deliveries.
|
*/
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/
'port' => env('MAIL_PORT', 587),
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/
'sendmail' => '/usr/sbin/sendmail -bs',
/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown based email rendering, you may configure your
| theme and component paths here, allowing you to customize the design
| of the emails. Or, you may simply stick with the Laravel defaults!
|
*/
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];

85
config/queue.php Normal file
View File

@ -0,0 +1,85 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Queue Driver
|--------------------------------------------------------------------------
|
| Laravel's queue API supports an assortment of back-ends via a single
| API, giving you convenient access to each back-end using the same
| syntax for each one. Here you may set the default queue driver.
|
| Supported: "sync", "database", "beanstalkd", "sqs", "redis", "null"
|
*/
'default' => env('QUEUE_DRIVER', 'sync'),
/*
|--------------------------------------------------------------------------
| Queue Connections
|--------------------------------------------------------------------------
|
| Here you may configure the connection information for each server that
| is used by your application. A default configuration has been added
| for each back-end shipped with Laravel. You are free to add more.
|
*/
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'retry_after' => 90,
],
'sqs' => [
'driver' => 'sqs',
'key' => 'your-public-key',
'secret' => 'your-secret-key',
'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id',
'queue' => 'your-queue-name',
'region' => 'us-east-1',
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'retry_after' => 90,
],
],
/*
|--------------------------------------------------------------------------
| Failed Queue Jobs
|--------------------------------------------------------------------------
|
| These options configure the behavior of failed queue job logging so you
| can control which database and table are used to store the jobs that
| have failed. You may change them to any database / table you wish.
|
*/
'failed' => [
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],
];

38
config/services.php Normal file
View File

@ -0,0 +1,38 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Third Party Services
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third party services such
| as Stripe, Mailgun, SparkPost and others. This file provides a sane
| default location for this type of information, allowing packages
| to have a conventional place to find your various credentials.
|
*/
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
'ses' => [
'key' => env('SES_KEY'),
'secret' => env('SES_SECRET'),
'region' => 'us-east-1',
],
'sparkpost' => [
'secret' => env('SPARKPOST_SECRET'),
],
'stripe' => [
'model' => App\User::class,
'key' => env('STRIPE_KEY'),
'secret' => env('STRIPE_SECRET'),
],
];

179
config/session.php Normal file
View File

@ -0,0 +1,179 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Session Driver
|--------------------------------------------------------------------------
|
| This option controls the default session "driver" that will be used on
| requests. By default, we will use the lightweight native driver but
| you may specify any of the other wonderful drivers provided here.
|
| Supported: "file", "cookie", "database", "apc",
| "memcached", "redis", "array"
|
*/
'driver' => env('SESSION_DRIVER', 'file'),
/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/
'lifetime' => 120,
'expire_on_close' => false,
/*
|--------------------------------------------------------------------------
| Session Encryption
|--------------------------------------------------------------------------
|
| This option allows you to easily specify that all of your session data
| should be encrypted before it is stored. All encryption will be run
| automatically by Laravel and you can use the Session like normal.
|
*/
'encrypt' => false,
/*
|--------------------------------------------------------------------------
| Session File Location
|--------------------------------------------------------------------------
|
| When using the native session driver, we need a location where session
| files may be stored. A default has been set for you but a different
| location may be specified. This is only needed for file sessions.
|
*/
'files' => storage_path('framework/sessions'),
/*
|--------------------------------------------------------------------------
| Session Database Connection
|--------------------------------------------------------------------------
|
| When using the "database" or "redis" session drivers, you may specify a
| connection that should be used to manage these sessions. This should
| correspond to a connection in your database configuration options.
|
*/
'connection' => null,
/*
|--------------------------------------------------------------------------
| Session Database Table
|--------------------------------------------------------------------------
|
| When using the "database" session driver, you may specify the table we
| should use to manage the sessions. Of course, a sensible default is
| provided for you; however, you are free to change this as needed.
|
*/
'table' => 'sessions',
/*
|--------------------------------------------------------------------------
| Session Cache Store
|--------------------------------------------------------------------------
|
| When using the "apc" or "memcached" session drivers, you may specify a
| cache store that should be used for these sessions. This value must
| correspond with one of the application's configured cache stores.
|
*/
'store' => null,
/*
|--------------------------------------------------------------------------
| Session Sweeping Lottery
|--------------------------------------------------------------------------
|
| Some session drivers must manually sweep their storage location to get
| rid of old sessions from storage. Here are the chances that it will
| happen on a given request. By default, the odds are 2 out of 100.
|
*/
'lottery' => [2, 100],
/*
|--------------------------------------------------------------------------
| Session Cookie Name
|--------------------------------------------------------------------------
|
| Here you may change the name of the cookie used to identify a session
| instance by ID. The name specified here will get used every time a
| new session cookie is created by the framework for every driver.
|
*/
'cookie' => 'laravel_session',
/*
|--------------------------------------------------------------------------
| Session Cookie Path
|--------------------------------------------------------------------------
|
| The session cookie path determines the path for which the cookie will
| be regarded as available. Typically, this will be the root path of
| your application but you are free to change this when necessary.
|
*/
'path' => '/',
/*
|--------------------------------------------------------------------------
| Session Cookie Domain
|--------------------------------------------------------------------------
|
| Here you may change the domain of the cookie used to identify a session
| in your application. This will determine which domains the cookie is
| available to in your application. A sensible default has been set.
|
*/
'domain' => env('SESSION_DOMAIN', null),
/*
|--------------------------------------------------------------------------
| HTTPS Only Cookies
|--------------------------------------------------------------------------
|
| By setting this option to true, session cookies will only be sent back
| to the server if the browser has a HTTPS connection. This will keep
| the cookie from being sent to you if it can not be done securely.
|
*/
'secure' => env('SESSION_SECURE_COOKIE', false),
/*
|--------------------------------------------------------------------------
| HTTP Access Only
|--------------------------------------------------------------------------
|
| Setting this value to true will prevent JavaScript from accessing the
| value of the cookie and the cookie will only be accessible through
| the HTTP protocol. You are free to modify this option if needed.
|
*/
'http_only' => true,
];

33
config/view.php Normal file
View File

@ -0,0 +1,33 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| View Storage Paths
|--------------------------------------------------------------------------
|
| Most templating systems load templates from disk. Here you may specify
| an array of paths that should be checked for your views. Of course
| the usual Laravel view path has already been registered for you.
|
*/
'paths' => [
resource_path('views'),
],
/*
|--------------------------------------------------------------------------
| Compiled View Path
|--------------------------------------------------------------------------
|
| This option determines where all the compiled Blade templates will be
| stored for your application. Typically, this is within the storage
| directory. However, as usual, you are free to change this value.
|
*/
'compiled' => realpath(storage_path('framework/views')),
];

1
database/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.sqlite

View File

@ -0,0 +1,23 @@
<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(App\User::class, function (Faker\Generator $faker) {
static $password;
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
];
});

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateAdminUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_users', function(Blueprint $table)
{
$table->increments('id')->comment('ID');
$table->string('username')->unique('users_username_unique')->comment('用户名');
$table->string('email')->unique('users_email_unique')->comment('邮件');
$table->string('mobile', 11)->nullable()->comment('手机号码');
$table->smallInteger('sex')->default(1)->comment('性别');
$table->string('password', 60)->comment('密码');
$table->string('remember_token', 100)->nullable()->comment('TOKEN');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('admin_users');
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateAdminRolesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_roles', function(Blueprint $table)
{
$table->increments('id')->comment('ID');
$table->string('name')->unique('roles_name_unique')->comment('角色名');
$table->string('display_name')->nullable()->comment('显示名');
$table->string('description')->nullable()->comment('描述');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('admin_roles');
}
}

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateAdminLogsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_logs', function(Blueprint $table)
{
$table->integer('id', true)->comment('ID');
$table->integer('admin_id')->comment('用户ID');
$table->string('log_url', 128)->nullable()->comment('URL');
$table->string('log_ip', 20)->nullable()->comment('ip');
$table->string('log_info', 100)->nullable()->comment('描述');
$table->datetime('log_time')->nullable()->comment('日志日期');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('admin_logs');
}
}

View File

@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateAdminMenusTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_menus', function(Blueprint $table)
{
$table->increments('id');
$table->integer('parent_id')->default(0)->comment('上级ID');
$table->integer('order')->default(0)->comment('菜单排序');
$table->string('title', 50)->nullable()->comment('标题');
$table->string('icon', 50)->comment('图标');
$table->string('uri', 50)->comment('URI');
$table->string('routes', 256)->nullable()->comment('路由,如url:/menu,controller:MenuController');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('admin_menus');
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateAdminPermissionMenuTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_permission_menu', function(Blueprint $table)
{
$table->integer('permission_id');
$table->integer('menu_id');
$table->index(['permission_id','menu_id'], 'permission_menu_permission_id_menu_id_index');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('admin_permission_menu');
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateAdminPermissionRoleTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_permission_role', function(Blueprint $table)
{
$table->integer('permission_id')->unsigned();
$table->integer('role_id')->unsigned()->index('permission_role_role_id_foreign');
$table->primary(['permission_id','role_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('admin_permission_role');
}
}

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateAdminPermissionsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_permissions', function(Blueprint $table)
{
$table->increments('id')->comment('ID');
$table->string('name')->unique('permissions_name_unique')->comment('权限名 英文');
$table->string('display_name')->nullable()->comment('显示名 中文');
$table->string('description')->nullable()->comment('描述');
$table->string('controllers', 512)->nullable()->comment('对应的controllers');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('admin_permissions');
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateAdminRoleMenuTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_role_menu', function(Blueprint $table)
{
$table->integer('role_id');
$table->integer('menu_id');
$table->index(['role_id','menu_id'], 'role_menu_role_id_menu_id_index');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('admin_role_menu');
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateAdminRoleUserTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_role_user', function(Blueprint $table)
{
$table->integer('user_id')->unsigned();
$table->integer('role_id')->unsigned()->index('role_user_role_id_foreign');
$table->primary(['user_id','role_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('admin_role_user');
}
}

1
database/seeds/.gitkeep Normal file
View File

@ -0,0 +1 @@

View File

@ -0,0 +1,104 @@
<?php
use Illuminate\Database\Seeder;
class AdminMenusTableSeeder extends Seeder
{
/**
* Auto generated seed file
*
* @return void
*/
public function run()
{
\DB::table('admin_menus')->delete();
\DB::table('admin_menus')->insert(array (
0 =>
array (
'id' => 1,
'parent_id' => 0,
'order' => 4,
'title' => '权限设置',
'icon' => '&#xe614;',
'uri' => 'url:/qx',
'routes' => 'url:',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
1 =>
array (
'id' => 2,
'parent_id' => 1,
'order' => 5,
'title' => '用户管理',
'icon' => '&#xe612;',
'uri' => '/users',
'routes' => 'url:/users',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
2 =>
array (
'id' => 3,
'parent_id' => 1,
'order' => 6,
'title' => '角色管理',
'icon' => '&#xe631;',
'uri' => '/roles',
'routes' => 'url:/roles',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
3 =>
array (
'id' => 4,
'parent_id' => 1,
'order' => 7,
'title' => '权限管理',
'icon' => '&#xe629;',
'uri' => '/permissions',
'routes' => 'url:/permissions',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
4 =>
array (
'id' => 5,
'parent_id' => 1,
'order' => 8,
'title' => '菜单管理',
'icon' => '&#xe62a;',
'uri' => '/menus',
'routes' => 'url:/menus',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
5 =>
array (
'id' => 6,
'parent_id' => 0,
'order' => 1,
'title' => '日志设置',
'icon' => '&#xe632;',
'uri' => '/log',
'routes' => 'url:',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
6 =>
array (
'id' => 7,
'parent_id' => 6,
'order' => 2,
'title' => '日志管理',
'icon' => '&#xe621;',
'uri' => '/logs',
'routes' => 'url:/logs',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
)
);
}
}

View File

@ -0,0 +1,64 @@
<?php
use Illuminate\Database\Seeder;
class AdminPermissionMenuTableSeeder extends Seeder
{
/**
* Auto generated seed file
*
* @return void
*/
public function run()
{
\DB::table('admin_permission_menu')->delete();
\DB::table('admin_permission_menu')->insert(array(
0 =>
array(
'permission_id' => 1,
'menu_id' => 2,
),
1 =>
array(
'permission_id' => 2,
'menu_id' => 2,
),
2 =>
array(
'permission_id' => 3,
'menu_id' => 3,
),
3 =>
array(
'permission_id' => 4,
'menu_id' => 3,
),
4 =>
array(
'permission_id' => 5,
'menu_id' => 4,
),
5 =>
array(
'permission_id' => 6,
'menu_id' => 4,
),
6 =>
array(
'permission_id' => 7,
'menu_id' => 5,
),
7 =>
array(
'permission_id' => 8,
'menu_id' => 5,
),
8 =>
array(
'permission_id' => 9,
'menu_id' => 7,
)
));
}
}

View File

@ -0,0 +1,66 @@
<?php
use Illuminate\Database\Seeder;
class AdminPermissionRoleTableSeeder extends Seeder
{
/**
* Auto generated seed file
*
* @return void
*/
public function run()
{
\DB::table('admin_permission_role')->delete();
\DB::table('admin_permission_role')->insert(array(
0 =>
array(
'permission_id' => 1,
'role_id' => 1,
),
1 =>
array(
'permission_id' => 2,
'role_id' => 1,
),
2 =>
array(
'permission_id' => 3,
'role_id' => 1,
),
3 =>
array(
'permission_id' => 4,
'role_id' => 1,
),
4 =>
array(
'permission_id' => 5,
'role_id' => 1,
),
5 =>
array(
'permission_id' => 6,
'role_id' => 1,
),
6 =>
array(
'permission_id' => 7,
'role_id' => 1,
),
7 =>
array(
'permission_id' => 8,
'role_id' => 1,
),
8 =>
array(
'permission_id' => 9,
'role_id' => 1,
)
));
}
}

View File

@ -0,0 +1,109 @@
<?php
use Illuminate\Database\Seeder;
class AdminPermissionsTableSeeder extends Seeder
{
/**
* Auto generated seed file
*
* @return void
*/
public function run()
{
\DB::table('admin_permissions')->delete();
\DB::table('admin_permissions')->insert(array(
0 =>
array(
'id' => 1,
'name' => 'userlist',
'display_name' => '用户管理查看',
'description' => '用户管理查看',
'controllers' => 'UserController@get',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
1 =>
array(
'id' => 2,
'name' => 'userhandle',
'display_name' => '用户管理编辑',
'description' => '用户管理编辑',
'controllers' => 'UserController@post',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
2 =>
array(
'id' => 3,
'name' => 'rolelist',
'display_name' => '角色管理查看',
'description' => '角色管理查看',
'controllers' => 'RoleController@get',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
3 =>
array(
'id' => 4,
'name' => 'rolehandle',
'display_name' => '角色管理编辑',
'description' => '角色管理编辑',
'controllers' => 'RoleController@post',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
4 =>
array(
'id' => 5,
'name' => 'perlist',
'display_name' => '权限管理查看',
'description' => '权限管理查看',
'controllers' => 'PermissionController@get',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
5 =>
array(
'id' => 6,
'name' => 'perhandle',
'display_name' => '权限管理编辑',
'description' => '权限管理编辑',
'controllers' => 'PermissionController@post',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
6 =>
array(
'id' => 7,
'name' => 'menulist',
'display_name' => '菜单管理查看',
'description' => '菜单管理查看',
'controllers' => 'MenuController@get',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
7 =>
array(
'id' => 8,
'name' => 'menuhandle',
'display_name' => '菜单管理编辑',
'description' => '菜单管理编辑',
'controllers' => 'MenuController@post',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
8 =>
array(
'id' => 9,
'name' => 'loglist',
'display_name' => '日志管理查看',
'description' => '日志管理查看',
'controllers' => 'LogController@get',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
)
));
}
}

View File

@ -0,0 +1,54 @@
<?php
use Illuminate\Database\Seeder;
class AdminRoleMenuTableSeeder extends Seeder
{
/**
* Auto generated seed file
*
* @return void
*/
public function run()
{
\DB::table('admin_role_menu')->delete();
\DB::table('admin_role_menu')->insert(array(
0 =>
array(
'role_id' => 1,
'menu_id' => 1,
),
1 =>
array(
'role_id' => 1,
'menu_id' => 2,
),
2 =>
array(
'role_id' => 1,
'menu_id' => 3,
),
3 =>
array(
'role_id' => 1,
'menu_id' => 4,
),
4 =>
array(
'role_id' => 1,
'menu_id' => 5,
),
5 =>
array(
'role_id' => 1,
'menu_id' => 6,
),
6 =>
array(
'role_id' => 1,
'menu_id' => 7,
)
));
}
}

View File

@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Seeder;
class AdminRoleUserTableSeeder extends Seeder
{
/**
* Auto generated seed file
*
* @return void
*/
public function run()
{
\DB::table('admin_role_user')->delete();
\DB::table('admin_role_user')->insert(array(
0 =>
array(
'user_id' => 1,
'role_id' => 1,
),
));
}
}

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Seeder;
class AdminRolesTableSeeder extends Seeder
{
/**
* Auto generated seed file
*
* @return void
*/
public function run()
{
\DB::table('admin_roles')->delete();
\DB::table('admin_roles')->insert(array(
0 =>
array(
'id' => 1,
'name' => 'admin',
'display_name' => '超级管理员',
'description' => '最高级的权限',
'created_at' => date('Y-m-d H:i:s', time()),
'updated_at' => date('Y-m-d H:i:s', time()),
),
));
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Seeder;
class AdminUsersTableSeeder extends Seeder
{
/**
* Auto generated seed file
*
* @return void
*/
public function run()
{
\DB::table('admin_users')->delete();
\DB::table('admin_users')->insert(array (
0 =>
array (
'id' => 1,
'username' => 'admin',
'email' => 'admin@admin.com',
'mobile' => '18888888888',
'sex' => 1,
'password' => '$2y$10$0nZ2IJJQzkuwTUvmsxVCYOAFw09sGceAk5b9p.AQ.h7I0YEj975rO', //f123456
'remember_token' => '',
'created_at' => date('Y-m-d H:i:s',time()),
'updated_at' => date('Y-m-d H:i:s',time()),
),
)
);
}
}

View File

@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(AdminUsersTableSeeder::class);
$this->call(AdminMenusTableSeeder::class);
$this->call(AdminRolesTableSeeder::class);
$this->call(AdminPermissionsTableSeeder::class);
$this->call(AdminRoleUserTableSeeder::class);
$this->call(AdminRoleMenuTableSeeder::class);
$this->call(AdminPermissionMenuTableSeeder::class);
$this->call(AdminPermissionRoleTableSeeder::class);
}
}

View File

@ -0,0 +1,9 @@
CREATE TABLE `admin_logs` (
`id` bigint(16) unsigned NOT NULL AUTO_INCREMENT COMMENT '表id',
`admin_id` int(10) DEFAULT NULL COMMENT '管理员id',
`log_info` varchar(255) DEFAULT NULL COMMENT '日志描述',
`log_ip` varchar(30) DEFAULT NULL COMMENT 'ip地址',
`log_url` varchar(50) DEFAULT NULL COMMENT 'url',
`log_time` datetime DEFAULT NULL COMMENT '日志时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '后台日志表';

View File

@ -0,0 +1,12 @@
CREATE TABLE `admin_menus` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int(11) NOT NULL DEFAULT '0' COMMENT '上级ID',
`order` int(11) NOT NULL DEFAULT '0' COMMENT '菜单排序,从1开始,数字越小排在超前,0为排在最后',
`title` varchar(50) DEFAULT NULL COMMENT '标题',
`icon` varchar(50) NOT NULL COMMENT '图标',
`uri` varchar(50) NOT NULL COMMENT 'URI',
`routes` varchar(256) DEFAULT NULL COMMENT '路由,如url:/menu,controller:MenuController',
`created_at` timestamp NULL DEFAULT '0000-00-00 00:00:00' COMMENT '创建时间',
`updated_at` timestamp NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '菜单表';

View File

@ -0,0 +1,5 @@
CREATE TABLE `admin_permission_menu` (
`permission_id` int(11) NOT NULL,
`menu_id` int(11) NOT NULL,
KEY `permission_menu_permission_id_menu_id_index` (`permission_id`,`menu_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,6 @@
CREATE TABLE `admin_permission_role` (
`permission_id` int(10) unsigned NOT NULL,
`role_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`permission_id`,`role_id`),
KEY `permission_role_role_id_foreign` (`role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
CREATE TABLE `admin_permissions` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`name` varchar(255) NOT NULL COMMENT '权限标识 英文',
`display_name` varchar(255) DEFAULT NULL COMMENT '权限名称 中文',
`description` varchar(255) DEFAULT NULL COMMENT '权限描述',
`controllers` varchar(512) DEFAULT NULL COMMENT '对应的controllers',
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '创建时间',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `permissions_name_unique` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,5 @@
CREATE TABLE `admin_role_menu` (
`role_id` int(11) NOT NULL,
`menu_id` int(11) NOT NULL,
KEY `role_menu_role_id_menu_id_index` (`role_id`,`menu_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,6 @@
CREATE TABLE `admin_role_user` (
`user_id` int(10) unsigned NOT NULL,
`role_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`user_id`,`role_id`),
KEY `role_user_role_id_foreign` (`role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,10 @@
CREATE TABLE `admin_roles` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`name` varchar(255) NOT NULL COMMENT '角色标识',
`display_name` varchar(255) DEFAULT NULL COMMENT '角色名称',
`description` varchar(255) DEFAULT NULL COMMENT '角色描述',
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '创建时间',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '修改时间',
PRIMARY KEY (`id`),
UNIQUE KEY `roles_name_unique` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '角色表';

View File

@ -0,0 +1,14 @@
CREATE TABLE `admin_users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`username` varchar(255) NOT NULL COMMENT '用户名',
`email` varchar(255) NOT NULL COMMENT '邮件',
`mobile` varchar(11) DEFAULT NULL COMMENT '手机号码',
`sex` smallint(3) NOT NULL DEFAULT 1 COMMENT '性别, 1为男,2为女',
`password` varchar(60) NOT NULL COMMENT '密码',
`remember_token` varchar(100) DEFAULT NULL COMMENT 'TOKEN',
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '创建时间',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '修改时间',
PRIMARY KEY (`id`),
UNIQUE KEY `users_username_unique` (`username`),
UNIQUE KEY `users_email_unique` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '管理用户表';

BIN
img/index.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
img/log.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

BIN
img/m-index.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
img/m-log.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Some files were not shown because too many files have changed in this diff Show More