PHP code example of muhammadn / laravel-zammad

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

    

muhammadn / laravel-zammad example snippets


    'providers' => [
        .... all the other providers ....
        Muhammadn\LaravelZammad\ZammadServiceProvider::class,
    ],

    'aliases' => [
        ... all the other facades ...
        'LaravelZammad' => Muhammadn\LaravelZammad\ZammadFacade::class,
    ]

use LaravelZammad;

class MyController extends Controller
{

  public function index(LaravelZammad $zammad)
  {
      // get all tickets
      $data = $zammad::all('ticket');
      // get all tickets with pagination
      // example below for page 4, 50 entries at a time.
      $data = $zammad::all('ticket', 4, 50);

      // get ticket of specific id
      $data = $zammad::find('ticket', 34);

      // To view the data (all values)
      $data->getValues();

      // Get single value 
      $data->getValue('title');

      // get articles from ticket
      $ticket = $zammad::find('ticket', 34);
      $articles = $ticket->getTicketArticles();
      // get first article content
      $article_content = $articles[0]->getValues();

      // Search the data
      $data = $zammad::search('ticket', 'text that you want to search')
      // get search results with pagination
      // example below for page 4, 50 entries at a time.
      $data = $zammad::search('ticket', 'text you want to search', 4, 50);

      // Add new ticket
      $ticket_values = ['title' => 'Test Ticket', 'owner_id' => 1]
      $data = $zammad::create('ticket', $ticket_values)

      // Update a ticket
      $ticket_values = ['title' => 'Test Ticket', 'owner_id' => 1]
      $data = $zammad::update('ticket', $ticket_id, $ticket_values)

      // Delete a ticket
      $data = $zammad::delete('ticket', $ticket_id)
    }
}

use LaravelZammad;

class MyController extends Controller
{

  public function index(LaravelZammad $zammad)
  {
      // get all users
      $data = $zammad::all('user');
      // get all users with pagination
      // example below for page 4, 50 entries at a time.
      $data = $zammad::all('user', 4, 50);

      // get user of specific id
      $data = $zammad::find('user', 34);

      // To view the data (all values)
      $data->getValues();

      // Get single value
      $data->getValue('title');

      // Search the data
      $data = $zammad::search('user', 'text that you want to search')
      // get search results with pagination
      // example below for page 4, 50 entries at a time.
      $data = $zammad::search('user', 'text you want to search', 4, 50);

      // Add new User
      $user_values = ['email' => '[email protected]', 'owner_id' => 1]
      $data = $zammad::create('user', $user_values)

      // Update a user
      $user_values = ['email' => '[email protected]', 'owner_id' => 1]
      $data = $zammad::update('user', $user_id, $user_values)

      // Delete a user
      $data = $zammad::delete('user', $user_id)
    }
}

use LaravelZammad;

class MyController extends Controller
{

  public function index(LaravelZammad $zammad)
  {
      // get all groups
      $data = $zammad::all('group');
      // get all groups with pagination
      // example below for page 4, 50 entries at a time.
      $data = $zammad::all('group', 4, 50);

      // get group of specific id
      $data = $zammad::find('group', 34);

      // To view the data (all values)
      $data->getValues();

      // Get single value
      $data->getValue('title');

      // Add new Group
      $group_values = ['name' => 'ZammadGroup']
      $data = $zammad::create('group', $group_values)

      // Update a group
      $group_values = ['name' => 'ZammadGroup2']
      $data = $zammad::update('group', $group_id, $group_values)

      // Delete a group
      $data = $zammad::delete('group', $group_id)
    }
}

use LaravelZammad;

class MyController extends Controller
{

  public function index(LaravelZammad $zammad)
  {
      // get all ticket states
      $data = $zammad::all('ticket_state');
      // get all ticket states with pagination
      // example below for page 4, 50 entries at a time.
      $data = $zammad::all('ticket_state', 4, 50);

      // get ticket state of specific id
      $data = $zammad::find('ticket_state', 34);

      // To view the data (all values)
      $data->getValues();

      // Get single value
      $data->getValue('title');

      // Add new ticket state
      $state_values = ['name' => 'delayed', 'active' => true]
      $data = $zammad::create('ticket_state', $state_values)

      // Update a ticket state
      $state_values = ['name' => 'boarding', 'active' => true]
      $data = $zammad::update('ticket_state;, $state_id, $state_values)

      // Delete a ticket state
      $data = $zammad::delete('ticket_state', $state_id)
    }
}

use LaravelZammad;

class MyController extends Controller
{

  public function index(LaravelZammad $zammad)
  {
      // get all ticket priorities
      $data = $zammad::all('ticket_priority');
      // get all ticket states with pagination
      // example below for page 4, 50 entries at a time.
      $data = $zammad::all('ticket_prioriry', 4, 50);

      // get ticket priority of specific id
      $data = $zammad::find('ticket_priority', 34);

      // To view the data (all values)
      $data->getValues();

      // Get single value
      $data->getValue('title');

      // Add new ticket priority
      $priority_values = ['name' => '4 urgent', 'active' => true]
      $data = $zammad::create('ticket_priority', $priority_values)

      // Update a ticket priority
      $priority_values = ['name' => '5 very very urgent', 'active' => true]
      $data = $zammad::update('ticket_priority', $priority_id, $priority_values)

      // Delete a ticket state
      $data = $zammad::delete('ticket_priority', $priority_id)
    }
}

  public function index(LaravelZammad $zammad)
  {
      // get ticket article of specific id
      $data = $zammad::find('ticket_article', 34);

      // To view the data (all values)
      $data->getValues();

      // Get single value
      $data->getValue('title');

      // Add ticket article
      $ticket_article_values = ['ticket_id' => 1, 'type_id' => 5, 'sender_id' => 2]
      $data = $zammad::create('ticket_article', $ticket_article_values)

      // Update a ticket article
      $ticket_article_values = ['ticket_id' => 2, 'type_id' => 3, 'sender_id' => 7]
      $data = $zammad::update('ticket_article', $ticket_article_id, $ticket_article_values)

      // Delete a ticket article
      $data = $zammad::delete('ticket_article', $ticket_article_id)


use LaravelZammad;

class MyController extends Controller
{

  public function index(LaravelZammad $zammad)
  {
      // get all organizations
      $data = $zammad::all('organization');
      // get all organizations with pagination
      // example below for page 4, 50 entries at a time.
      $data = $zammad::all('organization', 4, 50);

      // get organization of specific id
      $data = $zammad::find('organization', 34);

      // To view the data (all values)
      $data->getValues();

      // Get single value
      $data->getValue('title');

      // Search the data
      $data = $zammad::search('organization', 'text that you want to search')
      // get search results with pagination
      // example below for page 4, 50 entries at a time.
      $data = $zammad::search('organization', 'text you want to search', 4, 50);

      // Add organization
      $organization_values = ['name' => 'Zammad', 'active' => true]
      $data = $zammad::create('organization', $organization_values)

      // Update an organization
      $organization_values = ['name' => 'Zammad', 'active' => true]
      $data = $zammad::update('organization', $organization_id, $organization_values)

      // Delete an organization
      $data = $zammad::delete('organization', $organization_id)
    }
}