Laravel notification blade else statement not working - laravel

I'm trying to show user notification if data is found in notification table else show 'notification not found' on user notification blade but else statement isn't working. It only shows user notification if found and a blank page if notification not found in table.
<body>
<main>
#include('siteLayout.sidebar')
<div class="wrapper">
#include('siteLayout.header')
<div class="main-container">
<div class="main-header">Notifications</div>
<div class="main-contents">
<ul class="notification-lists">
#foreach ($notifications as $notification)
#if ($notification != null)
#if ($notification->musicOwner == Auth::user()->id)
<li class="notification unread"><span class="notification-icon">
<div>You have notifications</div>
</li>
#else
<li class="notification unread"><span class="notification-icon">
<div>You have no notifications yet</div>
</li>
#endif
#endif
#endforeach
</ul>
</div>
</div>
</div>
</main>
</body>

Make sure the $notifications isn't empty as the foreach isn't working. If you would like to show the message if the $notifications is empty make it work like this, with forelse:
<body>
<main>
#include('siteLayout.sidebar')
<div class="wrapper">
#include('siteLayout.header')
<div class="main-container">
<div class="main-header">Notifications</div>
<div class="main-contents">
<ul class="notification-lists">
#forelse ($notifications as $notification)
#if ($notification != null)
#if ($notification->musicOwner == Auth::user()->id)
<li class="notification unread"><span class="notification-icon"> <div>You have notifications</div>
</li>
#endif
#endif
#empty
<li class="notification unread"><span class="notification-icon">
<div>You have no notifications yet</div>
</li>
#endforelse
</ul>
</div>
</div>
</div>
</main>
</body>

Related

Livewire Pagination is not responding

Why there is so much problems with this pagination from livewire? i have been see many topics of this.. and srsly i don't get it.. what wrong im doing? https://i.imgur.com/PENGFjf.gifv <- problem
if i go manualy and i write "?page=2" in url adress it is working, but i don't have any actions inside, clicking in pagination buttons
| "laravel/framework": "^8.54",
| "laravel/jetstream": "^2.3",
| "laravel/sanctum": "^2.6",
| "laravel/tinker": "^2.5",
| "livewire/livewire": "^2.5"
<?php
namespace App\Http\Livewire;
use App\Models\Product;
use Livewire\Component;
use Livewire\WithPagination;
class ShopComponent extends Component
{
use WithPagination;
public function render()
{
return view('livewire.shop-component', ['products' => Product::paginate(9)])->layout('layouts.base');
}
public function paginationView()
{
return 'livewire.custom-pagination';
}
}
Custom pagination is copy from vendor - bootstrap pagination
<div>
#if ($paginator->hasPages())
<nav class="pagination justify-content-center">
<ul class="pagination mt-30 mb-30">
{{-- Previous Page Link --}}
#if ($paginator->onFirstPage())
<li class="page-item disabled" aria-disabled="true" aria-label="#lang('pagination.previous')">
<span class="page-link" aria-hidden="true">‹</span>
</li>
#else
<li class="page-item">
<button type="button" dusk="previousPage" class="page-link" wire:click="previousPage" wire:loading.attr="disabled" rel="prev" aria-label="#lang('pagination.previous')">‹</button>
</li>
#endif
{{-- Pagination Elements --}}
#foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
#if (is_string($element))
<li class="page-item disabled" aria-disabled="true"><span class="page-link">{{ $element }}</span></li>
#endif
{{-- Array Of Links --}}
#if (is_array($element))
#foreach ($element as $page => $url)
#if ($page == $paginator->currentPage())
<li class="page-item active" wire:key="paginator-page-{{ $page }}" aria-current="page"><span class="page-link">{{ $page }}</span></li>
#else
<li class="page-item" wire:key="paginator-page-{{ $page }}"><button type="button" class="page-link" wire:click="gotoPage({{ $page }})">{{ $page }}</button></li>
#endif
#endforeach
#endif
#endforeach
{{-- Next Page Link --}}
#if ($paginator->hasMorePages())
<li class="page-item">
<button type="button" dusk="nextPage" class="page-link" wire:click="nextPage" wire:loading.attr="disabled" rel="next" aria-label="#lang('pagination.next')">›</button>
</li>
#else
<li class="page-item disabled" aria-disabled="true" aria-label="#lang('pagination.next')">
<span class="page-link" aria-hidden="true">›</span>
</li>
#endif
</ul>
</nav>
#endif
</div>
shop-component
https://i.imgur.com/bob483q.png
<div>
#foreach ($products as $product)
<div class="col-sm-6 col-lg-4 mb-30">
<div class="card product-card">
<div class="card-body">
<div class="product-thumbnail position-relative">
<span class="badge badge-danger top-right">New</span>
<a href="single-product.html">
<img class="first-img" src="{{ asset('assets/img/product/1.png') }}" alt="thumbnail" />
</a>
<!-- product links -->
<ul class="actions d-flex justify-content-center">
<li>
<a class="action" href="wishlist.html">
<span data-toggle="tooltip" data-placement="bottom" title="add to wishlist" class="icon-heart">
</span>
</a>
</li>
<li>
<a class="action" href="#" data-toggle="modal" data-target="#compare">
<span data-toggle="tooltip" data-placement="bottom" title="Add to compare" class="icon-shuffle"></span>
</a>
</li>
<li>
<a class="action" href="#" data-toggle="modal" data-target="#quick-view" >
<span data-toggle="tooltip" data-placement="bottom" title="Quick view" class="icon-magnifier"></span>
</a>
</li>
</ul>
</div>
<div class="product-desc py-0 px-0">
<h3 class="title">
{{ $product->name }}
</h3>
<div class="star-rating">
<span class="ion-ios-star"></span>
<span class="ion-ios-star"></span>
<span class="ion-ios-star"></span>
<span class="ion-ios-star"></span>
<span class="ion-ios-star de-selected"></span>
</div>
<div class="d-flex align-items-center justify-content-between" >
<span class="product-price">{{ $product->regular_price }}</span>
<button class="pro-btn" data-toggle="modal" data-target="#add-to-cart" >
<i class="icon-basket"></i>
</button>
</div>
</div>
</div>
</div>
</div>
#endforeach
{{-- Paginacja produktów --}}
{{ $products->links() }}
</div>
php artisan livewire:publish --config
php artisan livewire:publish --assets
second , make sure to add this lines in the main template.
<head>
#livewireStyles
</head>
<body>
{{ $slot }}
#livewireScripts
</body>

