MFR ApiService & Clients
Drei Bausteine, je nach Use-Case:
| Klasse | Zweck | Auth |
|---|---|---|
App\Http\Clients\GuzzleClient | direkter REST-Call (POST/PUT/DELETE) | Basic Auth |
App\Http\Clients\ODataClient | OData-Queries (from, expand, where) | Basic Auth |
App\Services\MfrApiService | Orchestrator (kapselt beide) | — |
GuzzleClient — Direct REST
Wird in jedem Mfr/<Entity>Controller instantiiert:
public function __construct() {
$this->guzzle = new GuzzleClient('mfr');
}
// Verwendung
$body = json_encode($request->all(), true);
$mfrResponse = $this->guzzle->post('Companies', $body);
$mfrResponse = $this->guzzle->put(
'Companies(' . $company->Id . 'L)',
$company->makeHidden(['created_at','updated_at'])->toJson()
);
$this->guzzle->delete('Companies(' . $company->Id . 'L)');
Achtung: MFR (OData) erwartet IDs in der URL als
(123L)— nicht(123). DasLmarkiert in OData ein 64-bit-Integer-Literal.
Vollständige Methoden-Liste in Common HTTP-Clients.
ODataClient — Query-Builder
Für Reads / komplexe Filter:
use App\Http\Clients\ODataClient;
$mfr = (new ODataClient())->mfr;
// Liste mit Expand
$companies = $mfr->from('Companies')
->skip(0)
->order('ExternalId')
->expand('Contacts,Tags,ServiceObjects,MainContact')
->get();
// Single-Record by Id
$company = $mfr->from('Companies(61149446314L)')
->expand(\App\Http\Helpers\Mfr\Helper::getExpand('Companies'))
->get()
->first();
// Filter
$active = $mfr->from('ServiceObjects')
->where('Active', true)
->get();
Standard-Expand-Strings
Pro Entity gibt's einen vorkonfigurierten Expand in Mfr\Helper::getExpand():
| Entity | Expand |
|---|---|
Companies | Contacts,Tags,ServiceObjects,MainContact |
Contacts | Company,User |
Documents | ServiceRequest |
ItemTypes | Unit |
Products | CustomValueStepTemplate/Steps |
ServiceObjects | Contacts,Company,Product,Tags |
ServiceRequests | Qualifications,ServiceObjects,Customer,Reports,Items,Appointments/Contacts,Steps,Comments,StockMovements,Tags |
StepListTemplates | Steps |
TimeEvents | Contact,ServiceRequest |
Users | Contact |
$expand = \App\Http\Helpers\Mfr\Helper::getExpand('Companies');
$companies = $mfr->from('Companies')->expand($expand)->get();
MfrApiService
App\Services\MfrApiService
Höhere Orchestrator-Klasse, die Helper, ODataClient und GuzzleClient zusammenpackt — aktuell sehr schlank, gedacht als Erweiterungspunkt.
namespace App\Services;
class MfrApiService
{
public function __construct(
?Mfr\Helper $mfrHelper = null,
?ODataClient $oDataClient = null,
?GuzzleClient $guzzleClient = null,
) {
$this->mfrHelper = $mfrHelper ?? new Helper();
$this->oDataClient = $oDataClient ?? new ODataClient();
$this->guzzleClient = $guzzleClient ?? new GuzzleClient();
}
public function run(string $entity, int $skip = 0, string $expand = ''): void
{
// domänen-spezifische Sync-Logik hier
}
}
Wenn du eine neue, mehrstufige MFR-Sync-Operation kapseln willst, ist das der Ort dafür. Nicht für simple CRUD — das gehört in den jeweiligen Resource-Controller.
Authentication
Beide Clients nutzen Basic-Auth über config('services.mfr.{username,password,base_url}'):
'Authorization' => 'Basic ' . base64_encode($username . ':' . $password),
'Accept' => 'application/json',
'Content-Type' => 'application/json',
Setze in .env:
MFR_BASE_URL="https://portal.mobilefieldreport.com/odata/"
MFR_API_USERNAME="..."
MFR_API_PASSWORD="..."