Skip to content

Laravel integrations

Xavi edited this page Apr 22, 2019 · 4 revisions

The following are detailed procedures to do some integrations of PanicHD in your Laravel App. Beyond them, remember that you can replace easily any of the publishable files (views, translations and assets) that come with this package with your custom versions. You would just have to read Laravel official docs for that.

In this document:

Create tickets from your Laravel app

In any Laravel file from which you want to create PanicHD tickets, you have only to add the following code lines:

// After the namespace of the file
use PanicHD\PanicHD\Models\Ticket;

// Whenever you need it
$ticket = new Ticket;
$ticket->subject = "Your ticket subject";
$ticket->save();

As you can see, it's the same way as working with any other Model in a Laravel App. To have a piece of working code, you will have also to:

  • Define the values for all the other fields that belong to any ticket
  • Add your custom validation logic.

If you also want to use PanicHD email notifications logic, you need these additional lines:

// After the namespace of the file
use PanicHD\PanicHD\Events\TicketCreated;

// After saving the ticket
event(new TicketCreated($ticket));

Custom Member model

Following these steps, you will be able to:

  • Use the table you want for PanicHD members
  • Change the PanicHD's Member model behavior

Configuration steps

  1. Create a new model file for PanicHD's Member. The recommended would be to have it under a new folder "PanicHD" in the "App" folder in your Laravel app, with the file name "Member.php" for a easier future location.
  2. Make it extend PanicHD default Member model. If you don't know how to do that, you can copy our file example. Remember to change it's namespace if you're going to put it in a different folder.
  3. If you wanna set a different table than "users" for it, set it in the $table variable and uncomment it's line
  4. Access PanicHD configuration > initial and edit the setting "member_model_class"
  5. Type the namespace + file name without ".php" of your custom Member model. Using our example it would be "App\PanicHD\Member"

Example of a custom Member model file

File path: App\PanicHD\Member.php

<?php
    namespace App\PanicHD;
    
    use PanicHD\PanicHD\Models\Member as PanicHDMember;
    
    class Member extends PanicHDMember
    {
        // protected $table = "panichd_members";
    }
?>

Load list with specified filters

You may open a ticket list setting several filters at the same time by url. For that, you can use the /filterjust URL, like in the following examples:

  • localhost/tickets/filterjust/agent/1 : Default list filtered with agent_id == 1
  • localhost/tickets/filterjust/owner/3/list/newest : Newest list wih owner_id == 3

It does three actions:

  1. Removes any previous filter
  2. Applies all the filters set by URL
  3. Opens the specified ticket list or, if not specified, the active tickets list

Available filters with valid values:

  • agent/member_id
  • calendar/['expired', 'today', 'tomorrow', 'week', 'month', 'within-7-days', 'within-14-days', 'not-scheduled']
  • category/category_id
  • list/['newest', 'active', 'complete']
  • owner/member_id
  • year/4_digit_number

You may specify one or many of these filters at the same time. It doesn't care in which order you put them.

Use any PanicHD Configuration setting in any Laravel File

You can use any of the package configuration settings (the default ones or your custom's at top navigation > PanicHD > Configuration) in the package within any Laravel file using the PanicHD Setting model as the following example:

// After the namespace of the file
use PanicHD\PanicHD\Models\Setting;

// In that file
Setting::grab('desired_setting_slug');

The slug is the setting name, where spaces are replaced with underscores.

In any of the PanicHD views, you can also use the included instance $setting which allows you to directly load any setting like in this example:

{{ $setting->grab('admin_route') }}