I am trying to show count on specific name using laravel 8

I am trying to show count on specific name which is the left side menu name "property" but getting count show in all menus please help me how can i show count only on property menu using laravel 8
helpers.php
function propertyCount()
{
$propertyModelPath = Menu::where('route',
'property')->where('count_show', 1)->first();
$modelClass = $propertyModelPath->modal_path;
$count = new $modelClass;
return $count->count();
}
left side bar menu
<div id="sidebar-menu">
<ul>
#foreach ($menus as $menu)
#if ($menu->parent_id == 0)
<li class="has_sub">
<a href="{{$menu->route == null ? 'javascript:void(0);' : route($menu->route)}}" class="waves-effect">
<i class="{{$menu->icon}}"></i>
<span> {{$menu->name}} {{propertyCount()}} </span>
#if ($menu->route == null)
<span class='menu-arrow'></span>
#endif
</a>
</li>
#endif
#endforeach
</ul>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</div>
</div>
You may use like this
<span>
{{$menu->name}}
#if($menu->name=='property')
{{propertyCount()}}
#endif
</span>

Laravel Pagination 3 dots not showing

I ran the command to generate the customization files for my blog's pagination.
I was able to customize the appearance of the buttons but the issue I now have is that when the page number gets to say 8, the pagination link shows up to 8 links. I would like to implement the '...' separator within the link. My bootstrap-4.blade.php is as follows
<div class="row">
<div class="col-12">
<ul class="pagination justify-content-center">
{{-- Previous Page Link --}}
#if ($paginator->onFirstPage())
<li>
<a aria-label="Next">
<i class="fas fa-arrow-left"></i>
</a>
</li>
#else
<li class="px-1">
<span><i class="fas fa-arrow-left"></i></span>
</li>
#endif
{{-- Pagination Elements --}}
#foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
#if ($paginator->currentPage() > 4 && $page === 2)
<li class="px-1"><span class="page-link">...</span></li>
#endif
{{-- Array Of Links --}}
#if (is_array($element))
#foreach ($element as $page => $url)
#if ($page == $paginator->currentPage())
<li class="px-1"><a style="background:#56107c; color:white; cursor:not-allowed;" href="{{ $url }}">{{ $page }}</a></li>
#else
<li class="px-1">{{ $page }}</li>
#endif
#endforeach
#endif
#endforeach
{{-- Next Page Link --}}
#if ($paginator->hasMorePages())
<li class="px-1">
<span><i class="fas fa-arrow-right"></i></span>
</li>
#else
<li>
<a aria-label="Next">
<i class="fas fa-arrow-right"></i>
</a>
</li>
#endif
</ul>
</div>
</div>
#endif
You can use a built in function $posts->links(), it will auto create everything - links, numbers and next.

