Laravel View contains additional '<' character - php

Laravel view page displays additional '<' character,but it is not given in the code. How can I fix it? I have given the blade.php code for the view. While inspecting, all the tags are misplaced and the head tag is shown inside the body tag.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
</head>
<body>
<div class="flex-center position-ref full-height">
#if (Route::has('login'))
<div class="top-right links">
#auth
Home
#else
Login
#if (Route::has('register'))
Register
#endif
#endauth
</div>
#endif
<div class="content">
<div class="title m-b-md">
Laravel
</div>
<div class="links">
Docs
Laracasts
News
Blog
Nova
Forge
GitHub
</div>
</div>
</div>
</body>
</html>

Related

#extends and #yield in laravel not working for second blade file

#extends , #section and #yield work for the main welcome page, but I made a new product-gel.blade.php file in view and used the #extends and #section and #endsection on it but it doesnt seem to work.
Here is the yield place
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="..\resources\stylecss\style.css">
#vite(['resources/css/app.css', 'resources/js/app.js'])
<script></script>
</head>
<body>
<div id="app">
<section id="header">
<div class="main-pages-box">
<div class="main-pages">
CUSTOMER CARE
#if (Route::has('login'))
#auth
<a> {{Auth::user()->name}} </a>
LOG OUT
#else
LOGIN
#if (Route::has('register'))
REGISTER
#endif
#endauth
#endif
</div>
</div>
<div class="main-bar">
<div class="daraz-logo-container">
<img src="../resources/images/daraz_logo.png" alt="daraz_logo" class="daraz-logo">
</div>
<div class="search-box-container">
<form onSubmit="searching();">
<input type="text" placeholder=" Search on Daraz" name="search" class="search-bar" id="text-to-search">
<a onclick="searching();" class="search-btn"></a>
<img src="../resources/images/cart-icon.png" alt="">
<img src="../resources/images/downloadnow-icon.png" alt="">
</form>
</div>
</div>
</section>
<script src="../resources/scriptfiles/searching.js"></script>
#yield('content')
<section id="footer">
<div class="customer-care-end">
<h1>Customer Care</h1>
<ul>
<li>Help Center</li>
<li>How to Buy</li>
<li>Corporate & Bulk Purchasing</li>
<li>Returns & Refunds</li>
<li>Daraz Shop</li>
<li>Contact Us</li>
<li>Purchase Protection</li>
<li>Daraz Pick up Points</li>
<li>Fulfulled By Daraz (FBD)</li>
</ul>
</div>
<div class="codenthx">
<div class="QRcode"></div>
<div class="appdl">
<div class="QRthx"></div>
<p>Happy Shopping</p>
</div>
</div>
</section>
</div>
</body>
</html>
And here is the new file im trying to extend on (removed the html file and just put it a header testing file to see if it works)
#extends('layouts.frontend')
#section('content')
<div>
<h1>testing</h1>
</div>
#endsection
This works on the welcome.blade.php file but not on the product-gel.blade.php file.
this is what the directory is looking like for the welcome page
view > welcome.blade.php
and for the product one
view > produ > product-gel.blade.php
I have also tried moving the gel.blade.php file outside of produ folder like this
view > product-gel.blade.php
But that also doesnt work, I am still new to laravel so dont know what I am doing wrong here.
https://imgur.com/a/2crydOm
This is what it looks like.

Laravel PHP, navbar "not active"

