i am not able to find order through id in laravel - 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

Related

Is it possible to generate PDF using dompdf from form data before submitting the form to database in laravel?

Applogies for the question again. I'm new to laravel and this is my first project.
I'm trying to generate a pdf using DomPDF but before submitting my form to database, I dont know whether it is possible or not.
this is my create.blade.php code
#extends('layouts.main')
#section('content')
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Orders</h1>
</div>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-12">
<div>
<div class="card-header">{{ __('Creating Order') }}
Back
</div>
<div>
<form method="GET" action="{{ route('orders.create') }}" enctype="multipart/form-data">
#csrf
<div class="form-row align-items-center">
<div class="form-group col-md-6 col-lg-5">
<select id="customer_name" onchange="this.form.submit()" type="search" name="customer_id" class="form-control #error('customer_id') is-invalid #enderror" value="{{ old('customer_id') }}" required >
<option selected></option>
#foreach ($customers as $customer)
<option value="{{ $customer->id }}">{{ $customer->customer_name }}</option>
#endforeach
</select>
#error('customer_id')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="col-auto">
<input id="btn" type="button" class="btn btn-primary mb-3" value="Show Catalog" onclick="showDiv()">
</div>
</div>
<div class="m-3">
Displaying Catalog for: <strong> <span style="color: red" id="customerName"></span><span style="color: red">. {{$count_linkeds}}</span></strong> items found in this Catalog.
</div>
</form>
<form method="POST" action="{{ route('orders.store') }}" enctype="multipart/form-data">
#csrf
<main id="catalog" style="display: none" class="main">
<div class="container">
<div class="row s6 m3">
#foreach($linkeds as $lnkditem)
<div class="col s6 m3">
<div class="card item-images">
<div class="img-wrapper">
<img src="{{ asset('uploads/linkedItems/'.$lnkditem->item_image) }}" width= '50' height='50' class="img img-responsive" />
</div>
<div class="card-content mt-2 item">
<h6 style="font-size: 18px">
Product Name: <strong style="color: red">{{ $lnkditem->product->product_name}}</strong>
</h6>
<div style="float: right; margin-top: -30px">
<label hidden style="float: right;" for="linked_id">{{ __(': Linked ID') }}</label>
<textarea hidden style="text-align: center; resize: none; width:100px; height: 28px; overflow:hidden; border:none; background-color: #f8f8f8;" readonly rows="1" name="linked_id" id="linked_id" class="form-control"
value="{{ old('linked_id', $lnkditem->id) }}">{{ $lnkditem->id}}</textarea>
</div>
<p>
Product description: <strong style="color: red"> {{ $lnkditem->product->product_description}}</strong>
</p>
Item Name: <span readonly id="item_name" name="item_name" style="font-weight: bold; color: black" value="{{ $lnkditem->item->item_name}}">{{ $lnkditem->item->item_name}}</span>
<p>
Item description: <strong style="color: black"> {{ $lnkditem->item->item_description}}</strong>
</p>
<p>
Supplier Ref.: <strong style="color: black"> {{ $lnkditem->supplier_ref_no}}</strong>
</p>
<p>
Supplier Barcode: <strong style="color: black"> {{ $lnkditem->supplier_barcode}}</strong>
</p>
<div class="pass-quantity col-lg-3 col-md-4 col-sm-3 pl-0">
<label for="item_quantity" class="pass-quantity">Quantity:</label>
<input style="color: red" name="item_quantity" class="form-control" type="number" value="0" min="0">
</div>
<div>
<label for="pass-quantity" class="pass-quantity" style="color: red; font-weight: bold; float: right; margin-right: 45px !important; margin-top: -32px">Item Price: AED - </label>
<p type="number" name="item_cost" class="item_cost" style="color: red; font-weight: bold; float: right; margin-top: -32px">
{{ $lnkditem->item_cost}}
</p>
</div>
<div class="product-price d-none">{{ $lnkditem->item_cost}}</div>
<hr class="sidebar-divider">
<strong style="color: red"><p>Total Amount: AED:</p></strong>
<div class="product-line-price pt-4 pb-4 text-uppercase" style="color: red; font-weight: bold; float: right; margin-top: -67px">
<strong><span style="color: red" type="number" class="product-line-price">0.00</span></strong>
</div>
</div>
</div>
</div>
#endforeach
</div>
</div>
<div class="card card-action mb-3 pt-4" style="padding: 15px; height: 100%; width: 50%; margin-left: 25%">
<div class="mb-3" style="margin-left: 15px">
<label for="order_unq_id"></label>
Order UID: <textarea name="order_unq_id" style="color: red; font-weight: bold; width: 350px; resize: none; margin-left: 22%; margin-top: -31px !important; height: 38px; overflow:hidden; border:none; background-color: #f8f8f8;" readonly rows="1" id="order_unq_id" class="form-control #error('order_unq_id') is-invalid #enderror" value="{{ old('order_unq_id') }}">
</textarea>
</div>
<div style="margin-left: 20px">
Saving Order for - <strong> <span class="text-uppercase" style="color: red" id="order_save_customerName"></span></strong>
<input type="text" class="customerName_order_save_input" hidden id="customerName_order_save_input" value="">
</div><br>
<div class="col-xl-12 col-lg-4 col-md-5 totals">
<div class="border border-gainsboro mb-3 px-3">
<div class="border-bottom border-gainsboro">
<p class="text-uppercase mb-0 py-3 bg-primary text-white text-center"><strong>Order Summary</strong></p>
</div>
<p class="mt-3 text-uppercase">Subtotal AED:</p>
<div class="totals-item d-flex align-items-center justify-content-between"
style="float: right; margin-top: -40px">
<p class="totals-value" id="cart-subtotal"></p>
</div>
<div class="totals-item d-flex align-items-center justify-content-between">
<p class="text-uppercase">Aprox. VAT #5%</p>
<p class="totals-value tax" id="cart-tax"></p>
</div>
<div class="totals-item totals-item-total d-flex align-items-center justify-content-between mt-3 pt-3 border-top border-gainsboro">
<label for="total" class="text-uppercase" style="color: red;"><strong>grand Total</strong></label>
<input type="text" class="total_input" hidden id="total_input" name="total_input" value="0.00">
<textarea style="self-align: center; text-align: right; color: red; padding-top !important; 10px; resize: none; width:100px; height: 35px; overflow:hidden; border:none; background-color: white; font-size: 18px" readonly rows="1"
class="totals-value font-weight-bold cart-total" name="total" id="total" style="color: red;"></textarea>
</div>
</div>
</div>
<div>
<a type="submit" target="_blank" class="btn btn-success" href="{{route('mht_order_pdf')}}">Generate PDF</a>
</div>
<button type="submit" class="btn btn-primary" id="save_order" >Save Order</button>
</div>
</main>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
I dont want pdf to get data from database. I need to generate the pdf with form data before form gets submit to database. Is this possible to achive? Thank you in advance.
In terms of tecnicality, this is possible. Personally I've done something like this, only that the PDF is being generated after the form is stored to DB, but before the request is sent back to users.
So in the controller, you can do something like this:
// first validate request inputs..
// then generate the PDF
PDF::generate('order_pdf'); // or something, idk what's the actual syntax
// finally
return view('order_dashboard');
However you need to know that while the PDF::generate() line is being executed, the app will wait until it finished before moving to the next line, meaning that the execution is being done synchronously. Thus if the PDF generation takes too long, user will have to wait for it. To face this issue, you might want to look at Laravel's Queue so that the PDF generation can be executed asynchronously.

