使用()laravel的未定义方法

时间:2016-12-14 16:45:23

标签: php laravel laravel-5

我试图从中间件调用一个视图,但是我收到了这个错误:

  

调用未定义的方法Illuminate \ Http \ Response :: with()

中间件

<?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);
    }

}

查看文件

{{Session::get('name')}}

1 个答案:

答案 0 :(得分:1)

您不应将with()response()一起使用,请执行以下操作:

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

供参考 - 请参阅Laravel Response Redirects with Views

希望这有帮助!