Ich bin neu bei Laravel und versuche, Kopf-, Fuß- und View-Datei vom Controller in eine gemeinsame Vorlage zu laden und die Daten vom Controller in der View-Datei anzuzeigen. Ich bekomme aber einen Fehler View ['admin.dashboard'] not found.
Die Dashboard-Datei befindet sich im Admin-Ordner in Ansichten
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'); ?>
Wenn ich 'admin/dashboard' anstelle von $data['template']
direkt in $template
hinzufüge, wird die Dashboard-Datei geladen, wohingegen sie nicht geladen wird, wenn ich sie als String vom Controller übergebe.
Dashboard.Blattansicht
<p><?php echo $data['title']; ?></p> //printing the data from the controller
Helfen Sie mir bitte, durchzukommen. Vielen Dank
Verwenden Sie @include
, um die Blattvorlage in eine andere Vorlage einzubinden.
@include('admin.dashboard')
Oder
@include($data['template']) // This should be the name of template, like 'admin.dashboard', but not path
Überprüfen Sie auch, ob die Ansicht den richtigen Namen hat und sich im richtigen Verzeichnis befindet:
resources/views/admin/dashboard.blade.php
Um die Blade-Vorlage in eine andere Vorlage aufzunehmen,
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
Zunächst einmal muss Ihr Code gemäß dem Laravel Blade-Code-Standard korrigiert werden. Versuchen Sie es unter dem Code:
common_template.blade Ansicht
@include('includes.header')
@yield('content')
@include('includes.footer')
Dashboard.Blattansicht
@extends('common_template')
@section('content')
{{$data['title']}}
@endsection