My navbar in one of my laravel (php framework) project suddenly stopped working, I think I've tried everything with it but nothing works nor get me back to the point where it was working, any solutions or suggestions how to fix this issue?
navbar
<div class="container mx-auto flex justify-between p-4">
<h1 class="text-xl font-black">stackoverflow</h1>
<nav class="navbar navbar-inverse navbar-fixed-top">
Home
About
</nav>
</div>
web.php
Route::get('/', function () {
return view('index');
})->name('home');
Route::get('/about', function () {
return view('about');
})->name('about');
default
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>sss</title>
<link rel="stylesheet" href="{{ asset('css/app.css')}}">
</head>
<body class='bg-sky-500 text-white'>
<header class="fixed bg-sky-400 top-0 left-0 right-0" z-50>
<div class="container mx-auto flex justify-between p-4">
<h1 class="text-xl font-black">ssss</h1>
<nav class="navbar navbar-inverse navbar-fixed-top">
Home
About
</nav>
</div>
</header>
<main>
#yield('page-content')
</main>
<footer>
<div class="container mx-auto p4">
<p>©
<a>ssss</a>
sss
ssss
</p>
</div>
</footer>
</body>
</html>
EDIT:
https://github.com/wsamselbaudat/LaravelProject
resources/views/
2 blade.php files(ignore dashborad), on the about page the navbar is working perfectly fine, I want the navbar to be working on index.blade.php
You can check for current url using the request() helper is() method
or can get the current url using request()->url() method and compare it with the link route url
Try this
Home
Home
Or
Home
Home

Laravel 8 with breadcrumbs add dynamic page title

I'm using laravel-breadcrumbs package by diglactic with laravel 8 forked from davejamesmiller/laravel-breadcrumbs I'm trying to add dynamic page title based on this breadcrumbs package.
what I mean by dynamic page title ? let's imagine that every page I have it contain a page title section like this :
HTML: (Every Page it have this section below the navbar)
<section class="py-5 text-center container">
<div class="row py-lg-5">
<div class="col-lg-6 col-md-8 mx-auto">
<h1 class="fw-bold mb-4">Page Title Here</h1> // Dynamic Page Title Here
</div>
</div>
</section>
You can make your own breadcrumb. First you should generate blade component something like php artisan make:component breadcrumb and then look at the code, I use it anyway and it success
AppServiceProvider.php
public function boot()
{
// your prev code
view()->share('currentPath', explode('/', substr_replace(request()->path(), '', 0, 3)));
}
componenents/breadcrumb.blade.php
<nav>
<ul class="breadcrumbs">
<li class="breadcrumb-item pl-0">
Home
</li>
#foreach ($paths as $path)
<li class="breadcrumb-item pl-0 text-capitalize
{{ $loop->last ? 'active' : '' }}">
<a href="{{ url($path) }}">
{{ str_replace('-', ' ', $path) }}
</a>
</li>
#endforeach
</ul>
</nav>
And use it in any view like this
<x-breadcrumb :paths="$currentPath" />
You can use #yield to cahnge a section of your template dynamically.
check the documentation for more info.
The #yield is use to dynamic title
here i am create a template.blade.php file and title.blade.php.
the title.blade.php is extends template.blade.php file and title can dynamic is work perfectly.
template.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>#yield('title')</title>
</head>
<body>
The title is dynamically
</body>
</html>
title.blade.php
#extends('template')
#section('title')
My Title
#endsection

Laravel blade not showing content

