PHP Laravel 5.1 - php

I do not understand why the content is not visible no browser.
index.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Teste</title>
</head>
<body>
#yield('content')
</body>
</html>
conteudo.blade.php
#extends('index')
#section('content')
<p>This is my body content.</p>
#endsection
routes.php
Route::get('index', function() {
return view('layouts/index');
});
Route::get('blade', function() {
return view('layouts/conteudo');
});

Try this out:
please change your conteudo.blade.php code
#extends('index')
#section('content')
<p>This is my body content.</p>
#endsection
To
#extends('layouts.index')
#section('content')
<p>This is my body content.</p>
#endsection
Hope this helps you.

Related

Include layout in Laravel

My master.blade.php file is like below
<body>
#include('layouts.header')
#yield('content')
#include('layouts.footer')
#include('layouts.footer-script')
</body>
My dashboard.blade.php file is like below
#extends('layouts.master')
// I would like to add Menu here
#section('content')
//more code here
#endsection
My menu.blade.php is like below.
#extends('dashboard')
#section('menu')
// more HTML code
#endsection
How can I add Menu in dashboard.blade.php ?
dashboard.blade.php file is like below
#extends('layouts.master')
#include('menu')
#section('content')
//more code here
#endsection
menu.blade.php is like below.
<div>
// more HTML code
</div>
If your menu is static just use it as include
dashboard file
#extends('layouts.master')
#section('content')
#include('layouts.menu')
#endsection
and menu file will be (menu.blade.php)
<a href=''>Home</a>
master.blade.php
<body>
#include('layouts.header')
#yield('content')
#include('layouts.footer')
#include('layouts.footer-script')
</body>
dashboard.blade.php
#extends('layouts.master')
#include('menu')
#section('content')
//more code here
#endsection
This is your code.
It is Good.
If this is error, I think the path must have been wrong of menu.blade.php.
ex:#include(frontend.menu)
Thank you for your answer.

how to send data from controller to include/header blade file but return another blade file in laravel

I want to include send my data from my controller to my header.blade.php file in view
but i want to return the other view in the laravel as mentioned below:-
public function handleProviderCallback()
{
$user = Socialite::driver('google')->stateless()->user();
$finduser = User::where('google_id', $user->id)->first();
if($finduser) {
Auth::login($finduser);
$google_avatar = $user->getAvatar();
view('pages.home',['google_avatar', $google_avatar]);
return redirect()->route('home',);
}
}
By extending a layout is the cleanest way.
From the docs:
<!-- Stored in resources/views/layouts/app.blade.php -->
<html>
<head>
<title>App Name - #yield('title')</title>
</head>
<body>
#section('sidebar')
This is the master sidebar.
#show
<div class="container">
#yield('content')
</div>
</body>
</html>
The child:
#extends('layouts.app')
#section('title', 'Page Title')
#section('sidebar')
#parent
<p>This is appended to the master sidebar.</p>
#endsection
#section('content')
<p>This is my body content.</p>
#endsection
By just returning the "child" view from the controller, the data will be available in the header as well. If you pass it in the #extends declaration

Correct view output Laravel

That's my controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Spieler;
class SpielerController extends Controller
{
public function getSpieler(Request $request){
$spielID = $request->get('spielID');
$spielerOutput = Spieler::where('spielPlanID', '=', $spielID)->get();
return view('spieler')->with('alleSpieler', $spielerOutput);
}
}
here you can see my view which I will trigger
#extends('app')
#section('contentSpieler')
<h1>Spieler</h1>
#if(count($alleSpieler) > 0)
#foreach($alleSpieler as $teamSpieler)
{{ $teamSpieler->note }}
#endforeach
#endif
#endsection
And here is my main index/app page
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dateneingabe</title>
<link rel="stylesheet" href="/css/app.css">
<script src="{{ asset('/js/jquery-3.2.1.min.js') }}"></script>
</head>
<body>
<div class="container">
<h1>Spiele und Spieler AJAX - Drop Down</h1>
<div class="col-lg-4">
#yield('contentSpiel')
</div>
<div class="col-lg-4">
#yield('contentSpieler')
</div>
</div>
</body>
</html>
When my controller is going to trigger i get back this in my console
<script src="http://localhost:8000/js/jquery-3.2.1.min.js"></script>
</head>
<body>
<div class="container">
<h1>Spiele und Spieler AJAX - Drop Down</h1>
<div class="col-lg-4"></div>
<div class="col-lg-4">
<h1>Spieler</h1> 2.5 Blasdasd
</div>
</div>
</body>
</html>
But I want only that {{ $teamSpieler->note }} should appear in my index/app page in the part #yield('contentSpieler'). What is wrong with my code? The correct value of note 2.5 is in the html console output but at the moment I don't know why there is no output on my index/app page?
if your master view file location is view->index->app.blade.php then
your view file should be like this
#extends('index.app')
#section('contentSpieler')
<h1>Spieler</h1>
#if(count($alleSpieler) > 0)
#foreach($alleSpieler as $teamSpieler)
{{$teamSpieler->note}}
#endforeach
#endif
#endsection
here your master view file location should be correct to extend it in your view file

