1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\Config;
- use Illuminate\Support\Facades\Schema;
- class BaseController extends Controller
- {
- const SUCCESS_MSG = '操作成功';
- const ERROR_MSG = '操作失败';
- public function __construct()
- {
- $this->middleware('auth'); // 验证登录
- }
- // Admin response redirect
- protected function response($msg = self::SUCCESS_MSG, $status = 'success', $callback = '', $redirect = '', array $data = []) {
- $request = request();
- if ($request->wantsJson() || $request->ajax()) {
- if ($status == 'success' && empty($redirect)) {
- $redirect = '';
- }
- return response()->json([
- 'status' => $status,
- 'message' => $msg,
- 'redirect' => $redirect,
- 'callback' => $callback,
- 'data' => $data
- ]);
- } else {
- return redirect()->back()->withErrors($msg)->withInput();
- }
- }
- }
|