%PDF- %PDF-
Direktori : /home/silvzytp/crm-ind-code/app/Http/Controllers/ |
Current File : /home/silvzytp/crm-ind-code/app/Http/Controllers/CommentController.php |
<?php namespace App\Http\Controllers; use App\Models\Comment; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Auth; class CommentController extends Controller { public function commentStore(Request $request){ DB::beginTransaction(); try { DB::table('comments')->insert([ 'lead_id' => $request->calling_id, 'user_id' => Auth::id(), 'comment' => $request->comment, 'comment_date' => date('Y-m-d H:i:s'), ]); DB::commit(); $output = ['status'=>'success','message'=>'saved']; } catch (\Exception $e) { DB::rollBack(); $output = ['status'=>'error','message'=>'Somthing Wrong!']; } return response()->json($output); } public function commentGet(Request $request){ if ($request->ajax()) { $comments = Comment::with('user') ->where('lead_id',$request->calling_id)->get(); $output = ''; foreach ($comments as $comment) { $avatar = $comment->user->avatar != '' ? asset($comment->user->avatar) : 'https://placehold.co/40x40'; $output .= ' <div class="comment-item d-flex mb-2"> <div class="comment-avatar mr-2"> <img src="'.$avatar.'" width="40px" height="40px" class="rounded-circle" alt=""> </div> <div class="comment-box w-100"> <strong class="text-12 d-block">'.$comment->user->name.'</strong> <div class="content-box border p-2 mt-1"> '.$comment->comment.' </div> <small class="d-block text-secondary">'.date_formats($comment->comment_date,'Y-m-d h:i:s a').'</small> </div> </div> '; } return response()->json($output); } } }