模仿 TP5 写了 error 和 success 方法
<?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;
use Illuminate\Http\Exceptions\HttpResponseException;
use Auth;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected function dispatch_success_tmpl() {
return 'jump.dispatch_jump';
}
protected function dispatch_error_tmpl() {
return 'jump.dispatch_jump';
}
// 操作成功跳转的快捷方法
protected function success($msg = '', $url = null, $data = '', $wait = 3, array $header = []) {
session()->flash('success', $msg);
if (is_null($url)) {
$url = url()->previous();
}
$result = [
'code' => 1,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
if(request()->ajax()) {
$response = response()->json($result)->withHeaders($header);
} else {
$response = response()->view($this->dispatch_success_tmpl(), $result)->withHeaders($header);
}
throw new HttpResponseException($response);
}
// 操作失败跳转的快捷方法
protected function error($msg = '', $url = null, $data = '', $wait = 3, array $header = []) {
session()->flash('warning', $msg);
if (is_null($url)) {
$url = request()->ajax() ? '' : 'javascript:history.back(-1);';
}
$result = [
'code' => 0,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
if(request()->ajax()) {
$response = response()->json($result)->withHeaders($header);
} else {
$response = response()->view($this->dispatch_error_tmpl(), $result)->withHeaders($header);
}
throw new HttpResponseException($response);
}
public function _logout() {
Auth::logout();
session()->flash('success', '您已成功退出');
return redirect('login');
}
}
请问jump.dispatch_jump文件怎么写呢?还有这个方法具体怎么调用呢