Haren Sarma
Haren Sarma

Reputation: 2553

undefined method with() 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')}}

Upvotes: 0

Views: 230

Answers (1)

Saumya Rastogi
Saumya Rastogi

Reputation: 13693

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!

Upvotes: 1

Related Questions