if array empty blade laravel - laravel

i have this blade template and i wanna first check if the $dejeuner date exist if so do the rest else show a message but this line of code show both the error and fetch the details or if i change it i get only the error even though in else i ask to fetch data .can you guys check for me
<div style="text-align: center;" id="lunch">
#if(emptyArray($dejeuner))
<h2 class="sessiontitle">Déjeuner : </h2>
<ul style=" text-align: center;margin-top: 10%">
<li class="menuitems">menu non disponible</li>
</ul>
#else
<h2 class="sessiontitle">Déjeuner : {{$dejeuner[0]->date}}</h2>
#foreach($dejeuner as $dej)
<ul style=" text-align: center;margin-top: 10%">
#foreach($dej->liste as $list)
<li class="menuitems">{{$list->plat->titre}}</li>
#endforeach
</ul>
#endforeach
#endif

<div style="text-align: center;" id="lunch">
#if(count($dejeuner))
<h2 class="sessiontitle">Déjeuner : </h2>
<ul style=" text-align: center;margin-top: 10%">
<li class="menuitems">menu non disponible</li>
</ul>
#else
<h2 class="sessiontitle">Déjeuner : {{$dejeuner[0]->date}}</h2>
#foreach($dejeuner as $dej)
<ul style=" text-align: center;margin-top: 10%">
#foreach($dej->liste as $list)
<li class="menuitems">{{$list->plat->titre}}</li>
#endforeach
</ul>
#endforeach
#endif

Related

Page content moves behind sidebar, Bootstrap

I've written a sidebar using Bootstap 5 which is placed on my _Layout view. The issue I'm having is when I load a new page like a users view, initialy it looks great, until I resize my screen and then the content on the users view slides behind the sidebar. I've tried placing the sidebar in a new column and row, etc but nothing I do seems to fix this. Below is my sidebar code, any help on this issue will be greatly appreciated.
<!-- Side Nav-->
<div class="container-fluid">
<div class="row">
<nav class="sidebar card py-2 mb-4 col-2 float-start vh-100 rounded-0 position-fixed" style="background-color: rgb(95,131,183);
width: 250px; padding-left: 0px; padding-right: 0px">
<ul class="nav flex-column" id="nav_accordion">
<li class="nav-item border-bottom">
<a class="nav-link bi bi-house" asp-area="" asp-controller="Home" style="color:whitesmoke; padding-left: 10px"> Home </a>
</li>
<li class="nav-item border-bottom">
<a class="nav-link bi bi-gear" href="#" style="color:whitesmoke; padding-left: 10px"> Settings </a>
</li>
<li class="nav-item border-bottom">
<a class="nav-link bi bi-speedometer" href="#" style="color: whitesmoke; padding-left: 10px"> Dashboard </a>
</li>
<li class="nav-item has-submenu border-bottom">
<a class="nav-link bi bi-people" href="#" style="color: whitesmoke; padding-left: 10px"> Contacts </a>
<ul class="submenu collapse" style="padding-left: 0px; padding-right: 0px">
<li><a class="nav-link" asp-area="" asp-controller="Users" asp-action="UsersIndex" style="color: whitesmoke"> Users </a></li>
<li><a class="nav-link" href="#" style=" color: whitesmoke"> Customers </a></li>
<li><a class="nav-link" href="#" style=" color: whitesmoke"> Suppliers </a></li>
</ul>
</li>
#* <li class="nav-item">
<a class="nav-link" href="#"> Something </a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"> Other link </a>
</li>*#
</ul>
</nav>
</div>
</div
Many thanks
AJ

Last dropdown menu - Link sensitive area reduces when navbar stacked

