| Server IP : 139.59.63.204 / Your IP : 216.73.217.62 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ubuntu-s-1vcpu-1gb-blr1-01 6.8.0-110-generic #110-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 15:09:20 UTC 2026 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/billing/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use App\Models\Ticket;
use App\Http\Controllers\Traits\MediaUploadingTrait;
use App\Notifications\CommentEmailNotification;
use Illuminate\Support\Facades\Notification;
use Illuminate\Http\Request;
use DataTables;
class TicketController extends Controller
{
use MediaUploadingTrait;
public function index(Request $request)
{
if ($request->ajax()) {
$tickets = Ticket::where('author_email',auth()->user()->email);//->orderBy('created_at','desc');
return DataTables::of($tickets)
->addIndexColumn()
->addColumn('date', function($ticket){
return $ticket->created_at->format('M d Y');
})
->addColumn('status', function($ticket){
return $ticket->status->name;
})
->addColumn('action', function($ticket){
$btn = '<a href="'.route('tickets.show',$ticket->id).'" ><i class="fas fa-eye text-success fs-2"></i></a>';
return $btn;
})
->rawColumns(['action'])
->make(true);
}
return view('tickets.index');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('tickets.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'title' => 'required',
'content' => 'required',
// 'author_name' => 'required',
// 'author_email' => 'required|email',
]);
$request->request->add([
'author_name' => auth()->user()->name,
'author_email' => auth()->user()->email,
'category_id' => 1,
'status_id' => 1,
'priority_id' => 1
]);
$ticket = Ticket::create($request->all());
foreach ($request->input('attachments', []) as $file) {
$ticket->addMedia(storage_path('tmp/uploads/' . $file))->toMediaCollection('attachments');
}
return redirect()->back()->with('success','Your ticket has been submitted, we will be in touch. You can view ticket status <a href="'.route('tickets.show', $ticket->id).'">here</a>');
}
/**
* Display the specified resource.
*
* @param \App\Ticket $ticket
* @return \Illuminate\Http\Response
*/
public function show(Ticket $ticket)
{
$ticket->load('comments');
return view('tickets.show', compact('ticket'));
}
public function storeComment(Request $request, Ticket $ticket)
{
$request->validate([
'comment_text' => 'required'
]);
$comment = $ticket->comments()->create([
'author_name' => $ticket->author_name,
'author_email' => $ticket->author_email,
'comment_text' => $request->comment_text
]);
$ticket->sendCommentNotification($comment);
return redirect()->back()->withStatus('Your comment added successfully');
}
}