PHP code example of larastash / reviews

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

    

larastash / reviews example snippets


namespace App\Models;

...
use Larastash\Reviews\Concerns\Reviewable;

class Product extends Model
{
    use Reviewable;

    ...
}

namespace App\Models;

...
use Larastash\Reviews\Concerns\Reviewer;

class User extends Model
{
    use Reviewer;

    ...
}

review($product)
$product->review();

$product->review($value, $body, $title, $extra, $userId);

review($product)->publish(5); // only value
review($product)->publish(5, 'I love it!'); // value & body
review($product)->publish(5, 'I love it!', 'Awesome'); // value, body & title
review($product)->publish(5, title: 'Awesome'); // value & title

review($product)->extra(['approved' => false, 'recommended' => 1])->publish(5);

review($product)->with('approved', false)->with('recommended', 1)->publish(5);

review($product)->as(User::find(1337))->publish(5);
review($product)->as(1337)->publish(5);

review($product)->with('approved', true)->update(5);

review($product)->by(User::find(1337))->with('approved', true)->update(5);
review($product)->by(1337)->with('approved', true)->update(5);

review($product)->exists();

review($product)->by(User::find(1337))->exists();
review($product)->by(1337)->exists();

review($product)->delete();

review($product)->by(User::find(1337))->delete();
review($product)->by(1337)->delete();

review($product)->total();

review($product)->avg();
review($product)->avg(precision: 0); // 2 by default

review($product)->avg('recommended');
review($product)->avg('recommended', 0); // precision is 2 by default

review($product)->query()->doSomething();

$product = Product::with('reviews');

$product = Product::withReviewAvgValue();
$product->reviews_avg_value;

Product::orderByReviewValue();

Product::orderByReviewValueDesc();

$product = Product::withReviewAvgExtra('recommended')->first();
$product->reviews_avg_extra_recommended;

Product::orderByReviewExtra('recommended');

Product::orderByReviewExtraDesc('recommended');

use App\Models\Product;
use Larastash\Reviews\Models\Review;

Review::withType(Product::class)->count();

auth()->user()->reviews;
shell
php artisan vendor:publish --tag="larastash:reviews"