How to upload Multiple Images in Laravel web page?

It uploads multiple images in database with below code as well as in admin panel but the problem is the images does not appear in laravel web page means it displays one image replace another image. Pls anyone can help me.
CMS Controller
public function store(Request $request)
{
$ginput = [];
if($request->hasFile('gallery')){
$files = $request->file('gallery');
foreach ($files as $file) {
$ginput[] = ImageUpload::upload('/upload/cms',$file);
}
$input['gallery'] = implode(',', $ginput);
}
}
Form.blade
<div class="col-md-12">
<p>Gallery Image</p>
<div class="col-md-6 col-md-offset-3">
<input type="file" name="gallery_multiple[]" class="form-control" multiple="multiple">
</div><br><br>
<p class="text-center">- OR -</p>
</div>
#if(isset($cms) && !empty($cms->gallery))
<?php
$galleryArray = explode(',', $cms->gallery);
?>
#if(!empty($galleryArray) && count($galleryArray) > 0)
#foreach($galleryArray as $gallery)
<div class="col-md-3 mb-4 gallery-image-parent">
<input class="upload property-image-input" type="hidden" value="{{ $gallery }}">
<div class="fuzone">
<div class="fu-text" style="margin: 0px;height: 100%;">
<img src="{{ asset('/upload/cms/'.$gallery) }}" class="property-image-preview">
</div>
<i style="background-color: red; color: #fff; height: 30px !important; width: 30px !important; border-radius: 50% !important; padding-top: 5px !important; position: relative !important; top: -160px !important; right: -92px !important;" class="fa fa-trash-o gallery-image-remove" data-page-type="{{ !isset($cms) ? 'create' : 'edit' }}" data-id="{{ $cms->id }}" data-image-name="{{ $gallery }}" style="font-size: 20px;top: -165px;"></i>
</div>
</div>
#endforeach
#endif