I have this topbar
<div class="container topbar">
<nav class="navbar navbar-expand-sm ">
{{-- With d-none d-lg-block logo hides on screen smaller than lg
--}}
<div class="col-md-3 d-none d-lg-block">
<div id="contain-logo">
<div id="logo">
<a class="rounded" href="{{ url('/') }}">{{ config('app.name', '') }}</a>
</div>
</div>
</div>
<!-- with ml-auto item align on right Side Of Navbar -->
<ul class="navbar-nav ml-auto">
<!-- Authentication Links -->
#guest
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ 'Se connecter' }}</a>
</li>
#if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ 'Créer un compte' }}</a>
</li>
#endif
#else
#can('isAtLeastPhotoprovider')
<!-- Dropdown -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
Administration
</a>
<div class="dropdown-menu">
#can('isAtLeastWriter')
<a class="dropdown-item" href="{{ route('posts.index') }}">Articles</a>
#endcan
#can('isAtLeastManager')
<a class="dropdown-item" href="{{ route('infoletter.index') }}">Infoletters</a>
<a class="dropdown-item" href="{{ route('adherent.index') }}">Adhérents</a>
#endcan
#can('isAtLeastPhotoprovider')
<a class="dropdown-item" href="{{ route('filemanager.index') }}">Fournir des
photos(contraint)</a>
#endcan
#can('isAdmin')
<a class="dropdown-item" href="{{ route('upload.index') }}">Fournir des
photos(libre)</a>
#endcan
<a class="dropdown-item" href="{{ route('home') }}">Retour à l'accueil</a>
</div>
</li>
#endcan
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop2" data-toggle="dropdown">
Bienvenue {{ Auth::user()->firstname }} {{ Auth::user()->familyname }} !
#can('isAtLeastPhotoprovider')
{{--Vous avez le rôle
{{ Auth::user()->role }}.--}}
#endcan
</a>
<div class="dropdown-menu ">
<a class="dropdown-item" href="{{ route('logout') }}" onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ 'Se déconnecter' }}
</a>
</div>
<form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
#csrf
</form>
</li>
#endguest
</ul>
</div>
</div>
</nav>
Hereafter are the changes in css that are in the custom css
.dropdown-menu {
background-color: antiquewhite;
padding: 5px;
}
.dropdown-item {
background-color: #513217;
border-radius: 8px;
color: antiquewhite;
margin-top: 5px;
}
.navbar {
background-color: transparent;
}
.navbar-nav {
background-color: transparent;
}
.nav-link {
color: antiquewhite;
background-color: rgba(110, 98, 89, 1);
border-radius: 5px;
border: 1px solid antiquewhite;
margin-left: 15px;
}
In this top bar there are 2 dropdown menus (Administration and Bienvenue). The trouble appears only when the navbar's dropdown menus become stacked on smaller devices.
The trouble appears only on the last dropdown menu. If Administration is the last it has the trouble and Bienvenue has not. Conversely if Bienvenue is the last it appears only for it.
The trouble is that the area where the mouse pointer has to be to trigger the link reduces to be a very thin strip on the top of the menu item. It is very uncomfortable for the user specially on smart phones.
In addition, the only item in the dropdown menu becomes effectless !
Thank you in advance for any help.
Finally I found that a div was overlapping the menu. Nothing very serious.

i am not able to find order through id in laravel

I am new to shopping cart. I am able to get all the data from order table on this page but i am not able to find single order by ID:
This is my view page where i am sending the $id to the controller of the order.
id)}}">Order# {{$order->id}}
The whole code:
'''
#foreach($orders as $order)
#if($order->status == "CompletedOrders")
<div class="panel panel-default">
<div class="panel-body">
<ul class="list-group" >
<li class="list-group-item" style="background-color: #5C94ED">
<h1 style="color: #FBEB58">Order# {{$order->id}}</h1>
<span class="badge" style="color: black; font-size: 16px">Name: {{$order->name}}</span>
<br>
<span class="badge" style="color: black; font-size: 16px">Phone: {{$order->phone}}</span>
<br>
#foreach($order->cart->items as $item)
<span class="badge" style="color: #FBEB58; font-size: 16px">{{$item['qty'] }} {{ $item['item']['name'] }}</span>
<br>
<span class="badge" style="color: #FBEB58; font-size: 16px">Price: ${{ $item['price'] }}</span>
<br>
#endforeach
<span class="badge" style="color: black; font-size: 16px">Instructions: {{$order->table}}</span>
<br>
<span class="badge" style="color: black; font-size: 16px">Time: {{$order->created_at}}</span>
<br>
</ul>
</div>
<div class="panel-footer">
<strong style="color: #222D32; font-size: 18px">Total Price: ${{ $order->cart->totalPrice }}</strong>
</div>
</div>
<input type="button" onclick="printDiv('printableArea')" value="print a div" />
#endif
#endforeach
'''
This is my route
'''
Route::get('showcompleteorder/{id}','OrderController#showCompleteOrder')->name('showcompleteorder');
'''
and this is my controller:
public function showCompleteOrder($id){
$orders = Order::find($id);
$orders->transform(function ($order, $key) {
$order->cart = unserialize($order->cart);
return $order;
});
return view('orders.showcompleteorders', ['orders' => $orders]);
}
but when i run this. it gives me a error of transform:
BadMethodCallException
Call to undefined method App\Order::transform()
http://localhost:8000/showcompleteorder/2
This is my view where i am trying to get the order by id:
#foreach($orders as $order)
<div class="panel panel-default">
<div class="panel-body">
<ul class="list-group" >
<li class="list-group-item" style="background-color: #5C94ED">
<h1 style="color: #FBEB58">Order# {{$order->id}}</h1>
<span class="badge" style="color: black; font-size: 16px">Name: {{$order->name}}</span>
<br>
<span class="badge" style="color: black; font-size: 16px">Phone: {{$order->phone}}</span>
<br>
#foreach($order->cart->items as $item)
<span class="badge" style="color: #FBEB58; font-size: 16px">{{$item['qty'] }} {{ $item['item']['name'] }}</span>
<br>
<span class="badge" style="color: #FBEB58; font-size: 16px">Price: ${{ $item['price'] }}</span>
<br>
#endforeach
<span class="badge" style="color: black; font-size: 16px">Instructions: {{$order->table}}</span>
<br>
<span class="badge" style="color: black; font-size: 16px">Time: {{$order->created_at}}</span>
<br>
</ul>
</div>
<div class="panel-footer">
<strong style="color: #222D32; font-size: 18px">Total Price: ${{ $order->cart->totalPrice }}</strong>
</div>
</div>
#endforeach
Can Someone please help me

