做一个laravel框架下的系统日志(php)
简要说明
做一个系统日志,要求主界面可以清晰显示出什么时间对此系统做了什么样的操作;同时可以根据日志类型,操作时间,操作人等关键字查询日志。
大概操作为:
1、做出界面view显示—通过新建路由,转到控制器,控制器写下方法,转到视图。
2、同步日志数据—通过新建路由,转到控制器,控制器写下方法,转到服务器Services,最终在public/js下新建.js文件,完成数据同步。
第一步:新建目录下系统日志
在/config/menus.php目录下新增代码:
herf指向其链接的HTML
[
'key' => 'system_log',
'title' => '系统日志',
'active' => '',
'icon' => 'flaticon-open-box',
'href' => '/manager/system_operation_log/index.html',
'item' => []
]
新建路由
此处新建两个路由,一个为视图路由,一个为服务器同步路由;
两个路由在一个控制器下,写不同的方法。
代码为:
//系统日志
Route::get('system_operation_log/index.html', 'Manager\SystemOperationLogController@index')->middleware('auth:system_log');
Route::post('system_operation_log/inquire.html', 'Manager\SystemOperationLogController@inquire')->middleware('auth:system_log');
转到控制器
新建控制器:
SystemOperationLogController.php
控制器内书写代码:
<?php
namespace App\Http\Controllers\Manager;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Services\SystemOperationLogService;
/**
* 系统日志
*/
class SystemOperationLogController extends Controller
{
private $_system_operation_log_service;
/**
* 构造函数
* @param SystemOperationLogService systemOperationLogService [description]
*/
function __construct(SystemOperationLogService $systemOperationLogService) {
$this->_system_operation_log_service = $systemOperationLogService;
}
/**
* 首页视图
* @param Request $request [description]
* @return [type] [description]
*/
public function index(Request $request) {
return view('manager.system_operation_log.index');
}
/**
* 查询数据
* @param Request $request [description]
* @return [type] [description]
*/
public function inquire(Request $request) {
return response()->json($this->_system_operation_log_service->inquire($request));
}
}
转到第一个首页视图方法对应view
新建php文件
view/manager/system_operation_log/index.blade.php
代码:
@extends('manager.layouts.manager')
@section('content')
<div class="alert alert-info" role="alert">
<ul class="m-subheader__breadcrumbs m-nav m-nav--inline">
<a href="/manager/index.html" class="m-nav__link m-nav__link--icon">
<i class="m-nav__link-icon la la-home"></i>
</a>
<strong>首页 / 系统设置 / 系统日志</strong>
</ul>
</div>
<div class="m-portlet m-portlet--mobile" id="app_body">
<div class="m-portlet__head">
<div class="m-stack m-stack--ver m-stack--general">
<div class="m-stack__item m-stack__item--center m-stack__item--middle" style="width: 150px;">
<select class="form-control m-input" v-model="inquire_model.type">
<option value="">日志类型</option><