I have blade template namely default.blade.php in app/layout/ folder
<!doctype html>
<html>
<head>
#include('includes.head')
</head>
<body>
<div class="container">
<header class="row">
#include('includes.header')
</header>
<div id="main" class="row">
#yield('content')
</div>
<footer class="row">
#include('includes.footer')
</footer>
</div>
</body>
</html>
Folder structure:
app/views/layout/default.blade.php
app/views/includes/footer.blade.php
app/views/includes/head.blade.php
app/views/includes/header.blade.php
My controller namely blade.php
<?php
class Blade extends BaseController
{
public function layout()
{
return View::make('layout.default');
}
}
?>
Routes.php
Route::get('blade','Blade#layout');
I am pointing my controller in browser like:
http://localhost/laravel/public/blade
It is showing error:
Call to undefined method Illuminate\Support\Facades\Blade::getAfterFilters()
How can i fix it. Please help me.
You can't name your Controller BLADE, Blade is a facade for the Template engine in Laravel, rename your Controller, to something else then Blade.
you can find all Laravel internal Facades in your config\app.php at the key aliases
Related
i created a new simple components for using into liveWire and i'm trying to use this component from a single route, in below simple implementation increment and decrement not working for me
route:
Route::get('/login',LoginComponent::class);
LoginComponent::class:
class LoginComponent extends Component
{
public $count = 10;
public function render()
{
return view('livewire.auth.login')->layout('livewire.auth.app');
}
public function increment()
{
$this->count++;
}
public function decrement()
{
$this->count--;
}
}
app.blade.php:
<!DOCTYPE html>
<html lang="en">
<head>
...
#livewireStyles
</head>
<body>
<div class="page-content">
<div class="content-wrapper">
#yield('content')
</div>
</div>
#livewireScripts
</body>
</html>
and then login.blade.php:
<div>
#section('content')
<div class="page-content">
<div class="content-wrapper">
<div class="content d-flex justify-content-center align-items-center">
<div style="text-align: center">
<button wire:click="increment"> + </button>
<button wire:click="decrement"> - </button>
<h1>{{ $count }}</h1>
</div>
</div>
</div>
</div>
#endsection
</div>
I would recommend to use proper rendering methods.
return view('livewire.auth.login')
->extends('livewire.auth.app')
->section('content');
And remove #section('content') from the login.blade.php
Check the docs on Rendering Components
I have tried the older #yield/#section Laravel style as described in the Livewire documentation and had no problem.
Your app.blade.php seems ok.
But your LoginController render method have to use extends():
public function render()
{
return view('livewire.auth.login')->extends('livewire.auth.app');
}
And you should remove #section from your login.blade.php component.
I have the following blade template:
<body>
<div id="app">
#extends('layouts._navbar')
<main class="py-4">
#yield('content')
</main>
</div>
</body>
Laravel first shows this:
<main class="py-4">
#yield('content')
</main>
And then:
#extends('layouts._navbar')
How do I to show the contents in the right order?
You have to use include instead of extends :
<body>
<div id="app">
#include('layouts._navbar')
<main class="py-4">
#yield('content')
</main>
</div>
</body>
Change the #extends('layout._navbar') to #include('layout._navbar').
Currently you're trying to push your blade file into the layout._navbar, instead of including it.
Laravel documentation on Blade Subviews
Your blade file will look like this after the edit:
<body>
<div id="app">
#include('layouts._navbar')
<main class="py-4">
#yield('content')
</main>
</div>
</body>
Here is the content of my home.blade.php file:
#extends('layouts.master')
#section('content')
#extends('partials.sidebar')
#section('pagecontent')
This is home
#endsection
#endsection
layouts/master.blade.php contains the main layout which has the typical <html><head><body>structure. In it's <body>, I am yielding to a section called content:
<!DOCTYPE html>
<html>
<body>
<div id="app">
#yield('content')
</div>
</body>
</html>
and in my parials/sidebar.blade.php, I am yielding to a section called pagecontent:
<div id="page-content-wrapper">
<div class="container-fluid">
#yield('pagecontent')
</div>
</div>
So I would naturally expect a DOM like this:
<!DOCTYPE html>
<html>
<body>
<div id="app"> <!-- #section('content') -->
<div id="page-content-wrapper">
<div class="container-fluid">
This is home <!-- #section('pagecontent') -->
</div>
</div>
</div>
</body>
</html>
Unfortunately, that's not the DOM my blade views are rendering. My sidebar partial doesn't get injected inside the master layout, instead, it is appended to the DOM as a sibling of the Entire Document:
<div id="page-content-wrapper">
<div class="container-fluid">
This is home <!-- #section('pagecontent') -->
</div>
</div>
<!DOCTYPE html>
<html>
<body>
<div id="app"> <!-- #section('content') -->
</div>
</body>
</html>
How can I fix this?
You can't use #extends like this. Use #include instead:
#include('partials.sidebar')
I have my master .php file setup here: views/layouts/app.blade.php
and my child here views/tasks.blade.php
In tasks.blade.php I wrote the following code:
#extends('layouts.app')
#section('content')
<div class="panel-body">
<form action="/task" method="POST" class="form-horizontal">
[content here]
</form>
</div>
#endsection
In app.blade.php I have a basic html setup with html-tags, bootstrap cdn, and jquery. In the body-tags I wrote:
#yield('content')
In routes.php the default route when localhost loads the map is set to 'tasks':
Route::get('/', function () {
return view('tasks');
});
However, I do not get the tasks.blade.php displayed within app.blade.php. this is what I DO get returned:
Any solutions please?
From what I see you should have this
#extends('layouts.app')
#section('content')
<div class="panel-body">
<form action="/task" method="POST" class="form-horizontal">
[content here]
</form>
</div>
#stop
#stop
I am having trouble rendering a view in my controller. I am currently running Laravel 4 and below is my code. (BTW, I am still learning Laravel particularly the latest version that has not been released yet. I find it a bad idea to learn from the older versions because there seems to be a lot of changes for the current one.)
controllers/PluginsController.php
class PluginsController extends BaseController {
public function index()
{
return View::make('plugins.index')->with(array('title'=>"The Index Page"));
}
views/plugins/index.blade.php
#layout('templates.master')
#section('header')
<h1>The Header</h1>
#endsection
#section('content')
testing the index.blade.php
#endsection
#section('footer')
<div style="background:blue;">
<h1>My Footer Goes Here</h1>
</div>
#endsection
views/templates/master.blade.php
<!doctype>
<html>
<head>
<meta charset="UTF-8" />
#yield('meta_info')
<title>{{$title}}</title>
#yield('scripts')
</head>
<body>
<div id="header">
#yield('header')
</div>
<div id="wrapper">
#yield('content')
</div>
<div id="footer">
#yield('footer')
</div>
</body>
</html>
you must use #extends instead of #layout, and #stop instead of #endsection
Using #extends instead of #layout solved my problem.