0

I am just learning laravel and now I am trying to pass data to a view.. but its not passing everytime it gives error:

View [layouts.{{$admin_theme}}.admin.admin] not found.

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');

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

}

and this is view:

@extends('layouts.{{$admin_theme}}.admin.admin')
@section('title', 'Mangement Login Area')

Route web.php

Route::get('/auth', function () {
//    This is for admin login. We'll varify if admin is already logged in or not.. if yes, then, we'll redirect.
//    We'll verify it using a middleware adminlogin.
})->middleware('adminlogin');
2
  • What file extension your view file has, it should be viewname.blade.php. Commented Dec 13, 2016 at 19:17
  • yes login.blade.php Commented Dec 13, 2016 at 19:23

1 Answer 1

1

{{ and }} are for use inside HTML (or the output sections of the template). When using variables inside Blade constructs, use them like you would with PHP:

@extends('layouts.' . $admin_theme . '.admin.admin')
Sign up to request clarification or add additional context in comments.

8 Comments

Ok, so now you're actually getting an issue with passing data to the views. Before, you were evaluating {{$admin_theme}} as a string.
any idea plz what to do ! :(
You don't have to concat, it is enough to put something like this: @extends("layouts.$admin_theme.admin.admin"), note the double quote, the variables inside of that kind of string are evaluated and converted to string automatically.
Can you post the views directory?, a screenshot or something like that
not getting what you want me to post.. and still getting same error: Undefined variable: admin_theme (View: /var/www/html/ecommerce/resources/views/admin/auth/login.blade.php)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.