1. Go to this page and download the library: Download mayoz/laravel-categorizable 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;
use Mayoz\Categorizable\Category as BaseCategory;
class Category extends BaseCategory
{
/**
* Get all posts for the relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphedByMany
*/
public function posts()
{
return $this->categorized(Post::class);
}
}
return [
/*
|--------------------------------------------------------------------------
| Model Namespace
|--------------------------------------------------------------------------
|
| Change these values when you need to extend the default category model
| or if the user model needs to be served in a different namespace.
|
*/
'category' => App\Category::class,
];
/**
* Respond the post
*
* @param \App\Category $category
* @return \Illuminate\Http\Response
*/
public function index(Category $category)
{
return $category->posts()->paginate(10);
}
/**
* Respond the post
*
* @param \App\Category $category
* @return \Illuminate\Http\Response
*/
public function index(Category $category)
{
return $category->categorize(Post::class)->paginate(10);
}