你们是怎么来控制页面跳转的?

在Laravel中没有像tp5这样的succcess或error这样的方法。感觉有点麻烦
每次写respnse是有点麻烦了,我自己有封装一个

<?php
namespace App\Traits\Controllers;
use Illuminate\Http\Exceptions\HttpResponseException;

trait Jump
{
    protected function _dispatch_success_tmpl() {

        if (request()->is('admin/*')) {
            return 'admin.jumps.cpmsg';
        }

        return 'jumps.dispatch_jump';
    }

    protected function _dispatch_error_tmpl() {

        if (request()->is('admin/*')) {
            return 'admin.jumps.cpmsg';
        }

        return 'jumps.dispatch_jump';
    }

    protected function success($message = '', $url = null, $data = '', $wait = 3, array $header = []) {

        if (is_null($url)) {
            $url = url()->previous();
        }

        $result = [
            'message'  => $message,
            'data'     => $data,
            'url'      => $url,
            'wait'     => $wait,
            'code'     => 1,
        ];

        if(request()->ajax()) {
            $response = response()->json($result, 200)->withHeaders($header);
        } else {
            $response = response()->view($this->_dispatch_success_tmpl(), $result)->withHeaders($header);
        }

        throw new HttpResponseException($response);
    }

    protected function error($message = '', $url = null, $data = '', $wait = 15, array $header = []) {

        if (is_null($url)) {
            $url = request()->ajax() ? '' : 'javascript:history.back(-1);';
        }

        $result = [
            'message'  => $message,
            'data'     => $data,
            'url'      => $url,
            'wait'     => $wait,
            'code'     => 0,
        ];

        if(request()->ajax()) {
            $response = response()->json($result, 422)->withHeaders($header);
        } else {
            $response = response()->view($this->_dispatch_error_tmpl(), $result)->withHeaders($header);
        }

        throw new HttpResponseException($response);
    }
}

使用方法

class UsersController extends BackendController
{
    public function index(Request $request) {
        $type = request()->has('type') ? request()->input('type') : '';
        $user = new User();
        $list = $user->withOrder($this->orderBy())->withSearch($this->keywords(), $type)->paginate();
        return view('admin.users.index', compact('list'));
    }

    public function destroy(User $user) {
        $user->delete() && $this->success('用户删除成功');
    }
}

我后台的模板弄得很漂亮,但是前台就没有了。有没有这种通用的插件,如果有直接用比较方便??

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!