Title and all <head> content in <body> - laravel

This is the structure of the views folder:
/layout
header.blade.php
footer.blade.php
template.blade.php
index.blade.php
header content:
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="{{ asset('img/favicon.png') }}">
<link rel="apple-touch-icon" href="{{ asset('img/favicon.png') }}">
<title>#yield('title')</title>
</head>
<body>
footer:
<script src="{{ asset('js/jquery-3.6.0.min.js') }}"></script>
<script src="{{ asset('js/custom.js') }}"></script>
#stack('scripts')
</body>
</html>
template:
#include('layout.header')
#yield('content')
#include('layout.footer')
index:
#extends('layout.template')
#section('title', 'Title')
#section('content')
<div>Content</div>
#endsection
When I inspect the html that's how the structure looks like:
<html>
<head></head>
<body>
<link rel="icon" href="http://localhost/project/public/img/favicon.png">
<title>testing</title>
<div>Test</div>
<script src="http://localhost/project/public/js/jquery-3.6.0.min.js"></script>
<script src="http://localhost/project/public/js/custom.js"></script>
</body>
</html>
This causes the favicon not to be displayed.
How to fix this issue?

You are making this much more complicated then it needs to be. You can use the #extend method to use a template file. I would make it like this:
/layouts/app.blade.php
index.blade.php
<!-- app.blade.php -->
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="{{ asset('img/favicon.png') }}">
<link rel="apple-touch-icon" href="{{ asset('img/favicon.png') }}">
<title>#yield('title', 'Title')</title>
</head>
<body>
#yield('content')
<script src="{{ asset('js/jquery-3.6.0.min.js') }}"></script>
<script src="{{ asset('js/custom.js') }}"></script>
</body>
</html>
<!-- index.blade.php -->
#extends('layouts.app')
#section('title, 'My Page Title')
#section('content')
<div>
<!-- Go crazy -->
<!-- Everything in here will take place of the #yield('content') area -->
<!-- in the app.blade.php file -->
</div>
#endsection

Related

Adding vue component to Laravel's main welcome.blade.php file

I'm trying to add a header component to my main 'welcome.blade.php' file, but it's content is not rendering. What am I doing wrong here?
I have made my header component in my components folder like this:
<template>
<div class="header">This is the header.</div>
</template>
<script>
export default {
name: "Header",
};
</script>
Then I imported my header to my main app.js file and registered my component like this:
import Header from './components/header';
Vue.component('header', Header);
Eventually I added my header tags to Laravel's main 'welcome.blade.php' file within the #app container:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!--<link rel="shortcut icon" href="{{ asset('images/evoqia-icon-gray.png') }}" />-->
<link rel="shortcut icon" href="//creatio.com/themes/custom/creatio/favicon.ico" />
<title>{{ config('app.name') }}</title>
</head>
<body class="antialiased">
<div id="app" v-cloak>
<header></header>
<div class="content-wrapper" :class="{'nopadding': !$store.state.authStore.user}">
<div class="container app-container">
<router-view></router-view>
</div>
</div>
</div>
<script>
var Laravel = {
'csrfToken': '{{ csrf_token() }}'
};
</script>
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<script src="{{ asset('js/app.js') }}"></script>
</body>
</html>
So what am I doing wrong here?

Laravel 8: Session::forget() not working in blade file

I have a blade file thanks.blade.php where I put two sessions grand_total and order_id. When I refresh the page session still exists.
I want when I refresh the page the session should be destroyed. I have written the session forget code at the end. Is it correct? I think it's not correct then how to write it.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>Thanks</title>
<link href="{{ url('css/front_css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url('css/front_css/font-awesome.min.css') }}" rel="stylesheet">
<link href="{{ url('css/front_css/prettyPhoto.css') }}" rel="stylesheet">
<link href="{{ url('css/front_css/price-range.css') }}" rel="stylesheet">
<link href="{{ url('css/front_css/animate.css') }}" rel="stylesheet">
<link href="{{ url('css/front_css/main.css') }}" rel="stylesheet">
<link href="{{ url('css/front_css/responsive.css') }}" rel="stylesheet">
<!--[if lt IE 9]>
<script src="{{ url('js/front_js/html5shiv.js') }}"></script>
<script src="{{ url('js/front_js/respond.min.js') }}"></script>
<![endif]-->
<!-- favicon -->
<link rel="icon" type="image/png" sizes="192x192" href="{{ asset('images/ico/android-icon-192x192.png')}}">
</head>
<!--/head-->
<body>
<!-- Header Part -->
#include('layouts.front_layout.front_header')
<div class="jumbotron text-center">
<h1 class="display-3">Thank You!</h1>
<p class="lead"><strong>Your Order Is Successfully Place</strong></p>
<p class="lead">Your Order number is {{Session::get('order_id')}} and grand total is PK. {{Session::get('grand_total')}}</p>
<hr>
<p>
<strong>Please check your email</strong> for further instruction. Having trouble? Contact us
</p>
<p class="lead">
<a class="btn btn-primary btn-sm" href="{{url('/')}}" role="button">Continue to homepage</a>
</p>
</div>
<!--/Footer-->
#include('layouts.front_layout.front_footer')
<script src="{{ url('js/front_js/jquery.js') }}"></script>
<script src="{{ url('js/front_js/bootstrap.min.js') }}"></script>
<script src="{{ url('js/front_js/main.js') }}"></script>
</body>
</html>
<php Session::forget('grand_total'); Session::forget('order_id'); ?>
You have to use following code below
#php
Illuminate\Support\Facades\Session::forget('grand_total');
Illuminate\Support\Facades\Session::forget('order_id');
#endphp
It is working fine for me. I have just now used in my project.

