I am new to laravel and I am trying to load header, footer and the view file from controller in a common template and display the data from controller in the view file. But I am get error View ['admin.dashboard'] not found.
The dashboard file is present in admin folder inside views
controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class common extends Controller
{
public function login()
{
$data['title'] = 'Dashboard';
$data['template'] = 'admin/dashboard';
return view('common_template', compact('data'));
}
}
common_template.blade View
<?php echo View::make('includes/header'); ?>
<?php echo $template = "'".$data['template']."'";
echo View::make($template); ?>
<?php echo View::make('includes/footer'); ?>
When I add 'admin/dashboard' instead of $data['template']
directly in $template
it loads the dashboard file whereas it doesnt load when i pass it as string from controller.
dashboard.blade view
<p><?php echo $data['title']; ?></p> //printing the data from the controller
Kindly help me get through this. Thanks
To include blade template into another template, use @include
:
@include('admin.dashboard')
Or
@include($data['template']) // This should be the name of template, like 'admin.dashboard', but not path
Also, check if view has correct name and is in right directory:
resources/views/admin/dashboard.blade.php
First of all your code require correction as per the laravel blade code standard. Try below code:
common_template.blade View
@include('includes.header')
@yield('content')
@include('includes.footer')
dashboard.blade view
@extends('common_template')
@section('content')
{{$data['title']}}
@endsection
To include blade template into another template,
layouts/index.blade.php
<head>
<!-- Site Title -->
<title>{{ $title }}</title> //dynamic title
<link rel="stylesheet" href="{{ asset('website/css/main.css') }}">
@stack('css') //internal css
</head>
<body>
@include('../website/layouts/header')//include header
@yield('content')//include content
@include('../website/layouts/footer') //include footer
<!-- start footer Area -->
<!-- End footer Area -->
<script src="{{asset('website/js/vendor/jquery-2.2.4.min.js ') }}"></script>
@stack('js')//internal js
</body>
</html>
layouts/footer.blade.php
// footer code
<h1>This area for footer code
layouts/header.blade.php
// headercode
<h1>This area for headercode
/home.blade.php
<?php $title = "dynamic title"; ?> //title
@extends('layouts/index') //include index page
@Push('css') // this is for internal js
*{
color:black;
}
@endpush
@section('content') //section for content
This area for home page content
@stop // content ended
@Push('js') // this is for internal js
<script>
$(document).ready(function(){
var loggedIn={!! json_encode(Auth::check()) !!};
$('.send').click(function() {
if(!loggedIn){
moda.style.display = "block";
return false;
}
});
});
@endpush