Skip to content

Commit 3bdb7b4

Browse files
initcommit notification&readnotification
1 parent f3946eb commit 3bdb7b4

File tree

10 files changed

+180
-7
lines changed

10 files changed

+180
-7
lines changed

app/Http/Controllers/CartController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function add_to_cart(Request $request)
3939
], [
4040

4141
'price' => $product->sale_price ? $product->sale_price : $product->price,
42-
'quantity' => DB::raw('quantity + ' . $request->quantity),
42+
'quantity' => DB::raw(' + ' . $request->quantity),
4343
]);
4444

4545
return redirect()->back()->with('msg', 'product added to cart successfully');

app/Notifications/NewOrder.php

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace App\Notifications;
4+
5+
use FontLib\Table\Type\name;
6+
use Illuminate\Bus\Queueable;
7+
use Illuminate\Notifications\Notification;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
9+
use Illuminate\Notifications\Messages\MailMessage;
10+
11+
class NewOrder extends Notification
12+
{
13+
use Queueable;
14+
15+
public $order;
16+
/**
17+
* Create a new notification instance.
18+
*
19+
* @return void
20+
*/
21+
public function __construct($order)
22+
{
23+
//
24+
$this->order= $order;
25+
}
26+
27+
/**
28+
* Get the notification's delivery channels.
29+
*
30+
* @param mixed $notifiable
31+
* @return array
32+
*/
33+
public function via($notifiable)
34+
{
35+
$notification_channel = 'database';
36+
$channel = explode(',' , $notification_channel);
37+
return $channel;
38+
}
39+
40+
/**
41+
* Get the mail representation of the notification.
42+
*
43+
* @param mixed $notifiable
44+
* @return \Illuminate\Notifications\Messages\MailMessage
45+
*/
46+
public function toMail($notifiable)
47+
{
48+
return (new MailMessage)
49+
->line('The introduction to the notification.')
50+
->action('Notification Action', url('/'))
51+
->line('Thank you for using our application!');
52+
}
53+
54+
public function toDatabase($notifiable)
55+
{
56+
return [
57+
'data' => 'Thare is new Order ('.$this->order->user->name.') With Number (#'.$this->order->id.')',
58+
'url' => URL('/'),
59+
];
60+
}
61+
/**
62+
* Get the array representation of the notification.
63+
*
64+
* @param mixed $notifiable
65+
* @return array
66+
*/
67+
public function toArray($notifiable)
68+
{
69+
return [
70+
//
71+
];
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('notifications', function (Blueprint $table) {
17+
$table->uuid('id')->primary();
18+
$table->string('type');
19+
$table->morphs('notifiable');
20+
$table->text('data');
21+
$table->timestamp('read_at')->nullable();
22+
$table->timestamps();
23+
});
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*
29+
* @return void
30+
*/
31+
public function down()
32+
{
33+
Schema::dropIfExists('notifications');
34+
}
35+
};
8.74 KB
Binary file not shown.
9.03 KB
Binary file not shown.

resources/views/pdf/invoice.blade.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
{{-- <img src="http://webivorous.com/wp-content/uploads/2020/06/brand-logo-webivorous.png"
3939
class="img-rounded logo"> --}}
4040
{{-- {!! QrCode::format('png')->size(150)->generate('Moahmmed Alqarra'); !!} --}}
41-
{{-- {!! QrCode::size(150)->generate('Moahmmed Alqarra'); !!} --}}
4241
<img src="data:image/png;base64, {{ base64_encode(QrCode::size(150)->generate('Moahmmed Alqarra')) }}" />
4342
<address>
4443
<strong>Webivorous Web services Pvt. Ltd.</strong><br>
@@ -88,8 +87,8 @@ class="img-rounded logo"> --}}
8887
<tr>
8988
<td>{{ $item->product->trans_name }}</td>
9089
<td>{{ $item->price }}</td>
91-
<td>{{ $item->quantity }}</td>
92-
<td>${{ $item->quantity * $item->price }}</td>
90+
<td>{{ $item->product->quantity }}</td>
91+
<td>${{ $item->product->quantity * $item->price }}</td>
9392
</tr>
9493
@endforeach
9594
<tr>

resources/views/read_notify.blade.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@extends('site.master')
2+
3+
@section('styles')
4+
<style>
5+
span form button{
6+
border: 0 ;
7+
background:transparent;
8+
}
9+
</style>
10+
@endsection
11+
12+
@section('content')
13+
<br>
14+
<br>
15+
<div class="container">
16+
17+
18+
<div class="list-group">
19+
@foreach (auth()->user()->notifications as $notification)
20+
<a href="{{ route('readd' , $notification->id ) }}" class="list-group-item {{ $notification->read_at ? 'active' : '' }}">
21+
{{ $notification->data['data'] }}
22+
23+
</a>
24+
@endforeach
25+
</div>
26+
27+
</div>
28+
@stop

resources/views/site/master.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
<!-- Main Stylesheet -->
4545
<link rel="stylesheet" href="{{ asset('siteassets/css/style.css') }}">
46-
@yield('style')
46+
@yield('styles')
4747
</head>
4848

4949
<body id="body">
@@ -223,7 +223,7 @@ class="tf-ion-android-cart"></i>Cart</a>
223223

224224
@yield('content')
225225

226-
<footer class="footer section text-center">
226+
<footer class="footer section text-center mb-0">
227227
<div class="container">
228228
<div class="row">
229229
<div class="col-md-12">

routes/test.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use App\Models\Order;
5+
use App\Notifications\NewOrder;
6+
use Illuminate\Support\Facades\Auth;
7+
use Illuminate\Support\Facades\Route;
8+
9+
// Route::get('test', function(){
10+
// return 'test';
11+
// });
12+
13+
14+
15+
Route::get('send-notify', function(){
16+
17+
$user = Auth::user();
18+
19+
$order = Order::find(1);
20+
21+
$user->notify(New NewOrder($order));
22+
});
23+
24+
25+
26+
27+
Route::get('read-notify', function(){
28+
29+
return view('read_notify');
30+
});
31+
32+
33+
Route::get('read-notify/{id}', function($id){
34+
35+
Auth::user()->notifications->find($id)->update(['read_at' => now()]);
36+
// Auth::user()->notifications->find($id)->markAsRead();
37+
return redirect(Auth::user()->notifications->find($id)->data['url']);
38+
})->name('readd');

routes/web.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
Route::get('/search', [SiteController::class, 'search'])->name('site.search');
7474
});
7575

76-
76+
include 'test.php';
7777
// This just for Test only
7878

7979
//Route::get('send-notification', function () {

0 commit comments

Comments
 (0)