PHP code example of lumina / tickets

1. Go to this page and download the library: Download lumina/tickets 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/ */

    

lumina / tickets example snippets


...
use Lumina\Tickets\Concerns\HasTickets;
use Lumina\Tickets\Contracts\CanUseTickets;
...
class User extends Model implements CanUseTickets
{
    ...
    use HasTickets;
    ...
}

use Lumina\Tickets\Models\Ticket;
use Lumina\Tickets\Models\Category;

...
public function store(Request $request)
{
    /** @var User */
    $user = Auth::user();

    $ticket = $user->tickets()
                    ->create($request->validated());

    $category = Category::first();
    $ticket->attachCategories($category);
    
    // or you can create the categories & the tickets directly by:
    // $ticket->categories()->create(...);

    return redirect(route('tickets.show', $ticket->uuid))
            ->with('success', __('Your Ticket Was created successfully.'));
}

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);
}
...

namespace App\Models\Ticket;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

class Ticket extends \Lumina\Tickets\Models\Ticket implements HasMedia
{
    use InteractsWithMedia;
}
bash
php artisan vendor:publish --tag="ticket-migrations"
bash
php artisan migrate

php artisan make:model Ticket