Service String
The service string is used to send information from the front-end to the back-end about which functionality is needed to perform a certain action.
Format
The service string must be in a set format and supports up to three parts, but only one is required. Each segment is separated with a :.
Format: {type}:{id}:{endpoint}
Examples
projects:1:applicable: The applicable view for project with an ID of #1projects:assessment-day:1: The assessment day view for the assessment day with an ID #1employees: The employees overview
Service Manager
The service string can be interpreted by resolving it from the ServiceManager which is part of the core package.
Registering services
A service has to extend the OSMAviation\Core\Concerns\Service class and implement two methods: resolveQueryBuilder and resolveFilter.
Pulling a service
This example will return a instance of a Service interface, where you can resolve the query builder for the service if found, and
$service = resolve('servicemanager')->get('projects:1:applicable');
This will result in $service containing a Eloquent Builder instance. You can use this to perform further filters.
The below is the CREWMAN service.
use App\Services\Auth\Models\User;
use App\Services\CrewManagement\Models\Employee;
use App\Services\Projects\Filters\ApplicantFilter;
use OSMAviation\Core\Concerns\Service;
class Crewman extends Service
{
public $aliases = [
'employees'
];
public $idColumn = 'employees';
public function resolveFilter()
{
return ApplicantFilter::class;
}
public function resolveQueryBuilder()
{
$include = [];
if ($this->id) {
$include = explode(',', $this->id);
}
$query = Employee::include($include);
if ($this->user) {
$query = $query->accessibleByUser(User::find($this->user));
}
return $query;
return null;
}
}