PHP code example of makeabledk / laravel-eloquent-status
1. Go to this page and download the library: Download makeabledk/laravel-eloquent-status 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/ */
makeabledk / laravel-eloquent-status example snippets
class ApprovalStatus extends \Makeable\EloquentStatus\Status
{
public function pending($query)
{
return $query
->whereNull('tutor_approved_at')
->whereNull('teacher_approved_at')
->whereNull('assessor_approved_at');
}
public function reviewing($query)
{
return $query
->whereNotNull('tutor_approved_at')
->whereNull('assessor_approved_at');
}
public function approved($query)
{
return $query
->whereNotNull('tutor_approved_at')
->whereNotNull('teacher_approved_at')
->whereNotNull('assessor_approved_at');
}
}
use \Makeable\EloquentStatus\HasStatus;
class Approval extends Eloquent
{
use HasStatus;
}
$approval->checkStatus(new ApprovalStatus('reviewing')); // true or false
use \Makeable\EloquentStatus\HasStatus;
class Approval extends Eloquent
{
use HasStatus;
public function getStatusAttribute()
{
return ApprovalStatus::guess($this);
}
}
use Makeable\EloquentStatus\StatusManager;
StatusManager::bind(Approval::class, ApprovalStatus::class);
$approval->checkStatus('accepted');
Approval::status(new ApprovalStatus('approved'))->get(); // Collection
// Or when default status is defined
Approval::status('approved')->get(); // Collection