diff --git a/app/Http/Controllers/Admin/HelpTicketCrudController.php b/app/Http/Controllers/Admin/HelpTicketCrudController.php index c2f6e17f..a5d6bc06 100644 --- a/app/Http/Controllers/Admin/HelpTicketCrudController.php +++ b/app/Http/Controllers/Admin/HelpTicketCrudController.php @@ -112,6 +112,8 @@ class HelpTicketCrudController extends CrudController 'user_id' => auth()->id() ]); + $ticket->update('status','waiting_replay'); + Notification::route('mail', $ticket->email) ->notify(new TicketCommented($comment)); diff --git a/app/Http/Controllers/HelpDeskController.php b/app/Http/Controllers/HelpDeskController.php index 286fc175..8bff7a7c 100644 --- a/app/Http/Controllers/HelpDeskController.php +++ b/app/Http/Controllers/HelpDeskController.php @@ -8,8 +8,8 @@ use App\Http\Requests\HelpTicketCommentRequest; use App\Http\Requests\HelpTicketRequest; use App\Models\HelpTicket; use App\Models\HelpTicketComment; -use App\Models\HelpTopic; use App\Models\User; +use App\Notifications\TicketCommented; use App\Notifications\TicketReceived; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Notification; @@ -56,12 +56,7 @@ class HelpDeskController extends Controller */ $ticket->notify(new TicketReceived($ticket)); - /** - * Notify administrators that ticket is arrived; - */ - $administrators = User::where('is_admin',1)->get(['id','email']); - - Notification::send($administrators, new TicketReceived($ticket)); + $this->notifyAdministrators(new TicketReceived($ticket)) ; return redirect()->route('help.show',['code' => $ticket->code]); } @@ -73,9 +68,19 @@ class HelpDeskController extends Controller } + /** + * Notify administrators that ticket is arrived; + */ + private function notifyAdministrators(\Illuminate\Notifications\Notification $notification){ + + $administrators = User::where('is_admin',1)->get(['id','email']); + + Notification::send($administrators, $notification); + } + public function comment(HelpTicketCommentRequest $request,$code){ - $ticket = HelpTicket::select('id') + $ticket = HelpTicket::select('id','name','email') ->where('code',$code) ->first(); @@ -84,16 +89,14 @@ class HelpDeskController extends Controller $comment = HelpTicketComment::create([ 'text' => $request->text, - 'help_ticket_id' => $ticket->id + 'help_ticket_id' => $ticket->id, + 'attachment' => $request->file('attachment'), + 'name' => $ticket->owner, ]); $ticket->update(['status' => 'pending']) ; - if($request->has('attachment')){ - - } - - //todo notify, attachment + $this->notifyAdministrators(new TicketCommented($comment)); return redirect()->route('help.show',['code' => $code]); diff --git a/app/Models/HelpTicketComment.php b/app/Models/HelpTicketComment.php index 20240666..890f6fb5 100644 --- a/app/Models/HelpTicketComment.php +++ b/app/Models/HelpTicketComment.php @@ -64,34 +64,17 @@ class HelpTicketComment extends Model |-------------------------------------------------------------------------- */ //todo use trait for image upload - public function setAttachmentAttribute($value){ + public function setAttachmentAttribute($file){ $attribute_name = "attachment"; $disk = config('filesystems.default'); // or use your own disk, defined in config/filesystems.php $destination_path = "help"; // path relative to the disk above - // if the image was erased - if ($value==null) { - // delete the image from disk - \Storage::disk($disk)->delete($this->{$attribute_name}); + if($file){ + $filename = md5($file.time()) . '.' . strtolower($file->getClientOriginalExtension()); + // 2. Move the new file to the correct path + $file_path = $file->storeAs($destination_path, $filename, $disk); - // set null in the database column - $this->attributes[$attribute_name] = null; - } - - // if a base64 was sent, store it in the db - if (starts_with($value, 'data:image')) - { - // 0. Make the image - $image = \Image::make($value)->encode('jpg', 90); - // 1. Generate a filename. - $filename = md5($value.time()).'.jpg'; - // 2. Store the image on disk. - \Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream()); - // 3. Save the public path to the database - // but first, remove "public/" from the path, since we're pointing to it from the root folder - // that way, what gets saved in the database is the user-accesible URL - $public_destination_path = Str::replaceFirst('public/', '', $destination_path); - $this->attributes[$attribute_name] = $public_destination_path.'/'.$filename; + $this->attributes[$attribute_name] = $file_path; } } @@ -106,11 +89,6 @@ class HelpTicketComment extends Model $disk = config('filesystems.default'); \Storage::disk($disk)->delete($obj->seats_image); - if (count((array)$obj->images)) { - foreach ($obj->images as $file_path) { - \Storage::disk('uploads')->delete($file_path); - } - } }); } } diff --git a/app/Notifications/TicketCommented.php b/app/Notifications/TicketCommented.php index 2384bf55..8ccdc909 100644 --- a/app/Notifications/TicketCommented.php +++ b/app/Notifications/TicketCommented.php @@ -33,7 +33,7 @@ class TicketCommented extends Notification implements ShouldQueue */ public function via($notifiable) { - return ['mail']; + return ['mail','database']; } /** @@ -56,10 +56,8 @@ class TicketCommented extends Notification implements ShouldQueue * @param mixed $notifiable * @return array */ - public function toArray($notifiable) + public function toDatabase($notifiable) { - return [ - // - ]; + return $this->comment->toArray(); } }