Excluding all tables with XPath and Scrapy

I have the following html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Scrapy</title>
</head>
<body>
<table style="border: #ffffff 0px solid" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center">
<div style="margin-top:7px;margin-bottom:7px;font-size:16px;font-weight:bold;font-color:white" width="100%">
Scrapy Rocks
</div>
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" width="100%" style="margin-top:25px">
<tr>
<td align="left" valign="top"></td>
<td valign="top">
<font size="-1">
<div style="margin-right:10; margin-top:5; text-align: right">
AAA |
BBB |
CCC
</div>
</font>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div>
<a href="http://example.com" target="_blank">
<img src="/images/a.jpg" border="0" vspace="0" width="100" height="100" valign="middle"/>
</a>
<a href="/index.html">
<img src="/images/aaa.gif" border="0" vspace="0" width="100" height="100" valign="middle"/>
</a>
</div>
</td>
<td valign="top">
<div style="margin-right:10; margin-top:5; text-align: right"></div>
</td>
</tr>
</table>
<hr size=1>
<h2 style="margin-top: 36px; margin-bottom: 24px">
Abcd efgh for 2017
</h2>
Part 1 |
Part 2 |
Part 3 |
Part 4 |
A very bold title
<hr size="1" style="margin-top: 36px; margin-bottom: 24px">
<a name="part1"></a>
<h3>Part 1</h3>
<ul>
</ul>
<a name="part2"></a>
<h3>Part 2</h3>
<ul>
</ul>
<a name="part3"></a>
<h3>Part 3</h3>
<ul>
</ul>
<a name="part4"></a>
<h3>Part 4</h3>
<ul>
</ul>
<div style="margin-top: 36px; margin-bottom: 24px">
<a name="non_rep"></a>
<h3>Abcd efgh</h3>
</div>
<b>January 2017</b>
<ul>
<li>
<b>Part1 1</b>
</li>
<ul>
<li>
Title 1
</li>
<br>
<li>
Title 2
</li>
<br>
</ul>
<li>
<b>Part1 2</b>
</li>
<ul>
<li>
Title A
</li>
<br>
<li>
Title B
</li>
<br>
</ul>
<li>
<b>Part1 3</b>
</li>
<ul>
<li>
Some text 1
</li>
<br>
<li>
Some Text 2
</li>
</ul>
</ul>
<b>February 2017</b>
<ul>
<li>
<b>Part1 1</b>
</li>
<ul>
<li>
Title 1
</li>
<br>
<li>
Title 2
</li>
<br>
</ul>
<li>
<b>Part1 2</b>
</li>
<ul>
<li>
Title A
</li>
<br>
<li>
Title B
</li>
<br>
</ul>
<li>
<b>Part1 3</b>
</li>
<ul>
<li>
Some text 1
</li>
<br>
<li>
Some Text 2
</li>
</ul>
</ul>
<b>March 2017</b>
<ul>
<li>
<b>Part1 1</b>
</li>
<ul>
<li>
Title 1
</li>
<br>
<li>
Title 2
</li>
<br>
</ul>
<li>
<b>Part1 2</b>
</li>
<ul>
<li>
Title A
</li>
<br>
<li>
Title B
</li>
<br>
</ul>
<li>
<b>Part1 3</b>
</li>
<ul>
<li>
Some text 1
</li>
<br>
<li>
Some Text 2
</li>
</ul>
</ul>
</body>
</html>
What i need here is to extract the text between the body tags (using Scrapy xpath) but I don't want the tables text at all.
What I tried to get all the text was:
def parse(self, response):
"""
-*-
"""
item = DummyItem()
title = response.xpath('//title/text()').extract()
body = "\n ".join(
response.xpath(
'//body//*[not(self::script or self::style)]/text()'
).extract()
)
item['title'] = title
item['body'] = body
yield item
Whit the above stanza, I managed to extract all the text, tables inclusive, which I don't want.
Then I replaced the "body" with:
body = "\n ".join(
response.xpath(
'//body//*[not(self::table or self::script or self::style)]/text()'
).extract()
)
It didn't do the job. Still extracting the tables text.
Any ideas on how to tackle it?
You want "all text nodes that are not in a <table>", or "all text nodes that do not have a <table> ancestor".
That's /html/body//text()[not(ancestor::table)] in XPath.
text_nodes = response.xpath("/html/body//text()[not(ancestor::table)]").extract()
now you only need to strip whitespace from the resulting items and remove empty strings from the list.
body = "\n ".join(filter(None, map(str.strip, text_nodes)))

