1. Go to this page and download the library: Download fomvasss/laravel-str-tokens 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/ */
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Fomvasss\Taxonomy\Models\Traits\HasTaxonomies;
class Article extends Model
{
use HasTaxonomies;
//...
public function strTokenTest($entity, $method, $attr): string
{
// $entity - this article
// $method - "test"
// $attr - additional args
return 'TEST TOKEN:' . $attr;
}
public function strTokenCreatedAt(): string
{
return $this->created_at->format('d.m.Y');
}
// For package https://github.com/fomvasss/laravel-simple-taxonomy
public function txArticleStatus()
{
return $this->term('status', 'system_name')
->where('vocabulary', 'post_statuses');
}
}
namespace App\Models\Taxonomies;
use App\Article;
class Term extends \Fomvasss\Taxonomy\Models\Term
{
public function articles()
{
return $this->morphedByMany(Article::class, 'termable');
}
/**
* Method for generate next example token for article model:
* [article:txArticleCategories:root:name]
*
* @param $entity
* @param $r
* @param $param
* @return mixed
*/
public function strTokenRoot($entity, $r, $param)
{
if ($root = $entity->ancestors->first()) {
return $root->{$param};
}
return $entity->{$param};
}
}