How to create #yield in #yield - php

how to make #yield inside #yield, because the second #yield does not bring up the content that I want to release??
I'm tired of finding ways to make #yield inside #yield.
because I want to use side navigation inside side navigation, so I need a way to make #yield inside #yield.
please help
//THIS IS MY FIRST #yield (mail.blade.php)
#extends('layouts.app')
#section('content')
<div class="mail-w3agile">
<!-- page start-->
<div class="row">
<div class="col-sm-3 com-w3ls">
<section class="panel">
<div class="panel-body">
<a href="#" data-toggle="modal" data-target="#myModal1" class="btn btn-compose">
Compose Mail
</a>
<ul class="nav nav-pills nav-stacked mail-nav">
<li class="active"><a href="{{ route('mail') }}"> <i class="fa fa-inbox"></i> Inbox <span
class="label label-danger pull-right inbox-notification">9</span></a></li>
<li> <i class="fa fa-envelope-o"></i> Send Mail</li>
<li><i class="fa fa-star"></i>Favorit</li>
<li> <i class="fa fa-certificate"></i> Important</li>
<li><a href="#"> <i class="fa fa-file-text-o"></i> Drafts <span
class="label label-info pull-right inbox-notification">123</span></a></a></li>
<li> <i class="fa fa-trash-o"></i> Trash</li>
</ul>
</div>
</section>
</div>
<section id="main-content">
#yield('main-content')
</section>
</div>
<!-- page end-->
</div>
#endsection
//AND THIS IS MY SECOND #yield (inbox.blade.php)
#extends('admin.mail')
#section('main-content')
<h2>TESTING</h2>
#endsection

Are you looking for #stacks?
https://laravel.com/docs/6.x/blade#stacks
Instead of trying to use a mess of nested #yield you can define your side menu as a #stack('sideMenu') in the layout file, that way each time you include a blade file you would be able to add view data by targeting that specific stack with
#push('sideMenu')
This will be second...
#endpush
// Later...
#prepend('sideMenu')
This will be first...
#endprepend

Related

Laravel Applications Invalid argument supplied for foreach() Errors

I am learning PHP Laravel and I am developing shopping cart project. I am able to add the product into list but, when I click shopping cart link. I am getting following error.
Facade\Ignition\Exceptions\ViewException
Invalid argument supplied for foreach() (View: C:\Users\Khundokar Nirjor\Desktop\laravel Tutorial\shopping-cart\resources\views\shop\shopping-cart.blade.php)
Here is my Router
Route::get('/shopping-cart',[
'uses' => 'ProductController#getCart',
'as' => 'product.shopppingCart'
]);
Here is my header.blade.php code.
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="{{route ('product.shopppingCart')}}"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Shopping Cart
<span class="badge">{{ Session::has('cart') ? Session::get('cart')->totalQty : '' }}</span>
</a>
</li>
<li class="dropdown">
<i class="fa fa-user" aria-hidden="true"></i> User Mangemetn <span class="caret"></span>
<ul class="dropdown-menu">
#if(Auth:: check())
<li>User Profile</li>
<li>Logout</li>
#else
<li>Sign Up</li>
<li>Sign In</li>
#endif
<li role="separator" class="divider"></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
Here is my shopping-cart.blade.php
#extends('layouts.master')
#section('title')
Laravel Shopping Cart
#endsection
#section('content')
#if(Session::has('cart'))
<div class="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<ul class="list-group">
#foreach($products as $product)
<li class ="list-group-item">
<span class ="badge"> {{ $product['qty'] }}</span>
<strong >{{ $product['item']['title']}}</strong>
<span class ="label label-success"> {{ $product['price']}}</span>
<div class="btn-group">
<button type="button" class="btn btn-primary btn-xs dropdown-toggle" data-toggle="dropdown">Action<span class="caret"></span></button>
<ul class="dropdown-menu">
<li> Reduce By 1 </li>
<li> Reduce All </li>
</ul>
</div>
</li>
#endforeach
</ul>
</div>
</div>
<div class ="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<strong > Total : {{ $totalPrice}}</strong>
</div>
</div>
<hr>
<div class ="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<button type="button" class="btn btn-success">Checkout</button>
</div>
</div>
<div class ="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<strong>Total : {{$totalPrice}} </strong>
</div>
</div>
<hr>
<div class ="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<button type="button" class ="btn-btn-success">Checkout</button>
</div>
</div>
#else
<div class ="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<h2>No Items In Cart</h2>
</div>
</div>
#endif
#endsection
Here is my controller code
public function getCart()
{
if(!Session :: has('cart') ){
return view ('shop.shopping-cart');
}
$oldCart = Session::get('cart');
$cart = new Cart($oldCart);
return view ('shop.shopping-cart' , ['products' => $cart->items, 'totalPrice'=>$cart->totalPrice]);
}
Here is screen shot when I clicked the shopping-cart link
Try like this
#if(!empty($products) && count($products) > 0)
#foreach($products as $product)
// your code here
#endforeach // typo in foreach fixed
#endif
You're getting this error cuase of sometime your products array is empty. So whenever you call foreach make sure to check the array is not empty.
#if(!empty($products)
#foreach($products as $product)
//code here
#endforech
#endif
Make your code like this your error will be gone.