I want to get a pop-up notification when new value in inserted in my mysql database table using Laravel

I want to show a successful message as notification in my home page when a new value is inserted into my database.
Controller
function insert(Request $request)
{
$teacher = new teacher;
$teacher->Teacher_name = $request->Teacher_name;
$teacher->School_name = $request->School_name;
$teacher->Date_of_Birth = $request->Date_of_Birth;
$teacher->save();
$teacher = teacher::find($request->id);
return back()->with('success', 'Data inserted Successfully');
}
View
<ul class="nav navbar-nav navbar-left">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span
class="label label-pill label-danger count" style="border-
radius:10px;"></span> <span class="glyphicon glyphicon-bell"
style="font-size:18px;"></span></a>
<ul class="dropdown-menu">
</ul>
</li>
</ul>
In Laravel, you can show success or failure alerts using Flash as below,
Controller:
\Session::flash('success', 'Data inserted Successfully.');
Blade file:
#if ($message = \Session::get('success'))
<div class="alert success-msg">
{{ $message }}
</div>
#endif
UPDATE:
To keep message in blade until closed;
#if (session()->has('success'))
<div class="alert alert-dismissable alert-success">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>
{!! session()->get('success') !!}
</strong>
</div>
#endif
UPDATE:2
To get real time notification, you can use Pusher and implementation guide for the same is: https://www.sitepoint.com/add-real-time-notifications-laravel-pusher/
Hope this helps.
Use Flash,
Controller:
\Session::flash('success', 'Data inserted Successfully.');
Blade file:
#if ($message = \Session::get('success'))
<div class="modal hide fade" id="myModal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<p>{{$message}}</p>
</div>
<div class="modal-footer">
Close
</div>
</div>
<script> $('#myModal').modal('show');</script>
#endif
Post this after you Load jquery and bootstrap.

shoping cart data display in laravel

I want to display the order details form database. I store cart data into database using serialize method. When i want to display data i can not properly show it. only can print order object. And there give that a error.That is
(1/1) FatalErrorException syntax error, unexpected 'endforeach'
(T_ENDFOREACH) in 9ad30ab1db6ca668d8a75c428e65858dc800d045.php line 27
.
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h1>User Profile</h1>
<hr>
<h2>My Oders</h2>
#foreach($orders as $order)
<div class="panel panel-default">
<div class="panel-body">
<ul class="list-group">
#forecah($order->cart->items as $product)
<li class="list-group-item">
<span class="badge">{{$product['product_price']}}
</span>
{{$product['item']['product_name']}} |
{{$product['qty']}} Units
</li>
#endforeach
</ul>
</div>
<div class="panel-footer">
<strong>Total Price : {{$order->cart->totalPrice}}</strong>
</div>
</div>
#endforeach
</div>
</div>
You have typo in your code:
#forecah($order->cart->items as $product)
Try to change into:
#foreach($order->cart->items as $product)e
Hope it works..as it does not detect the foreach loop before.
You have wrong spelling of forecah. you should correct the spelling.
Look at the second foreach and change the spelling.
You can copy code below as i have changed the spelling.
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h1>User Profile</h1>
<hr>
<h2>My Oders</h2>
#foreach($orders as $order)
<div class="panel panel-default">
<div class="panel-body">
<ul class="list-group">
#foreach($order->cart->items as $product)
<li class="list-group-item">
<span class="badge">{{$product['product_price']}}
</span>
{{$product['item']['product_name']}} |
{{$product['qty']}} Units
</li>
#endforeach
</ul>
</div>
<div class="panel-footer">
<strong>Total Price : {{$order->cart->totalPrice}}</strong>
</div>
</div>
#endforeach
</div>

Resources