why Laravel #yield and #section not wokring?

I have Master as a main page where I load dynamic pages.
Master
<!DOCTYPE html>
<html lang="en">
<head>
#include('backend.includes.header')
#yield('style')
</head>
<body>
#include('backend.includes.navbar')
<div class="mobile-menu-overlay"></div>
#yield('content')
#yield('script')
</body>
</html>
Dashboard
#extends('backend.master.master')
#section('style')
<link rel="stylesheet" href="{{ asset('backend/css/apexcharts.css') }}">
#stop
#section('content')
// Dashboard Code here
#endsection
#section('script')
<script src="{{ asset('backend/js/dashboard.js') }}"></script>
#endsection
It doesn't render #yield('style') and #yield('script')
Also my controller:
public function index(){
return view('backend.pages.home.dashboard');
}

Eonasdan DatePicker not working in Laravel 5.5

I'm trying to use the package bootstrap-datetimepicker. I had already followed the installation tutorial. But I couldn't accomplish to get it to work. I imported the files required into app\publicfolder as well.
My Folder Structure
public folder structure
My blade file
<html>
<head>
<title>Laravel Bootstrap Datepicker</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- JS AND CSS -->
<script type="text/javascript" src="{{ URL::asset('js/jquery-3.3.1.js') }}"></script>
<script type="text/javascript" src="{{ URL::asset('js/moment.js')}}"></script>
<script type="text/javascript" src="{{ URL::asset('js/bootstrap.js') }}"></script>
<script type="text/javascript" src="{{ URL::asset('js/bootstrap-datetimepicker.js')}}"></script>
<link href="{{ asset('css/bootstrap.css')}}" rel="stylesheet">
<link href="{{ asset('css/bootstrap-datetimepicker.css')}}" rel="stylesheet">
</head>
<body>
<!-- DATATIME PICKER CODE -->
<img src="{{asset('goku.jpg')}}" alt="Mountain View">
<div class="container">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='datetimepicker5'>
<input type='text' class="form-control " />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
$('#datetimepicker5').datetimepicker({
defaultDate: "11/1/2013",
disabledDates: [
moment("12/25/2013"),
new Date(2013, 11 - 1, 21),
"11/22/2013 00:53"
]
});
});
</script>
</div>
</div>
</body>
</html>
My Result
The result I'm getting is this, an import with a fail icon. And nothing showing up while clicking.

[Vue warn]: Cannot find element: #app

I have a fresh installed laravel project with all the components updated.
All I did is tried to add app.js in my welcome.blade.php file, after adding the following I get this error
[Vue warn]: Cannot find element: #app
I followed this thread, but it's not relevant as my script is at the bottom of the page.
https://laracasts.com/discuss/channels/vue/fresh-laravel-setup-and-vue-2-wont-work
Here's my file
<!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">
<title>{{$project}} | {{ $title }}</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
<!-- Styles -->
<link href="/css/app.css" rel="stylesheet" type="text/css"/>
<style>
...
</style>
</head>
<body class="sticky-nav">
<div id="nav">
<div class="display-sm">
<header class="top-header">
<span class="menu-icon">☰</span>
</header>
</div>
<div class="custom-container">
<div id="logo" class="float-left">
<img alt="xyz" src="/images/xyz.png"/><span> xyz</span>
</div>
<div id="btn-project" class="float-right">
<a title="project" href="#" class="btn btn-project">Project</a>
</div>
</div>
</div>
<div class="sub-container">
<h1 id="header-title">{{ $header_title }}</h1>
<h2 id="meta-data"><i class="fa fa"></i>{{$location}} <span id="category"> <i></i>{{$category}} </span></h2>
<div class="clear"></div>
</div>
<script src="/js/app.js"></script>
<script>
var wrap = $(".sticky-nav");
wrap.on("scroll", function (e) {
if (this.scrollTop > 147) {
wrap.find('#nav').addClass("fix-nav");
} else {
wrap.find('#nav').removeClass("fix-nav");
}
});
</script>
</body>
</html>
Error says it all. Vue can't find #app element, so you need to add it:
<div id='app'></div>
https://v2.vuejs.org/v2/guide/
Sometime everything seems got , but we are still getting same error then you have to copy this code and paste in app. blade.
<head>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
<div id="app">
.
.
.
.
.
.
</div>
</body>
Verify that your main design file app.blade.php contains a div with the app id just after the <body> tag just like this:
<body>
<div id="app">
.
.
.
</div>
</body>

Resources