PHP code example of beziworld / laravel-opinions

1. Go to this page and download the library: Download beziworld/laravel-opinions 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/ */

    

beziworld / laravel-opinions example snippets


use Beziworld\Opinions\Data\Invitation;
use Beziworld\Opinions\Data\InvitationProduct;
use Beziworld\Opinions\Facades\Opinions;

$invitation = new Invitation(
    orderReference: $order->number,
    email: $order->email,
    firstName: $order->first_name,
    lastName: $order->last_name,
    orderedAt: $order->created_at,
    products: $order->items->map(fn ($item) => new InvitationProduct(
        sku: $item->sku,
        name: $item->name,
        url: route('product', $item->product),     // 

use Beziworld\Opinions\Data\ReviewQuery;
use Beziworld\Opinions\Enums\ReviewType;

$page = Opinions::driver('trustedshops')->reviews(ReviewQuery::approved(20));

foreach ($page->items as $review) {
    $review->rating;          // 4.0 (1 to 5)
    $review->title;
    $review->comment;
    $review->authorName;
    $review->verified;
    $review->reply;           // shop reply, if any
    $review->submittedAt;     // CarbonImmutable in the application time zone
}

$older = Opinions::driver()->reviews(ReviewQuery::approved(20)->withAfter($page->nextCursor));

// product reviews for given SKUs, iterating over every page lazily
Opinions::driver()->cursor(new ReviewQuery(type: ReviewType::Product, skus: ['SKU-1'], statuses: ['APPROVED']));

Opinions::rating();                          // cached Rating: average, count, distribution, period, trend
Opinions::rating('trustedshops', 'outlet');
Opinions::refreshRating();                   // fetch now and store

// routes/console.php
Schedule::command('opinions:refresh-ratings')->hourly();

// config/opinions.php: 'shops' => ['default' => [...], 'outlet' => ['trustedshops' => [...]]]
Opinions::shop('outlet')->queueInvitation($invitation);
Opinions::shop('outlet')->driver('trustedshops')->reviews();

// credentials stored per tenant
Opinions::using('trustedshops', $tenant->trustedShopsCredentials(), shop: $tenant->key)->invite($invitation);

// custom driver
Opinions::extend('opineo', fn (array $config, string $shop) => new OpineoDriver($config, $shop));