Content added after PHP "included" files not positioning correctly

I'm using PHP's "include" function to display static elements on all my pages, but the end result is not displaying as it should.
index code:
<?php
require '../../views/sidebar.php';
require '../../views/navbar.php';
?>
<div class="card">
<div class="card-header">
Test
</div>
<div class="card-body">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item active" aria-current="page">Library</li>
</ol>
</nav>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
Go somewhere
</div>
</div>
sidebar code:
<nav class="side-navbar">
<div class="side-navbar-wrapper">
<div class="sidenav-header d-flex align-items-center justify-content-center">
<div class="sidenav-header-inner text-center"><img src="../../views/img/logo.jpg" alt="menulogo" class="img-fluid rounded-circle">
<h2 class="h5">Test</h2><span>Dashboard</span>
</div>
<div class="sidenav-header-logo"> <strong>B</strong><strong class="text-primary">D</strong></div>
</div>
<div class="main-menu">
<h5 class="sidenav-heading">Main</h5>
<ul id="side-main-menu" class="side-menu list-unstyled">
<li> <i class="icon-home"></i>Home </li>
<li> <i class="icon-form"></i>Forms </li>
<li> <i class="fa fa-bar-chart"></i>Charts </li>
<li> <i class="icon-grid"></i>Tables </li>
<li> <i class="icon-interface-windows"></i>Example dropdown
<ul id="exampledropdownDropdown" class="collapse list-unstyled ">
<li>Page</li>
<li>Page</li>
<li>Page</li>
</ul>
</li>
<li> <i class="icon-interface-windows"></i>Login page</li>
<li> <a href="#"> <i class="icon-mail"></i>Demo
<div class="badge badge-warning">6 New</div></a></li>
</ul>
</div>
<div class="admin-menu">
<h5 class="sidenav-heading">Second menu</h5>
<ul id="side-admin-menu" class="side-menu list-unstyled">
<li> <i class="icon-screen"> </i>Demo</li>
<li> <a href="#"> <i class="icon-flask"> </i>Demo
<div class="badge badge-info">Special</div></a></li>
<li> <i class="icon-flask"> </i>Demo</li>
<li> <i class="icon-picture"> </i>Demo</li>
</ul>
</div>
</div>
</nav>
this is a snippet from a bootstrapious template I'm using for learning purposes, and the css is both bootstrap and the template's, untouched.

Bootstrap prevent multiple collapsable elements from being open at the same time

