PHP code example of rinvex / laravel-testimonials

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

    

rinvex / laravel-testimonials example snippets


namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Rinvex\Testimonials\Traits\GivesTestimonials;

class User extends Model
{
    use GivesTestimonials;
}

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Rinvex\Testimonials\Traits\TakesTestimonials;

class Company extends Model
{
    use TakesTestimonials;
}

$user = \App\Models\User::find(1);
$company = \App\Models\Company::find(1);
$testimonial = app('rinvex.testimonials.testimonial');
$testimonialBody = 'I have been using this service as my main learning resource since it went live. I believe it has the best teaching material out there.';

// Create a new testimonial via subject model (attestant, body)
$company->newTestimonial($user, $testimonialBody);

// Create a new testimonial via attestant model (subject, body)
$user->newTestimonial($company, $testimonialBody);

// Create a new testimonial explicitly
$testimonial->make(['body' => $testimonialBody])
            ->subject()->associate($company)
            ->attestant()->associate($user)
            ->save();

$testimonial = app('rinvex.testimonials.testimonial')->find(1);

$company = $testimonial->subject; // Get the owning company model
$user = $testimonial->attestant; // Get the owning user model

$testimonialsOfCompany = app('rinvex.testimonials.testimonial')->ofSubject($company)->get(); // Get testimonials of the given company
$recommendationsOfUser = app('rinvex.testimonials.testimonial')->ofAttestant($user)->get(); // Get testimonials of the given user

$company->testimonialsOf($user)->get(); // Get testimonials of the given user
$user->recommendationsOf($company)->get(); // Get testimonials by the user for the given company

$user->recommendations; // Get given testimonials collection
$user->recommendations(); // Get given testimonials query builder

$company->testimonials; // Get received testimonials collection
$company->testimonials(); // Get received testimonials query builder
shell
    php artisan rinvex:publish:testimonials
    
shell
    php artisan rinvex:migrate:testimonials