Skip to content

Commit c4d1378

Browse files
committed
update
1 parent 96d7a11 commit c4d1378

File tree

3 files changed

+97
-9
lines changed

3 files changed

+97
-9
lines changed

app/Http/Controllers/Product/PublishedProductController.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,36 @@
55
use App\Models\Product;
66
use App\Models\FeedBack;
77
use Illuminate\Http\Request;
8+
use App\Jobs\SendDeclineProductJob;
89
use App\Http\Controllers\Controller;
10+
use App\Jobs\SendVerificationSellerJob;
911

1012
class PublishedProductController extends Controller
1113
{
1214
public function publishedProduct($id,Request $request)
1315
{
1416
$product = Product::find($id);
15-
if($product->status == 0){
16-
$product->status = 1;
17-
$product->isRejet=0;
18-
$product->save();
19-
return response()->json(['message' => 'Product published successfully']);
20-
}else{
21-
if($request->message){
22-
$feedBack=new FeedBack;
17+
if($request->message && $request->user_id){
18+
19+
$feedBack=new FeedBack;
2320
$feedBack->user_id=$request->user_id;
2421
$feedBack->message=$request->message;
2522
$feedBack->status=0;
2623
$feedBack->type="1";
2724
$feedBack->product_id=$product->id;
2825
$product->isRejet=1;
2926
$feedBack->save();
30-
}
27+
SendDeclineProductJob::dispatch($product,$request->message);
28+
3129
$product->status = 0;
3230
$product->save();
3331
return response()->json(['message' => 'Product unpublished successfully']);
32+
}else{
33+
$product->status = 1;
34+
$product->isRejet=0;
35+
$product->save();
36+
return response()->json(['message' => 'Product published successfully']);
3437
}
38+
3539
}
3640
}

app/Jobs/SendDeclineProductJob.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace App\Jobs;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Queue\SerializesModels;
7+
use Illuminate\Queue\InteractsWithQueue;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
9+
use Illuminate\Foundation\Bus\Dispatchable;
10+
use App\Notifications\NewMessageFromVerificationProductNotification;
11+
12+
class SendDeclineProductJob implements ShouldQueue
13+
{
14+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
15+
16+
/**
17+
* Create a new job instance.
18+
*/
19+
protected $product;
20+
protected $message;
21+
public function __construct($product,$message)
22+
{
23+
$this->product=$product;
24+
$this->message=$message;
25+
}
26+
27+
/**
28+
* Execute the job.
29+
*/
30+
public function handle(): void
31+
{
32+
$shop=$this->product->shop;
33+
$seller=$shop->user;
34+
$seller->notify(new NewMessageFromVerificationProductNotification($this->message,$this->product));
35+
}
36+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace App\Notifications;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Notifications\Messages\MailMessage;
8+
use Illuminate\Notifications\Notification;
9+
10+
class NewMessageFromVerificationProductNotification extends Notification
11+
{
12+
use Queueable;
13+
14+
/**
15+
* Create a new notification instance.
16+
*/
17+
18+
protected $message;
19+
protected $product;
20+
public function __construct($message,$product)
21+
{
22+
$this->message=$message;
23+
$this->product=$product;
24+
}
25+
26+
/**
27+
* Get the notification's delivery channels.
28+
*
29+
* @return array<int, string>
30+
*/
31+
public function via(object $notifiable): array
32+
{
33+
return ['database'];
34+
}
35+
36+
/**
37+
* Get the mail representation of the notification.
38+
*/
39+
public function toDatabase($notifiable)
40+
{
41+
return [
42+
"product_id" => $this->product->id,
43+
'feedback' => $this->message,
44+
'message' => 'Vous aviez recu un nouveau message suite à la verification de votre produit',
45+
];
46+
}
47+
48+
}

0 commit comments

Comments
 (0)