PHP code example of starfolksoftware / factchecks

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

    

starfolksoftware / factchecks example snippets


$post = Post::find(1);

/**
 * Attach a factcheck to this model.
 *
 * @param string $claim
 * @param string $conclusion
 * @return \Illuminate\Database\Eloquent\Model
 */
$post->factcheck('Messi is the great', 'You cant be wrong with that');

/**
 * Attach a factcheck to this model as a specific user.
 *
 * @param Model|null $user
 * @param string $claim
 * @param string $conclusion
 * @return \Illuminate\Database\Eloquent\Model
 */
$post->factcheckAsUser($user, 'Messi is the great', 'You cant be wrong with that');

$post = Post::find(1);

$factcheck = $post->factcheck(array([
  'claim' => 'Messi is the greatest of all time',
  'conclusion' => 'You cant be wrong with that'
]));

$post = Post::find(1);

$factcheck = $post->factcheckAsUser($yourUser, array([
  'claim' => 'Messi is the greatest of all time',
  'conclusion' => 'You cant be wrong with that'
]));

namespace App\Models;

use StarfolkSoftware\Factchecks\Contracts\Factchecker;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements Factchecker
{
  /**
   * Check if a comment for a specific model needs to be approved.
   * @param mixed $model
   * @return bool
   */
  public function needsFactcheckApproval($model): bool
  {
    return false;    
  } 
}

namespace App\Models;

use StarfolkSoftware\Factchecks\Contracts\Factchecker;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements Factchecker
{
  /**
   * Check if a comment for a specific model needs to be approved.
   * @param mixed $model
   * @return bool
   */
  public function needsFactcheckApproval($model): bool
  {
    return false;    
  } 
}

$post = Post::find(1);
$factcheck = $post->factchecks->first();

$factcheck->submit()

$post = Post::find(1);
$factcheck = $post->factchecks->first();

$factcheck->approve();

$post = Post::find(1);
$factcheck = $post->factchecks->first();

$factcheck->publish();


$post = Post::find(1);

// Retrieve all factchecks
$factchecks = $post->factchecks;

// Retrieve only drafted factchecks
$drafts = $post->factchecks()->draft()->get();

// Retrieve only approved factchecks
$approved = $post->factchecks()->approved()->get();

// Retrieve only published factchecks
$published = $post->factchecks()->published()->get();

bash
php artisan vendor:publish --provider="StarfolkSoftware\Factchecks\FactchecksServiceProvider" --tag="migrations"
bash
php artisan migrate
bash
php artisan vendor:publish --provider="StarfolkSoftware\Factchecks\FactchecksServiceProvider" --tag="config"