Bootstrap image card text overlay

Unable to set card footer as expected output
Expected output:
My Code:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-md-3">
<div class="card">
<img src="https://images.unsplash.com/photo-1523805009345-7448845a9e53?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=752&q=80" class="card-img-top" alt="...">
<div class="card-img-overlay">
<h5 class="card-title"></h5>
</div>
<div class="card-footer text-center">
<h6>
Africa
</h6>
<h4>
Kenya
</h4>
</div>
</div>
</div>
jsfiddle: https://jsfiddle.net/sidh_41/p8sdfy7u/2/
.card-footer:last-child {
border-radius: 0!important;
}
.card-footer {
padding: 0!important;
background-color: unset!important;
border-top: unset!important;
}
.text-center {
color: #fff;
}
.card-img-overlay {
display: flex;
flex-direction: column;
justify-content: flex-end;
height: 100%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-md-3">
<div class="card">
<img src="https://images.unsplash.com/photo-1523805009345-7448845a9e53?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=752&q=80" class="card-img-top" alt="...">
<div class="card-img-overlay">
<h5 class="card-title"></h5>
<div class="card-footer text-center">
<h6>
Africa
</h6>
<h4>
Kenya
</h4>
</div>
</div>
</div>
</div>
Try this:
.card-footer:last-child {
border-radius: 0!important;
}
.card-footer {
padding: 0!important;
background-color: unset!important;
border-top: unset!important;
}
.text-center {
color: #fff;
}
.card-img-overlay {
display: flex;
flex-direction: column;
justify-content: flex-end;
height: 100%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-md-3">
<div class="card">
<img src="https://images.unsplash.com/photo-1523805009345-7448845a9e53?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=752&q=80" class="card-img-top" alt="...">
<div class="card-img-overlay">
<h5 class="card-title"></h5>
<div class="card-footer text-center">
<h6 class="m-0 small">
AFRICA
</h6>
<h1>
Kenya
</h1>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="card">
<img class="card-img" src="https://images.unsplash.com/photo-1523805009345-7448845a9e53?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=752&q=80" alt="...">
<div class="card-img-overlay">
<h5 class="card-title"></h5>
<div class="card-footer text-center">
<h6>
Africa
</h6>
<h4>
Kenya
</h4>
</div>
</div>
</div>
</div></div>
I think you need to add another div surrounding the card. This div needs to have the class row
.img-wrapper{
position: relative;
text-align: center;
color: white;
}
.card-footer{
position: absolute;
top: 60%;
left: 50%;
transform: translate(-50%, -50%);
}
h3, h1{
color: #fff
}
<div class="col-md-3">
<div class="card">
<div class="img-wrapper">
<img src="https://images.unsplash.com/photo-1523805009345-7448845a9e53?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=752&q=80" class="card-img-top" alt="...">
<div class="card-img-overlay">
<h5 class="card-title"></h5>
</div>
</div>
</div>
<div class="card-footer text-center">
<h3>
Africa
</h3>
<h1>
Kenya
</h1>
</div>
</div>
</div>

laravel 5.4 pagination issue invalid argument supplied for foreach()

I have around 50 objects in an array.
$user = User::with('abc','def','ghi','jkl','mno','pqr')
->where([['id', '<>', Auth::user()->id],['role', '<>', 2]])->simplePaginate(15);
$users = json_decode($user,true);
Have I placed ->simplePaginate(15) this correctly? Can I do json_decode after that? like I am doing? I dont get any error in controller.
In Views
#section('content')
<div class="container-fluid">
<div></br></br></div>
#include('errors.list')
<div class="row">
#foreach($users as $user)
<a href="#" onclick=document.getElementById('{{$user->id}}').style.display='block'>
<div class="col-md-3" style="margin-bottom:50px;">
#if($user["search_status"] == 'matched')
<div class="w3-card-12-disabled" style="border-radius:15px;width:225px; padding-top: 20px; background-color: #FFA534;">
#else
<div class="w3-card-12" style="border-radius:15px;width:225px; padding-top: 20px; background-color: #FFA534;">
#endif
<img align="center" src="{{$user->photo}}" style=" border-radius:50%; ; border-style: solid; border-color: #333; border-width: 5px; margin-left:15%;" width="150px !important" height="150px !important" />
<h3 style="color:#000;
padding-top: 20px;" align="center">{{ $user->firstname}}</br>{{ $user->lastname}}</h3>
<div style="display:flex; justify-content: center;">
<div class="tooltip2">
<img align="middle" style="" src="{{$user->natives->flag}}"/>
<span class="tooltiptext">{{$user->natives->language}}</span>
</div>
</div>
</br>
</div>
</div>
</a>
#endforeach
<div class="row">
#foreach($users as $user)
<div id="{{$user->id}}" class="w3-modal">
<div class="w3-modal-content w3-animate-top w3-card-8">
<div id="div1" style="padding:40px 30px 30px 30px;">
<img style="border-radius:50%; border:5px solid #333; margin-left:18px" src="{{$user->photo}}" width="200px !important" height="200px !important">
<div style="text-align: center; padding-top:70px;">
{!! Form::open(['url' => '/users/'. $user->id.'/reportc']) !!}
{!! Form::hidden('_method', 'POST') !!}
{!! Form::hidden('friend', $user->id, null, ['class'=>'form-control']) !!}
{!! Form::submit('Report', ['class'=>'btn', 'style' => 'padding: 10px 10px 10px 10px; color:#000; border-color:#000;']) !!}
{!! Form::close() !!}
</div>
</div>
<div id="div2" style="padding:40px 0px 40px 0px;">
<span onclick=document.getElementById('{{$user->id}}').style.display='none'
class="w3-closebtn">×</span>
<h1>{{ $user->firstname}} {{ $user->lastname}}</h1>
</br>
</br>
<h5 style="padding-top:30px;"><b>About Me:</b> {{ $user->bio}} </h5>
<h5 style="padding-top:10px;"><b>Campus:</b> {{$user->campus->campus_name}}</h5>
<h5 style="padding-top:10px;"><b>School:</b> {{ $user->schools->schools_name}} </h5>
<h5 style="padding-top:10px;"><b>Year:</b> {{ $user->years->years_name}} </h5>
<h5 style="padding-top:10px;"><b>Native Speaker of:</b> {{$user->natives->language}} </h5>
<h5 style="padding-top:10px;"><b>Second Native Speaker of:</b> {{ $user->snatives->language }} </h5>
<h5 style="padding-top:10px;"><b>Seeking Speaker of:</b>
#foreach($seeks as $seek)
#if($seek->user_id === $user->id)
{{ $seek->language}},
#endif
#endforeach </h5>
</div>
</div>
</div>
#endforeach
</div>
{!! $users->links() !!}
</div>
</div>
#endsection
Even if I dont put this code {{ $users->links() }} in view I still get same error. I guess issue is with the pagination code on controller.
Edited
I have this small issue still:
Before
<h5 style="padding-top:10px;"><b>Campus:</b> {{$user['campus']['campus_name']}}</h5>
<h5 style="padding-top:10px;"><b>School:</b> {{ $user['schools']['schools_name']}} </h5>
<h5 style="padding-top:10px;"><b>Year:</b> {{ $user['years']['years_name']}} </h5>
<h5 style="padding-top:10px;"><b>Native Speaker of:</b> {{$user['natives']['language']}} </h5>
<h5 style="padding-top:10px;"><b>Second Native Speaker of:</b> {{$user['snatives']['language']}} </h5>
<h5 style="padding-top:10px;"><b>Seeking Speaker of:</b>
#foreach($seeks as $seek)
#if($seek->user_id === $user['id'])
{{ $seek->language}},
#endif
#endforeach </h5>
After
<h5 style="padding-top:10px;"><b>Campus:</b> {{$user->campus->campus_name}}</h5>
<h5 style="padding-top:10px;"><b>School:</b> {{ $user->schools->schools_name}} </h5>
<h5 style="padding-top:10px;"><b>Year:</b> {{ $user->years->years_name}} </h5>
<h5 style="padding-top:10px;"><b>Native Speaker of:</b> {{$user->natives->language}} </h5>
<h5 style="padding-top:10px;"><b>Second Native Speaker of:</b> {{$user->snatives->language}} </h5>
<h5 style="padding-top:10px;"><b>Seeking Speaker of:</b>
#foreach($seeks as $seek)
#if($seek->user_id === $user->id)
{{ $seek->language}},
#endif
#endforeach </h5>
This gives After code gives me error trying to get property of non-object which is why I was using json_decode() and Before code. How do I fix these?
result
{
"per_page":12,
"current_page":1,
"next_page_url":"http:\/\/localhost:8000\/users\/community?page=2",
"prev_page_url":null,
"from":1,
"to":12,
"data":[
{
"id":5,
"firstname":"Beth",
"lastname":"Hanley",
"email":"bah3#org.uk",
"role":1,
"photo":"uploads\/2.jpg",
"bio":"Hockey fan, foodie, gamer, Saul Bass fan and HTML5 Guru.",
"campus":{
"id":1,
"campus_name":"name"
},
"school":"1",
"year":"1",
"native_lang":"2",
"native_lang_flag":"2",
"search_status":"available",
"created_at":null,
"updated_at":null,
"lastlogin":null,
"verification_code":null,
"isverify":"0",
"native_lang_2":null,
"native_lang_flag_2":null,
"schools":{
"id":1,
"schools_name":"School of Energy, Geoscience, Infrastructure and Society"
},
"years":{
"id":1,
"years_name":"First"
},
"flags":{
"id":2,
"name":"\u00c5land Islands",
"flag":"\/flags\/AX-32.png"
},
"natives":{
"id":2,
"language":"English",
"flag":"\/flags\/GB-32.png"
},
"snatives":null
},
User Model
public function friends()
{
return $this->hasMany('App\Friend','friend_id','id');
}
public function seeks()
{
return $this->belongsToMany('App\Language');
}
public function natives()
{
return $this->hasOne('App\Language','id','native_lang');
}
public function snatives()
{
return $this->hasOne('App\Language','id','native_lang_2');
}
public function roles()
{
return $this->hasOne('App\Role','id','role');
}
public function campus()
{
return $this->hasOne('App\Campus','id','campus');
}
public function schools()
{
return $this->hasOne('App\School','id','school');
}
public function years()
{
return $this->hasOne('App\Year','id','year');
}
public function flags()
{
return $this->hasOne('App\Flag','id','native_lang_flag');
}
Campus Model
public function users()
{
return $this->belongsTo('App\User','campus','id');
}
Year Model
public function users()
{
return $this->belongsTo('App\User','year','id');
}
You don't need to json encode anything and access the object property directly.
Controller
$users = User::with('abc','def','ghi','jkl','mno','pqr')
->where([
['id', '<>', auth()->id()],
['role', '<>', 2]
])->simplePaginate(15);
return view('someview', compact('users'));
View
<div class="row">
#foreach($users as $user)
<a href="#" onclick="document.getElementById('{{ $user->id }}').style.display='block'">
<div class="col-md-3" style="margin-bottom:50px;">
#if($user->search_status == 'matched')
<div class="w3-card-12-disabled"
style="border-radius:15px;width:225px; padding-top: 20px; background-color: #FFA534;">
#else
<div class="w3-card-12"
style="border-radius:15px;width:225px; padding-top: 20px; background-color: #FFA534;">
#endif
<img align="center" src="{{ $user->photo }}"
style=" border-radius:50%; ; border-style: solid; border-color: #333; border-width: 5px; margin-left:15%;"
width="150px !important" height="150px !important"/>
<h3 style="color:#000;
padding-top: 20px;" align="center">{{ $user->firstname }}<br/>{{ $user->lastname}}</h3>
<br/>
</div>
</div>
</div>
</a>
#endforeach
</div>
{!! $users->links() !!}

if array empty blade 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

Resources