dou6577 2016-12-14 16:45
浏览 49
已采纳

使用()laravel的未定义方法

I am trying to call a view from a middleware, but I am getting this error:

Call to undefined method Illuminate\Http\Response::with()

Middleware

<?php

namespace App\Http\Middleware;

use Closure;
use App\Models\Readdb;

class Adminlogin {

    public function handle($request, Closure $next) {
        if (!$request->session()->has('userid')) {
            $db = new Readdb();
            $admin_theme = $db::get_setting('admin_theme');
            $data = array(
                'title' => 'My App yo',
                'Description' => 'This is New Application',
                'author' => 'foo'
            );

            return response()->view('admin.auth.login')->with($data);
        } else {
            return response()->view('admin.dash');
        }
        return $next($request);
    }

}

View File

{{Session::get('name')}}
  • 写回答

1条回答 默认 最新

  • duanshan3065 2016-12-14 16:51
    关注

    You shouldn't use with() with response(), do it like this:

    return view('admin.auth.login')->with($data);
    

    For reference - see Laravel Response Redirects with Views

    Hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c51单片机控制步进电机
  • ¥20 Visual studio无法检测到设备
  • ¥15 为什么我通过html绘制的SVG折线图插入到word中坐标轴不显示出来
  • ¥30 vue 页面窗口放大或者缩小元素会变化
  • ¥15 questasim仿真报错
  • ¥15 寻找电脑攻防的导师,有问题请教一下。
  • ¥20 微信同是win11,我的电脑安装不了pageoffice,一直无法打开
  • ¥15 这个界面我通过postman请求不到,但是通过浏览器可以正常访问
  • ¥15 多目标优化算法在与其他算法数据对比结果判断
  • ¥15 CPTN和EAST,主干网络是VGG16,请问在ICDAR2015数据集上训练之后,CPTN和EAST模型的大小为多少