Laravel - Download shared header and footer to view

I am new to laravel and I am trying to load the header, footer and view file from the controller into a common template and display the data from the controller in a view file. But I get an errorView ['admin.dashboard'] not found.

Toolbar 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 to $template, it loads the dashboard file, whereas it does not load when I pass it as a string from the controller.

dashboard.blade view

<p><?php echo $data['title']; ?></p> //printing the data from the controller

Please help me get through this. Thanks

+5
source share
4

, @include:

@include('admin.dashboard')

@include($data['template']) // This should be the name of template, like 'admin.dashboard', but not path

, :

resources/views/admin/dashboard.blade.php
+4

, . :
common_template.blade View

@include('includes.header')

@yield('content')

@include('includes.footer')

dashboard.blade view

@extends('common_template')

@section('content')
    {{$data['title']}}
@endsection
+1

Try this, replace the common_template.blade code below with the code shown.

<?php echo View::make('includes/header'); ?>
<?php echo View::make($template) ?> 
<?php echo View::make('includes/footer'); ?>

or

<?php echo View::make('includes/header'); ?>
{{ View::make($template) }}
<?php echo View::make('includes/footer'); ?>
+1
source
To include blade template into another template,

    **layouts/index.blade.php**

    <!DOCTYPE html>
    <html lang="en" class="no-js">

    <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
0
source

Source: https://habr.com/ru/post/1663393/


All Articles