PHP code example of lecturize / laravel-taxonomies
1. Go to this page and download the library: Download lecturize/laravel-taxonomies 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/ */
lecturize / laravel-taxonomies example snippets
" "lecturize/laravel-taxonomies": "^1.2"
}
namespace App\Models;
use Lecturize\Taxonomies\Contracts\CanHaveCategories;
use Lecturize\Taxonomies\Traits\HasCategories;
class Post extends Model implements CanHaveCategories
{
use HasCategories;
// ...
}
namespace App\Models;
use App\Models\Post;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Lecturize\Taxonomies\Models\Taxonomy as TaxonomyBase;
class Taxonomy extends TaxonomyBase
{
public function posts(): MorphToMany
{
return $this->morphedByMany(Post::class, 'taxable', 'taxables')
->withTimestamps();
}
}