Add the ability to associate factchecks to your Laravel Eloquent models.
$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');You can install the package via composer:
composer require starfolksoftware/factchecksThe package will automatically register itself.
You can publish the migration with:
php artisan vendor:publish --provider="StarfolkSoftware\Factchecks\FactchecksServiceProvider" --tag="migrations"After the migration has been published you can create the media-table by running the migrations:
php artisan migrateYou can publish the config-file with:
php artisan vendor:publish --provider="StarfolkSoftware\Factchecks\FactchecksServiceProvider" --tag="config"To let your models be able to receive factchecks, add the HasFactchecks trait to the model classes.
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use StarfolkSoftware\Factchecks\Traits\HasFactchecks;
class Post extends Model
{
use HasFactchecks;
...
}To create a comment on your commentable models, you can use the comment method. It receives the string of the comment that you want to store.
$post = Post::find(1);
$factcheck = $post->factcheck(array([
'claim' => 'Messi is the greatest of all time',
'conclusion' => 'You cant be wrong with that'
]));The factcheck method returns the newly created factcheck class.
Sometimes you also might want to create factchecks on behalf of other users. You can do this using the factcheckAsUser method and pass in your user model that should get associated
with this factcheck:
$post = Post::find(1);
$factcheck = $post->factcheckAsUser($yourUser, array([
'claim' => 'Messi is the greatest of all time',
'conclusion' => 'You cant be wrong with that'
]));If you want to automatically approve a factcheck for a specific user (and optionally model) you can let your User model implement the following interface and method:
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;
}
}The needsFactcheckApproval method received the model instance that you want to add a factcheck to and you can either return true to mark the factcheck as not approved, or return false to mark the factcheck as approved.
If you want to automatically approve a factcheck for a specific user (and optionally model) you can let your User model implement the following interface and method:
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;
}
}The needsFactcheckApproval method received the model instance that you want to add a factcheck to and you can either return true to mark the factcheck as not approved, or return false to mark the factcheck as approved.
By default, all factchecks that you create are saved as draft and not approved - this is just a datetime column called submitted_at that you can use in your views/controllers to filter out factchecks that you might not yet want to display.
To submit a single comment, you may use the submit method on the Factcheck model like this:
$post = Post::find(1);
$factcheck = $post->factchecks->first();
$factcheck->submit()After submitting a factcheck, the next stage on the journey to publishing is approval - this is just a datetime column called approved_at that you can use in your views/controllers to filter out factchecks that you might not yet want to display.
To approve a single factcheck, you may use the approve method on the Factcheck model like this:
$post = Post::find(1);
$factcheck = $post->factchecks->first();
$factcheck->approve();After approving a factcheck, the final stage is approval - this is just a datetime column called published_at that you can use in your views/controllers to filter out factchecks that you might not yet want to display.
To approve a single factcheck, you may use the publish method on the Factcheck model like this:
$post = Post::find(1);
$factcheck = $post->factchecks->first();
$factcheck->publish();The models that use the HasFactchecks trait have access to it's factchecks using the factchecks relation:
$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();composer testPlease see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.