I have the following html sidebar menu:
<li {{{ (Request::is('bookings/*') }}} data-toggle="collapse" data-target="#bookings">
<i class="fa fa-address-book" aria-hidden="true"></i> Bookings <i class="fa fa-chevron-down" aria-hidden="true"></i>
</li>
<ul class="sub-menu collapse" id="bookings">
<li class="collapsed">All Bookings</li>
<li class="collapsed" >Add New</li>
</ul>
<li {{{ (Request::is('bookings/*') || Request::is('bookings') ? 'class=active' : '') }}} data-toggle="collapse" data-target="#item2">
<i class="fa fa-address-book" aria-hidden="true"></i> Item 2 <i class="fa fa-chevron-down" aria-hidden="true"></i>
</li>
<ul class="sub-menu collapse" id="item2">
<li {{{ (Request::is('bookings') ? 'class=active' : 'collapsed') }}}>All Bookings</li>
<li {{{ (Request::is('bookings/create') ? 'class=active' : 'collapsed') }}} >Add New</li>
</ul>
This is a basic Bootstrap collapse menu that contains a sub menu which expands when the li element is clicked.
The problem I have is lets say I have 2 or 3 of these menu items that all have sub menus. There is a possibility that all of them could open at the same time, I don't like this because this forces a scroll overflow as the height increases which then shows a scrollbar for the side menu.
Is there a way I can prevent multiple elements from being expanded in Bootstrap?
I am using Laravel 5 if that helps.
I think this should help you, just play a little with it to adapt it to your needs:
<div class="row">
<div class="col">
<ul class="nav nav-stacked" id="accordion1">
<li class="panel"> <a data-toggle="collapse" data-parent="#accordion1" href="#firstLink">Test12</a>
<ul id="firstLink" class="collapse">
<li>SubTest1</li>
<li>SubTest1</li>
<li>SubTest1</li>
</ul>
</li>
<li class="panel"> <a data-toggle="collapse" data-parent="#accordion1" href="#secondLink">Test2</a>
<ul id="secondLink" class="collapse">
<li>SubTest2</li>
<li>SubTest2</li>
<li>SubTest2</li>
<li>SubTest2</li>
</ul>
</li>
</ul>
</div>
</div>
See it here
https://codepen.io/anon/pen/ZaMOxN

Toggle Dropdown not working?

I am doing a project in which I show users and when any person click on that user it should has to do a particular task and that is, it has to show a dropdown as written in code
But when I click on the username nothing happens, is just a simple click, it is not showing the dropdown
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<!-- User Account: style can be found in dropdown.less -->
<li class="dropdown user user-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<img src="dist/img/user2-160x160.jpg" class="user-image" alt="User Image">
<span class="hidden-xs">{{ Auth::user()->name }}</span>
</a>
<ul class="dropdown-menu">
<!-- User image -->
<li class="user-header">
<img src="dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">
<p>
{{ Auth::user()->name }} - Web Developer
<small>Member since {{ Auth::user()->created_at->toFormattedDateString() }}</small>
</p>
</li>
<!-- Menu Footer-->
<li class="user-footer">
<div class="pull-left">
Profile
</div>
<div class="btn btn-default pull-right">
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</div>
</li>
</ul>
</li>
</ul>
</div>
i think you might be missing your java script code that performs the toggle function itself. your link has the class=dropdown-toggle but nothing to help display the information you want to show.

How do I keep the current tab active?

I use bootstrap theme bs-admin-bcore and I want to make menu in file "menu.php" to be more dynamic.
For example, I have this code :
<ul id="menu" class="collapse">
<li class="panel">
<a href="index.php" >
<i class="icon-table"></i> Dashboard
</a>
</li>
<li class="panel ">
<a href="#" data-parent="#menu" data-toggle="collapse" class="accordion-toggle" data-target="#component-nav">
<i class="icon-tasks"> </i> UI Elements<span class="pull-right"><i class="icon-angle-left"></i></span> <span class="label label-default">10</span>
</a>
<ul class="collapse" id="component-nav">
<li class=""><i class="icon-angle-right"></i> Buttons </li>
</ul>
</li>
</ul>
when I call index.php <li class="panel"> becomes <li class="panel active"> and when I call button.php EU Elements becomes active.
You have to add "active" class to the parent li of buttons as well n it will work.

Categories