I'm trying to yield in one of my blade files but it's not working.
This is my index.blade.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="token" content="{{ csrf_token() }}">
<title>Forum</title>
<link href="https://fonts.googleapis.com/css?family=Lato:100,200,300,400" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Roboto:400,500,700' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="/css/bulma.css" rel='stylesheet' type='text/css'>
<link href="/css/all.css" rel='stylesheet' type='text/css'>
</head>
<body>
<div id="app">
#include('shared.menu.menu')
#yield('content')
</div>
<script src="/js/app.js"></script>
</body>
</html>
This is my login.blade.php:
#extends('index')
#section('content')
#yield('shared.bar.bar')
#stop
So the navigation bar is showing at this point. But the bar is not! When I replace: #yield('shared.bar.bar') with test, test shows up. This is shared/bar/bar.blade.php:
#section('bar')
<section class="hero is-primary">
<div class="hero-body">
<div class="container">
<h1 class="title">
test
</h1>
<h2 class="subtitle">
test
</h2>
</div>
</div>
</section>
#stop
What am I doing wrong? Is it also possible to pass variables to the bar? So I can show another title and subtitle on every page?
--EDIT--
#section('bar')
<section class="hero is-primary">
<div class="hero-body">
<div class="container">
<h1 class="title">
{{ $title }}
</h1>
<h2 class="subtitle">
{{ $subtitle }}
</h2>
</div>
</div>
</section>
#stop
If you are showing all of your code, looks like your yield is
#yield('shared.bar.bar')
And yout section
#section('bar')
When it should be
#section('shared.bar.bar')
Or you should change your yield to
#yield('bar')
Because #yield and #section are only strings, they are not related to files like #include.
And looks like this file is also wrong:
#extends('index')
#section('content')
#yield('shared.bar.bar')
#stop
#yield is something you should start using only in your main layout file, because it can get messy and hard and harder to undestand what's happening. So, unless you have a section 'shared.bar.bar' to fill this #yield, you should probably do something like
#extends('index')
#section('content')
<form>
.... your login form
</form>
#stop
or
#extends('index')
#section('content')
#include('shared.bar.bar')
#stop
or
#extends('index')
#section('content')
#include('shared.bar.bar')
<form>
.... your login form
</form>
#stop
To have the title changed via section you can also do:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<title>#yield('title')</title>
</head>
or
<h1 class="title">
#yield('title')
</h1>
And your login blade file, you can do
#extends('index')
// This will tell the Blade Compiler to replace every
// occurence of #yield('title')
#section('title')
User Login
#stop
#section('content')
#include('shared.bar.bar')
<form>
.... your login form
</form>
#stop

Laravel - Using of yields / extends

I have an #include problem with my bootstrap navbar. I worked on it this morning and I really don't know where the problem is.
Here is the error message :
View [layouts.navbar] not found.
I want to include the content of navbar.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Mana Tournaments</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"/>
{!! Html::style('css/style.css') !!}
{!! Html::style ('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css') !!}
{!! Html::style ('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css') !!}
</head>
<body>
<div class="container">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Logo</a>
</div>
<ul class="nav navbar-nav">
<li class="active">Accueil</li>
<li>Tournois</li>
<li>Inscription</li>
<li>Contact</li>
</ul>
</div>
</nav>
</div>
</body>
</html>
To my index page (welcome.blade.php)
<!DOCTYPE html>
<html>
<head>
<title>Mana Tournaments</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"/>
{!! Html::style('css/style.css') !!}
{!! Html::style ('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css') !!}
{!! Html::style ('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css') !!}
</head>
<body>
<h1>Gestionnaire de tournois</h1>
<div class="container">
#include('layouts.navbar')
</div>
</body>
</html>
I created manually a layout folder, then i created the navbar file. If I did someting wrong, maybe there's a command line for laravel for creating a folder ?
Thank you for helping me on my problem.
First of all,
Make sure the view you're including exists in the correct folder.
#include('layouts.navbar') will include that path \resources\views\layouts\navbar.blade.php
Make sure, The file within layouts directory,
Second, You don't need to write the whole html for the included part.
navbar.blade.php will be added (included) to welcome.blade.php,
it's like you're copying the content of navbar.blade.php and adding it to welcome.blade.php,
So make it like this instead,
navbar.blade.php
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Logo</a>
</div>
<ul class="nav navbar-nav">
<li class="active">Accueil</li>
<li>Tournois</li>
<li>Inscription</li>
<li>Contact</li>
</ul>
</div>
</nav>
That's because that file is not in the app/views directory. When you call #include('filename'), Blade automatically looks for any file with that name, inside the apps/views directory. Also, you're not supposed to write the file extension, as Blade automatically looks for files with .blade.php and .php extensions.
For Laravel 5 use this folder
resources/views/

Categories