mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
feat: update plugin data via webhook
This commit is contained in:
parent
e13f9708fd
commit
b8a0aa47bf
3 changed files with 135 additions and 29 deletions
|
|
@ -194,3 +194,24 @@ Route::post('/display/update', function (Request $request) {
|
|||
})
|
||||
->name('display.update')
|
||||
->middleware('auth:sanctum', 'ability:update-screen');
|
||||
|
||||
Route::post('custom_plugins/{plugin_uuid}', function (string $plugin_uuid) {
|
||||
$plugin = \App\Models\Plugin::where('uuid', $plugin_uuid)->firstOrFail();
|
||||
|
||||
// Check if plugin uses webhook strategy
|
||||
if ($plugin->data_strategy !== 'webhook') {
|
||||
return response()->json(['error' => 'Plugin does not use webhook strategy'], 400);
|
||||
}
|
||||
|
||||
$request = request();
|
||||
if (! $request->has('merge_variables')) {
|
||||
return response()->json(['error' => 'Request must contain merge_variables key'], 400);
|
||||
}
|
||||
|
||||
$plugin->update([
|
||||
'data_payload' => $request->input('merge_variables'),
|
||||
'data_payload_updated_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['message' => 'Data updated successfully']);
|
||||
})->name('api.custom_plugins.webhook');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue