1. Go to this page and download the library: Download dniccum/nova-webhooks 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/ */
dniccum / nova-webhooks example snippets
use Dniccum\NovaWebhooks\Nova\UsesWebhookResource;
...
class NovaServiceProvider extends NovaApplicationServiceProvider
{
// Add the following trait to your service provider
use UsesWebhookResource;
}
use Dniccum\NovaWebhooks\NovaWebhooks;
...
/**
* Get the tools that should be listed in the Nova sidebar.
*
* @return array
*/
public function tools()
{
return [
// other tools
new NovaWebhooks,
];
}
return [
/**
* Whether webhooks should be sent
*/
'enabled' => env('NOVA_WEBHOOKS_ENABLED', true),
/**
* If logging should be enabled for each successful/failed request
*/
'logging' => [
'enabled' => env('NOVA_WEBHOOKS_LOGGING_ENABLED', true),
],
/**
* Enter the desired formatting for timestamps that are attached to logging.
* See the official PHP documentation for more information: https://www.php.net/manual/en/datetime.format.php
*/
'date_format' => 'Y-m-d @ G:i',
/**
* The Laravel Nova resource that manages your authenticated users.
*/
'users' => [
'resource' => App\Nova\User::class
]
];
protected static function createdWebhookPayload($model)
{
return [
'id' => $model->id,
'name' => $model->first_name.' '.$model->last_name,
'email' => $model->email,
// And so on
];
}
class PageLikeResource extends \Illuminate\Http\Resources\Json\JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->first_name.' '.$this->last_name,
'email' => $this->email,
];
}
}
protected static function createdWebhookPayload($model)
{
return new PageLikeResource($model);
}
/**
* The name of the model that will be applied to the webhook
*
* @return string
*/
public static function webhookLabel() : string
{
return 'App Users';
}
use Dniccum\NovaWebhooks\Jobs\DispatchWebhook;
class PageLike extends \Illuminate\Database\Eloquent\Model
{
use ShouldQueueWebhook
...
}
/**
* The job class that should be used to dispatch this model's webhook
*
* @var string
*/
public static $job = DispatchWebhook::class;
/**
* @return bool
*/
public static function queueWebhook() : bool
{
return true;
}