grouped vm output to a view

I'm looking for the best/simplest way to output the following using Razor (ASP.Net MVC 4)
<ul id="contacts">
<li data-group="a">
<a class="title">A</a>
<ul>
<li>
<a href="#">
<span class="thumbnail">
<img alt="" src="~/backendContent/sample/p4.jpg"></span> Adam Woodward
<span style="font-size: 11px; display: block;" class="muted">Creative Director</span>
</a>
</li>
<li>
<a href="#">
<span class="thumbnail">
<img alt="" src="~/backendContent/sample/p5.jpg"></span> Aileen Espinoza
<span style="font-size: 11px; display: block;" class="muted">Creative Director</span>
</a>
</li>
<li>
<a href="#">
<span class="thumbnail">
<img alt="" src="~/backendContent/sample/p6.jpg"></span> Aimee Foley
<span style="font-size: 11px; display: block;" class="muted">Creative Director</span>
</a>
</li>
</ul>
</li>
<li data-group="b">
<a class="title">B</a>
<ul>
<li>
<a href="#">
<span class="thumbnail">
<img alt="" src="~/backendContent/sample/p1.jpg"></span> Baker Terry
<span style="font-size: 11px; display: block;" class="muted">Creative Director</span>
</a>
</li>
</ul>
</li>
<li data-group="c">
<a class="title">C</a>
<ul>
<li>
<a href="#">
<span class="thumbnail">
<img alt="" src="~/backendContent/sample/p1.jpg"></span> Cadman Mosley
<span style="font-size: 11px; display: block;" class="muted">Creative Director</span>
</a>
</li>
<li>
<a href="#">
<span class="thumbnail">
<img alt="" src="~/backendContent/sample/p2.jpg"></span> Cailin Jones
<span style="font-size: 11px; display: block;" class="muted">Creative Director</span>
</a>
</li>
</ul>
</li>
.
.
.
as you can see its a contact list that will be formatted to a nice phonebook. I currently have a iqueryable that holds all the information in alphabetical order. I honestly was not sure on how to use razor to structure the above html. I thought about using a group function in linq and came up with the following linq expression:
var _customers = (from c in _db.UserProfiles.Include("ParentCompanies").Include("cProfile")
where (c.ParentCompanies.Any(pc => pc.CompanyUsers.Any(cu => cu.UserName == userName)) && c.cProfile != null)
group c by c.FirstName.Substring(0, 1) into customerGroup
select new { FirstLetter = customerGroup.Key, Information = customerGroup }).OrderBy(letter=>letter.FirstLetter);
but I came across some problems with the return type of the method (anonymous type) and I was not sure how to deal with that. I am now using the following:
var _customers = (from c in _db.UserProfiles.Include("ParentCompanies").Include("cProfile")
where (c.ParentCompanies.Any(pc => pc.CompanyUsers.Any(cu => cu.UserName == userName)) && c.cProfile != null)
select c).OrderBy(f=>f.FirstName);
I am very new to the asp.net MVC world and any help would be greatly appreciated.
You can declare a custom return type for your query and use that as your view model.
public class GroupedCustomersViewModel
{
string FirstLetter { get; set; }
IEnumerable<UserProfile> Information { get; set; }
}
....
var _customers =
(from c in _db.UserProfiles.Include("ParentCompanies").Include("cProfile")
where (c.ParentCompanies.Any(pc => pc.CompanyUsers.Any(cu => cu.UserName == userName)) && c.cProfile != null)
group c by c.FirstName.Substring(0, 1).ToUpper() into customerGroup
select new GroupedCustomersViewModel
{
FirstLetter = customerGroup.Key,
Information = customerGroup
})
.OrderBy(letter=>letter.FirstLetter);
In your .cshtml use
#model IEnumerable<MyProject.Namespace.Models.GroupedCustomersViewModel>
...
<ul id="contacts">
#foreach(var group in Model)
{
<li data-group="#group.FirstLetter.ToLower()">
<a class="title">#group.FirstLetter</a>
<ul>
#foreach(var user in group.Information)
{
<li>
<a href="#">
<span class="thumbnail">
<img alt="" src="#user.Thumbnail"></span> #user.Name
<span style="font-size: 11px; display: block;" class="muted">#user.Title</span>
</a>
</li>
}
</ul>
</li>
}
</ul>

Resources