PHP code example of spinen / halo-php-client
1. Go to this page and download the library: Download spinen/halo-php-client 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/ */
spinen / halo-php-client example snippets
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spinen\Halo\Concerns\HasHalo;
class User extends Authenticatable
{
use HasHalo, Notifiable;
// ...
}
php artisan tinker
Psy Shell v0.11.14 (PHP 8.2.4 — cli) by Justin Hileman
> $user = App\Models\User::find(1)
= App\Models\User {#4344
id: 1,
name: "Jimmy",
email: "[email protected] ",
email_verified_at: null,
...
> $user->halo;
= Spinen\Halo\Api\Client {#4748}
> $user->halo();
= Spinen\Halo\Support\Builder {#4706}
> $user->halo()->teams->first()
= Spinen\Halo\Team {#4967
+exists: true,
+incrementing: false,
+parentModel: null,
+wasRecentlyCreated: false,
+timestamps: false,
}
> $user->halo()->teams->first()->toArray()
= [
"id" => 1,
"guid" => "<masked>",
"name" => "1st Line Support",
"sequence" => 10,
"forrequests" => true,
"foropps" => false,
"forprojects" => false,
"ticket_count" => 0,
"department_id" => 3,
"department_name" => "SPINEN - Support",
"inactive" => false,
"override_column_id" => 0,
"teamphotopath" => "",
"use" => "team",
]
> $user->halo()->clients->count()
= 9
// Only clients with a "y" in the name
> $user->halo()->clients()->search('y')->get()->pluck('name')
// Same as: $user->halo()->clients()->where('search', 'y')->get()->pluck('name')
= Spinen\Halo\Support\Collection {#5136
all: [
"Terry's Chocolates",
"Tony's Tyre Emporium",
],
}
> $builder->tickets()->take(7)->get()
= Spinen\Halo\Support\Collection {#4999
all: [
Spinen\Halo\Ticket {#4991
+exists: true,
+incrementing: false,
+parentModel: null,
+wasRecentlyCreated: false,
+timestamps: false,
},
// more...
],
}
> $tickets->count()
= 7
// Running through map to convert date to string
> $builder->tickets()->take(5)->oldest()->get()->pluck('dateoccurred', 'id')->map(fn($d) => (string)$d)
= Spinen\Halo\Support\Collection {#4983
all: [
1125 => "2019-12-14 13:30:00",
1128 => "2019-12-14 13:30:00",
1131 => "2019-12-14 13:30:00",
1134 => "2019-12-14 13:30:00",
1137 => "2019-12-14 13:30:00",
],
}
> $builder->tickets()->take(5)->latest()->get()->pluck('dateoccurred', 'id')->map(fn($d) => (string)$d)
= Spinen\Halo\Support\Collection {#4763
all: [
2205 => "2021-03-24 11:35:40",
2206 => "2021-03-24 10:23:47",
2200 => "2021-03-23 16:44:00",
2186 => "2021-03-23 14:17:57",
2187 => "2021-03-23 14:17:57",
],
}
// Could have been $builder->users()->paginate(2)->page(2)->get()
> $builder->users()->page(3, 2)->get()
= Spinen\Halo\Support\Collection {#4761
all: [
Spinen\Halo\User {#4763
+exists: true,
+incrementing: false,
+parentModel: null,
+wasRecentlyCreated: false,
+timestamps: false,
},
// more...
],
}
> $users->count()
= 2
> $user->halo()->quotes->count()
= 4
$user->halo()->statuses->pluck('name', 'id')->sort()
= Spinen\Halo\Support\Collection {#4959
all: [
3 => "Action Required",
18 => "Approved",
17 => "Awaiting Approval",
9 => "Closed",
15 => "Closed Item",
13 => "Closed Order",
20 => "Completed",
2 => "In Progress",
16 => "Invoiced",
1 => "New",
21 => "On Hold",
14 => "Open Item",
12 => "Open Order",
19 => "Rejected",
22 => "Updated",
10 => "With CAB",
5 => "With Supplier",
4 => "With User",
],
}
bash
$ composer
halo.php
bash
php artisan vendor:publish --tag=halo-config
bash
php artisan vendor:publish --tag=halo-migrations
bash
php artisan tinker
Psy Shell v0.11.14 (PHP 8.2.4 — cli) by Justin Hileman
> $halo = app(Spinen\Halo\Api\Client::class);
= Spinen\Halo\Api\Client {#4013}
> $halo->get('tenant')
= [
"id" => 0,
"key" => "some_key",
"hostname" => "some.host.tld",
"api_root" => "https://some.host.tld/api",
"alias" => "",
"linked_instance_id" => 0,
"has_linked_instances" => false,
"isportal" => false,
]