How to arrange display position of conten when using blade in Laravel?

I have a folder in View:
resources -> view
- layouts
+ master.blade.php
- partials
+ footer.blade.php
+ header.blade.php
- news
+ show.blade.php
+ list.blade.php
- apartment
+ show.blade.php
My code in master.blade.php:
<head>
<script src="{{{ URL::asset('js/theme.min.js')}}}"></script>
</head>
<body>
<div class="main-container">
#include('partials.header')
#yield('content')
#include('partials.footer')
</div>
</body>
In news>show.blade.php:
#extends('layouts.master')
#section('content')
<div class="show-news">show all news at here</div>
#stop
In apartment>show.blade.php:
#extends('layouts.master')
#section('content')
<div class="show-apartment">show all apartment at here</div>
#stop
In HTML file have structure like:
header
content
- show slider image
- show list news
- show list apartment
footer
Because all file is define with section('content').
I don't know how to arrange display position of `section('content') correctly with my HTML file.
I think it should be like:
In news>show.blade.php: #section('news')
In apartment>show.blade.php: #section('apartment')
In master.blade.php:
<head>
<script src="{{{ URL::asset('js/theme.min.js')}}}"></script>
</head>
<body>
<div class="main-container">
#include('partials.header')
#yield('news')
#yield('apartment')
#include('partials.footer')
</div>
</body>
But I see on almost project don't using like this.
You can create another layout page that extends master page like this
master.blade.php
<head>
<script src="{{{ URL::asset('js/theme.min.js')}}}"></script>
</head>
<body>
<div class="main-container">
#include('partials.header')
#yield('content')
#include('partials.footer')
</div>
</body>
newlayout.blade.php
#extends('master')
#section('content')
#yield('news')
#yield('appartments')
#endsection
And you can use this layout for pages like you described, for another you can use master

Laravel yield and extends not working

This is master.blade.php placed in views folder
<html ng-app="planner">
<head>
<title>MeetUp Planner</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/master.css" type="text/css">
</head>
<body ng-controller="MainController">
<div class="container" ng-controller="MainController">
<div class="row row-centered planner-block">
<div class="col-md-12">
<div class="col-md-5 col-centered col-min form-area">
<div class="row row-centered">
#yield('signup')
</div>
</div>
</div>
</div>
</div>
<script src="js/master.js"></script>
</body>
</html>
This is forms/signup.blade.php place in views folder
#extends('master')
#section('signup')
<div class="col-md-11 col-centered form-area-inner">
<span class="form-text">Sign Up</span>
<hr class="seperator"/>
</div>
#stop
This is routes file
<?php
Route::get('/', function () {
return view('master');
});
The yield 'signup' is not wokring, the divs and text are not being show in the master file. What could be the problem?
Directory Structure
resources:
---views->errors
---views->forms->signup.blade.php
---views->vendor
---views->master.blade.php
Using laravel 5.2
That's not how it works. master view will be extended when you'll use forms.signup view:
Route::get('/', function () {
return view('forms.signup');
});
If you want to include some view into master view, you should use #include() clause.
your route file will be
<?php
Route::get('/', function () {
return view('forms.signup');
});
?>
change the location of master.blade.php
move it to ---resources/views/layouts/master.blade.php
in your master.blade.php file change this line
#yield('signup') to #yield('content')
reference link : link

Categories