1. Go to this page and download the library: Download renatoxm/laravel-ticket library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
renatoxm / laravel-ticket example snippets
...
use Renatoxm\LaravelTicket\Concerns\HasTickets;
use Renatoxm\LaravelTicket\Contracts\CanUseTickets;
...
class User extends Model implements CanUseTickets
{
...
use HasTickets;
...
}
use Renatoxm\LaravelTicket\Models\Ticket;
use Renatoxm\LaravelTicket\Models\Category;
use Renatoxm\LaravelTicket\Models\Label;
...
public function store(Request $request)
{
/** @var User */
$user = Auth::user();
$ticket = $user->tickets()
->create($request->validated());
$category = Category::first();
$label = Label::first();
$ticket->attachCategories($category);
$ticket->attachLabels($label);
// or you can create the categories & the tickets directly by:
// $ticket->categories()->create(...);
// $ticket->labels()->create(...);
return redirect(route('tickets.show', $ticket->uuid))
->with('success', __('Your Ticket Was created successfully.'));
}
public function createLabel()
{
// If you create a label seperated from the ticket and wants to
// associate it to a ticket, you may do the following.
$label = Label::create(...);
$label->tickets()->attach($ticket);
// or maybe
$label->tickets()->detach($ticket);
}
public function createCategory()
{
// If you create a category/categories seperated from the ticket and wants to
// associate it to a ticket, you may do the following.
$category = Category::create(...);
$category->tickets()->attach($ticket);
// or maybe
$category->tickets()->detach($ticket);
}
...
$ticket->archive()
->close()
->markAsResolved();
namespace App\Models\Ticket;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class Ticket extends \Renatoxm\LaravelTicket\Models\Ticket implements HasMedia
{
use InteractsWithMedia;
}
use Renatoxm\LaravelTicket\Events\TicketCreated;
Event::listen(function (TicketCreated $event) {
dump($event->ticket->title);
});
// or
Event::listen(TicketCreated::class, [SomeListener::class, 'handle']);