this is my code
in the app.blade.php, i added this code to the navbar. The count method is working fine. I just can't display the notification data value.
<a class="nav-link" data-toggle="dropdown" href="#">
<i class="fa fa-comments">Business Alerts</i>
<span class="badge badge-danger navbar-badge">{{ count(auth()->user()->unreadNotifications) }}</span>
</a>
<ul class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
#foreach (auth()->user()->unreadNotifications as $notification)
<li class="dropdown-divider"></li>
<a href="#" class="dropdown-item">
{{--<i class="fas fa-info mr-2 green"></i>{{ $notification->type }}--}}
#include('layouts.partials.notification.'.snake_case(class_basename( $notification->type )))
{{ $notification->data['user']['email'] }}//it works only if i remove this line
</a>
#endforeach
<div class="dropdown-divider"></div>
See All Messages
</ul>
</li>
#endforeach
In the browser i'm getting this
Undefined index: alert (View: C:\laragon\www\test\resources\views\layouts\partials\notification\test.blade.php)
when i try
dd( $notification->data['alert']['id'] )
it display 2
this is the controller code
public function store(Request $request)
{
$user = User::find($request['user_id']);
$alert = ProductAlert::findOrFail($request['alert_id']);
$alert->alert_qty -= $request['alert_qty'];
$alert->save();
$user->notify(new StockEpuise(json_decode($alert)));
return invest::create([
'alert_id' => $request['alert_id'],
'user_id' => $request['user_id'],
'alert_type' => $request['alert_type'],
'alert_qty' => $request['alert_qty'],
]);
}```
I don't know what is the problem
Related
I am trying to show notification but unfortunately i am getting error if work permit table has not record how can i resolve this issue ? thnaks.
Trying to get property 'id' of non-object (View: /home/zubair/htdocs/permit-to-work/cms/resources/views/cms/layouts/header.blade.php)
view blade
#php
$notifications = getNotication();
#endphp
#foreach ($notifications as $notification)
<div class="notification-load">
<a href="{{route('work.permit.edit',$notification->workPermit->id)}}" class="dropdown-item notify-item ">
<div class="notify-icon bg-blue">
<i class="fas fa-file-alt text-white">
</i>
</div>
#php
$date=$notification->workPermit->validty_to;
$timestamp = strtotime($date);
$validty_date = date("d,M ,Y", $timestamp);
#endphp
<p class="text-muted mb-0 user-msg ">
<b>
<small class="notification_list">Permit No {{$notification->workPermit->permit_code}} validity is about to end at {{$validty_date}}
</small>
</b>
</p>
</a>
</div>
#endforeach
use this helper function
optional($notification->workPermit)->id
instead of that
$notification->workPermit
Controller:
public function shopfront(){
$products=Product::all();
$categories=Category::all();
return view('shop.index',compact('products','categories'));
}
index.blade.php:
<div class="sidebar-widget">
<h4 class="pro-sidebar-title">Categories</h4>
<div class="sidebar-widget-list mt-30">
<ul>
#foreach ($categories as $category)
#foreach ($products as $product)
#if ($category->id==$product->category->id)
<li>
<div class="sidebar-widget-list-left">
<input type="checkbox"> <a href="">{{ $category->name }}
{{-- <span>4</span> --}}
</a>
<span class="checkmark"></span>
</div>
</li>
#endif
#endforeach
#endforeach
</ul>
</div>
</div>
I do not know how to achieve this, will highly appreciate some help or i sample that i can work with
Image
i don't know how you want to achieve it but let me give you an idea if you want it in this way:
when click on a category then it should show all products of that category:
in your blade file
#foreach($categories as $category)
<li class="nav-item">
<a class="nav-link" href="{{route('category.products',$category->name)}}"> {{$category->name}}</a>
</li>
#endforeach
you should create a route named category.products as below in web.php
Route::get('category/{name}','YourController#yourmethod')->name('category.products');
controller
public function CategoryProducts($name){
$category = Category::where('name',$name)->first();
$products = $category->products;
return view('front-end.categoryWise-products',compact('products'));
}
you can customize it according to your requirements.
when i store new order i want th deliverer with "deliverer_id" get notified
public function store(Request $request)
{
$order = Order::create([
'deliverer_id' => $request->input('deliverer_id'),
'product_id' => $request->input('product_id'),
'responsible_id'=>$request->input('responsible_id'),
'quantity'=> $request->input('quantity'),
'totalprice' => $request->input('totalprice'),
'client_name' => $request->input('client_name'),
'client_phone' => $request->input('client_phone'),
'client_city'=> $request->input('client_city'),
]);
return redirect()->route('orders.index');
}
i want to show a notification say there is a new order on this view
<li class="nav-item btn-rotate dropdown new-order">
<a class="nav-link dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="nc-icon nc-bell-55"></i>
<p>
<span class="badge badge-link text-danger notif-count" data-count="8">8</span>
</p>
</a>
<div class="dropdown-menu dropdown-menu-right newor">
<a class="dropdown-item" href="#">New order</a>
</div>
</li>
Simple wayout here is to set the flash session data in controller method, for example:
session()->flash('newOrderReceived', true);
Then on view file, you can check to see if the session has that key. If yes, then show the notification. For example, to show bootstrap4 alert message if session has given key:
#if(session('newOrderReceived'))
<div class="alert alert-primary" role="alert">
There is a new order
</div>
#endif
i have database notification, and i was trying to redirect the user whenever they click one of the notification link it will go to the exact POST id,then mark as read that particular notification being selected. but i couldn't make it work
Here is my controller
public function readbyid($id){
if(isset($notification->data['id'])){
return redirect()->action(
'PostController#show', ['id' => $notification->data['id']]
);
}else{
return redirect()->back();
}
}
Notification Model
public function toArray($notifiable)
{
return [
'id' => $this->post->id,
];
}
Blade View:
<li class="nav-item dropdown"> <a id="messages" rel="nofollow" data-target="#" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link"><i class="fa fa-bell"></i>#if (auth()->user()->unreadnotifications->count())<span class="badge badge-warning">{{auth()->user()->unreadnotifications->count()}}</span>#endif</a>
<ul aria-labelledby="notifications" class="dropdown-menu">
<li><a rel="nofollow" href="{{Url('markread')}}" class="dropdown-item all-notifications text-center"> <strong> <i class="fa fa-bell"></i>Mark all as Read</strong></a></li>
#foreach(auth()->user()->unreadnotifications as $notify)
<li><a rel="nofollow" href="{{Url('markread/{id}')}}" class="dropdown-item d-flex">
<div class="msg-body">
<h3 class="h5">{{$notify->data['title']}}</h3>
</div> </a></li>#endforeach
</ul>
</li>
Route:
Route::get('markread/{id}', 'NotifyController#readbyid' );
I'm implementing the Jump to... functionality in my project. What I want is:
If the user is in the first item the left button is NOT included.
If the user is in the last item the right button is NOT included.
The left button should have a link same with the link before the current/selected item.
The right button should have a link same with the link after the current/selected item.
Please see my code below:
Controller
$course = Course::with([
'assignments' => $undeleted,
'quizzes' => $undeleted,
'add_links' => $undeleted
])->findOrFail($id);
$course_items = collect($course->assignments);
$course_items = $course_items->merge(collect($course->quizzes));
$course_items = $course_items->merge(collect($course->add_links));
$course_items = $course_items->sortBy('item_number');
View
<div class="jump-to">
<div class="pull-right">
<div class="btn-group" role="group">
#foreach($course->topics as $topic)
#foreach(collect($topic->assignments)->merge(collect($topic->quizzes))->merge(collect($topic->add_links))->sortBy('item_number') as $first_item)
#if($first_item->id != $assignment->id)
<a href="#" class="btn btn-primary">
<i class="fa fa-angle-left"></i>
</a>
#endif
<?php break 2; ?>
#endforeach
#endforeach
<div class="btn-group" role="group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Jump to <div class="caret"></div>
</button>
<ul class="dropdown-menu" role="menu">
#foreach($course->topics as $topic)
<li class="jdivider">
Topic {{ $topic->topic_number }}
</li>
#foreach(collect($topic->assignments)->merge(collect($topic->quizzes))->merge(collect($topic->add_links))->sortBy('item_number') as $topic_item)
<li>
#if($topic_item->item_type() == 'assignment')
<a title="Assignment: {{ $topic_item->name }}" class="regular-link" href="{{ route('assignment.view', ['course_id' => $course->id, 'id' => $topic_item->id]) }}">
<i class="fa fa-tasks"></i> {{ str_limit($topic_item->name, 15) }}
</a>
#elseif($topic_item->item_type() == 'quiz')
<a title="Quiz: {{ $topic_item->name }}" class="regular-link" href="{{ route('quiz.view', ['course_id' => $course->id, 'id' => $topic_item->id]) }}">
<i class="fa fa-file-text"></i> {{ str_limit($topic_item->name, 15) }}
</a>
#elseif($topic_item->item_type() == 'add_link')
<a href="#">
#if(!empty($topic_item->file_location) && in_array(strtolower(last(explode('.', $topic_item->file_location))), ['pdf', 'docx', 'doc']))
<i class="fa fa-file-pdf-o"></i>
#elseif(empty($topic_item->file_location))
<i class="fa fa-globe"></i>
#else
<i class="fa fa-file-text-o"></i>
#endif
{{ str_limit($topic_item->name, 15) }}
</a>
#endif
</li>
#endforeach
#endforeach
</ul>
</div>
<a href="#" class="btn btn-primary">
<i class="fa fa-angle-right"></i>
</a>
</div>
</div>
</div>
Example
dropdown links:
Assignment1
Assignment2
Quiz1
QUiz2
Reviewer1
If I clicked Assignment2, the left button, has the id or link to Assignment1. If I clicked Reviewer1, the right button disappears and the left button has the id or link to Quiz2 and same with the other links.