PHP code example of kraenzle-ritter / resources-components
1. Go to this page and download the library: Download kraenzle-ritter/resources-components 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/ */
kraenzle-ritter / resources-components example snippets
namespace App\Listeners;
use KraenzleRitter\ResourcesComponents\Events\ResourceSaved;
class UpdateLocationWithGeonamesCoordinates
{
public function handle(ResourceSaved $event)
{
if ($event->resource->provider == 'geonames') {
// Access resource data
\Log::debug($event->resource);
// Access the model that the resource is attached to
\Log::debug($event->model);
// Example: Update location coordinates from Geonames data
if (isset($event->resource->data['lat']) && isset($event->resource->data['lng'])) {
$event->model->update([
'latitude' => $event->resource->data['lat'],
'longitude' => $event->resource->data['lng']
]);
}
}
}
}
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use KraenzleRitter\ResourcesComponents\Events\ResourceSaved;
use App\Listeners\UpdateLocationWithGeonamesCoordinates;
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
ResourceSaved::class => [
UpdateLocationWithGeonamesCoordinates::class
]
];
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use KraenzleRitter\Resources\HasResources;
class Person extends Model
{
use HasResources;
// The rest of your model...
}