PHP code example of fbf / laravel-blog

1. Go to this page and download the library: Download fbf/laravel-blog 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/ */

    

fbf / laravel-blog example snippets


App::bind('Fbf\LaravelBlog\PostsController', function() {
    return new Fbf\LaravelBlog\PostsController(new Post);
});



use Fbf\LaravelCategories\Category;

class Post extends Fbf\LaravelBlog\Post {

	/**
	 * Defines the belongsToMany relationship between Post and Category
	 *
	 * @return mixed
	 */
	public function categories()
	{
		return $this->belongsToMany('Fbf\LaravelCategories\Category', 'category_post');
	}

	/**
	 * Query scope to filter posts by a given category
	 *
	 * @param $query
	 * @param $categorySlug
	 * @throws InvalidArgumentException
	 * @return mixed
	 */
	public function scopeByRelationship($query, $categorySlug)
	{
		$category = Category::live()
			->where('slug', '=', $categorySlug)
			->first();

		if (!$category)
		{
			throw new InvalidArgumentException('Category not found');
		}

		return $query->join('category_post', $this->getTable().'.id', '=', 'category_post.post_id')
			->join('fbf_categories', 'category_post.category_id', '=', 'fbf_categories.id')
			->whereBetween('fbf_categories.lft', array($category->lft, $category->rgt))
			->groupBy($this->getTable().'.id');
	}

}



use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class LinkPostsCategories extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('category_post', function(Blueprint $table)
		{
			$table->integer('category_id');
			$table->integer('post_id');
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('category_post');
	}

}

	/**
	 * The class name of the Eloquent model that this config represents
	 *
	 * @type string
	 */
	'model' => 'Post',

		'categories' => array(
			'title' => 'Categories',
			'type' => 'relationship',
			'name_field' => 'path',
			'options_sort_field' => 'name',
		),

App::bind('Fbf\LaravelBlog\PostsController', function() {
    return new Fbf\LaravelBlog\PostsController(new Post);
});