A simple blog package for Laravel 4

Overview

Laravel Blog

A Laravel 4 package to add a simple blog to a site

Features

  • Paginated index view with configurable results per page
  • Year/Month archive filtering, including an archive partial that you can include in your own views (requires MySQL)
  • Draft/Approved status and published date fields for approvals and scheduled publishing of posts
  • Configurable URLs, e.g. /blog or /news/yyyy/mm or /articles/< article slug >
  • Fields for title, slug, main image or YouTube Video ID, summary, content, link text and url for external links, is sticky?, published date, status, meta description and keywords, in RSS?
  • Faker seed to seed your blog with loads of good test data
  • Administrator config file for use with FrozenNode's Administrator package
  • Bundled migration for building the database schema
  • Extendable to add categories or tags relationships and filter by them, see below

Installation

Add the following to you composer.json file (Recommend swapping "dev-master" for the latest release)

"fbf/laravel-blog": "dev-master"

Run

composer update

Add the following to app/config/app.php

'Fbf\LaravelBlog\LaravelBlogServiceProvider'

Run the package migration

php artisan migrate --package=fbf/laravel-blog

Publish the config

php artisan config:publish fbf/laravel-blog

Optionally tweak the settings in the many config files for your app

Optionally copy the administrator config file (src/config/administrator/posts.php) to your administrator model config directory.

Create the relevant image upload directories that you specify in your config, e.g.

public/uploads/packages/fbf/laravel-blog/main_image/original
public/uploads/packages/fbf/laravel-blog/main_image/thumbnail
public/uploads/packages/fbf/laravel-blog/main_image/resized

Faker seed

The package comes with a seed that can populate the table with a whole bunch of sample posts. There are some configuration options for the seed in the config file. To run it:

php artisan db:seed --class="Fbf\LaravelBlog\PostTableFakeSeeder"

Configuration

See the many configuration options in the files in the config directory

Administrator

You can use the excellent Laravel Administrator package by FrozenNode to administer your blog.

http://administrator.frozennode.com/docs/installation

A ready-to-use model config file for the Post model (posts.php) is provided in the src/config/administrator directory of the package, which you can copy into the app/config/administrator directory (or whatever you set as the model_config_path in the administrator config file).

Usage

The package should work out the box (provided you have a master blade layout file, since the out-of-the-box views extend this) but if you want to add other content to the pages, such as your own header, logo, navigation, sidebar etc, you'll want to override the views provided.

The package views declare several sections that you may want to yield in your app/views/layouts/master.blade.php file, e.g.:

<!DOCTYPE html>
<html>
<head>
	<title>@yield('title')</title>
	<meta name="description" content="@yield('meta_description')">
	<meta name="keywords" content="@yield('meta_keywords')">
</head>
<body>
<div class="content">
	@yield('content')
</div>
</body>
</html>

The package's views are actually really simple, and most of the presentation is done in partials. This is deliberate so you can override the package's views in your own app, so you can include your own chrome, navigation and sidebars etc, yet you can also still make use of the partials provided, if you want to.

To override any view in your own app, just create the following directories and copy the file from the package into it, then hack away

  • app/views/packages/fbf/laravel-blog/posts
  • app/views/packages/fbf/laravel-blog/partials

Extending the package

This can be done for the purposes of say, relating the Post model to a Category model and allowing filtering by category, or relating the Post model to a User model to add and Author to a Post, or simply just for overriding the functionality in the bundled Post model.

Basic approach

(See the example below for more specific information.)

To override the Post model in the package, create a model in you app/models directory that extends the package model.

Finally, update the IoC Container to inject an instance of your model into the Fbf\LaravelBlog\PostsController, instead of the package's model, e.g. in app/start/global.php

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

To achieve adding a relationship and then filtering by that relationship, this involves extending the Post model to add the relationship method that you want, to another existing model in your app, and overriding the Post::indexByRelationship() method.

In addition, you'll need to create a link between the Post model and the related model. Depending on whether you are going for a belongsTo relationship or a belongsToMany relationship, this will either involve adding a field to the fbf_posts table, e.g. category_id or creating a many-to-many join table between the fbf_posts table and the related model's table, e.g. post_tag. So create a migration for this and run it.

If you are using FrozenNode's Administrator package, update the app/config/administrator/posts.php config file to use your new model e.g. Post instead of Fbf\LaravelBlog\Post, and add the field to the edit_fields section to allow you to attach the Post to the related model.

Finally you need to enable the filter by relationship route. In the package's routes config file in src/config/routes.php change the 'relationship_uri_prefix' value from false to the string you'd like to use in the URL, after the base part, and before the 'relationship identifier'. For example, if you want your URLs to be http://domain.com/posts/tagged/my-tag change the 'relationship_uri_prefix' value to be 'tagged'.

Example for Post belongsToMany Categories (hierarchical)

This is a sample model class that demonstrates how you can add a many to many relationship to the Post model and allow filtering of posts by an item in the related model. This example relates the Post model to a Category model in the fbf/laravel-categories package, which is a hierarchy, so this not only allows you to filter posts to those assigned to a selected category, but to filter them by the selected category and/or any of it's children.

To implement as is, create a file in app/models/Post.php, and copy this code into it

<?php

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');
	}

}

Here is a sample migration to link Posts to Categories. Create a migration called 2014_02_25_154025_link_posts_categories.php and paste this code into it, then run the migration.

<?php

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');
	}

}

If you are using FrozenNode's Administrator package, update the app/config/administrator/posts.php config file to use your new model e.g. Post instead of Fbf\LaravelBlog\Post, and add the field to the edit_fields section to allow you to attach the Post to the related model.

	/**
	 * 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',
		),

As mentioned above, update the IoC Container to inject an instance of your model into the Fbf\LaravelBlog\PostsController, instead of the package's model, e.g. in app/start/global.php

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

Finally you need to enable the 'filter by relationship' route. In the package's routes config file in src/config/routes.php change the 'relationship_uri_prefix' value from false to 'category'.

Once you've created some categories and assigned some posts to them, you can filter the posts by visiting a URL like http://domain.com/blog/category/my-category.

Need comments?

Have a look at https://github.com/FbF/Laravel-Comments

Comments
  • Configuration not found

    Configuration not found

    Hey,

    i`m totally new to lavarel and i tried to install your blog. But i get some errors with artisan

    image

    And in the Frontend i get this error:

    Illuminate \ Database \ QueryException SQLSTATE[42S02]: Base table or view not found: 1146 Table 'lavarel.fbf_blog_posts' doesn't exist (SQL: select count(*) as aggregate from fbf_blog_posts where fbf_blog_posts.status = APPROVED and fbf_blog_posts.published_date <= 2014-04-01 08:19:25)

    What do i wrong ?

    opened by ghost 8
  • thujohn/rss not found

    thujohn/rss not found

    I have a fresh 4.2 install and required your package in my composer.json and did a composer update, see below for what I got back.

    /Applications/MAMP/htdocs/trafficblog: composer update
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Installation request for fbf/laravel-blog dev-master -> satisfiable by fbf/laravel-blog[dev-master].
        - fbf/laravel-blog dev-master requires thujohn/rss dev-master -> no matching package found.
    
    Potential causes:
     - A typo in the package name
     - The package is not available in a stable-enough version according to your minimum-stability setting
       see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
    
    opened by thewinterwind 4
  • Great stuff!  Some requests...

    Great stuff! Some requests...

    I love how easy it is to integrate into an existing Laravel install, and the simplicity of its use.

    Do you have any plans to add Tags, Categories, or the ability to Preview Draft posts? Those are a few things I think that would really round out its functionality.

    enhancement 
    opened by imkane 4
  • Messages configuration

    Messages configuration

    First of all, thanks very much for this packagae - it has saved a lot of time, even though I've done a little modification for my own requirements.

    Speaking of which, I've noticed that there isn't a configuration file for the messages that get used in the views, for example:

    {{ trans('laravel-blog::messages.share.facebook') }}

    After publishing the configration to my project, I've tried creating a configuration file called messages.php under the package's config directory, with the following contents:

    return array(
        'adjacent' => array (
            'prev_link_text' => '&lt; :title',
            'next_link_text' => '&gt; :title'
        ),
        'share' => array (
            'twitter' => 'Yo!'
        )
    );
    

    However this doesn't change the output at all. Have I done something wrong?

    opened by legendarydrew 2
  • Call missing parent constructor in PostsController

    Call missing parent constructor in PostsController

    PostsController derives from BaseController but currently the constructor does not call the parent's constructor, which means any code you have in your BaseController constructor will not be executed.

    opened by borfast 2
  • Allow custom attributes in images.

    Allow custom attributes in images.

    This change allows you to pass an additional array parameter to Post::getImage(), to declare HTML attributes you want your image to have, while maintaining backwards compatibility with existing code.

    Example: if I want an image to use Bootstrap's img-responsive class, I can do it like this:

    {{ $post->getImage('main_image', 'thumbnail', ['class' => 'img-responsive']) }}

    opened by borfast 2
  • Mark this with releases

    Mark this with releases

    Hi, Would it be possible to mark this with a release? It makes it easer to use in production as we can fix it to a release rather then constantly using dev-master which isn't best practice.

    I'd suggest starting at 0.1.0 for this release.

    Thanks.

    opened by johnnye 2
  • installation problems

    installation problems

    i followed the installation guide: . i installed a new laravel package (4.2) . i added "fbf/laravel-blog": "dev-master" at the end of the composer.json file . I launched composer update command (without error messages) . i added 'Fbf\LaravelBlog\LaravelBlogServiceProvider' into app/config/app.php (into providers array) . i launched "php artisan migrate --package=fbf/laravel-blog", but the output it's:

    PHP Fatal error: Class 'Fbf\LaravelBlog\LaravelBlogServiceProvider' not found in /var/www/mypro/bootstrap/compiled.php on line 4415 {"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'Fbf\LaravelBlog\LaravelBlogServiceProvider' not found","file":"/var/www/mypro/bootstrap/compiled.php","line":4415}}

    where i wrong?

    opened by physio 1
  • Update to fzaninotto/Faker 1.4.0

    Update to fzaninotto/Faker 1.4.0

    Just what the title says :)

    Other packages have upgraded and when trying to use both, Composer can't resolve the dependencies, of course.

    Either that or, if the seeding (where Faker is used) is only meant for testing, then move the dependency to require-dev instead of require.

    opened by borfast 1
  • Can't seem to change the way the date is displayed on posts, meta descriptions, etc.

    Can't seem to change the way the date is displayed on posts, meta descriptions, etc.

    For example, in my vendor/fbf/laravel-blog/src/config/views.php, I have:

    <?php
    
    /**
     * Configuration options for the built-in views
     */
    return array(
    
        /**
         * Date format for published date, shown on partials.list and partials.details. Should be
         * a valid date() format string, e.g.
         *
         * @type string
         */
        'published_date_format' => 'jS F, Y',
    

    , but yet the blog doesn't seem to be reading and updating. Same thing goes with the header tag, it still reads "My Blog" instead of what I actually set it to.

    opened by singhjay 1
  • Update view.blade.php (Proposition)

    Update view.blade.php (Proposition)

    I think it will be better to not force the user to provide a page title, because we can also use the title for most situations.

    So something like:

    @section('title')
     {{ !empty($post->page_title) ? $post->page_title : 'Blog &middot; '.$post->title }}
    @endsection 
    

    instead of:

    @section('title')
     {{ $post->page_title }}
    @endsection 
    

    should be appreciate :)

    opened by mercuryseries 1
  • Laravel 8.x support

    Laravel 8.x support

    Hi everyone, to add blog functionality to your laravel website, you just need a package. This is compatible with latest version of laravel framework (laravel 8): https://github.com/vhessam/laravel-blogger

    opened by samberrry 0
  • Cannot remotely connect to postgres

    Cannot remotely connect to postgres

    I cannot make TC/IP connections to Postgres (using postgres.app) server, even after configuring pg_hba and pgpostgres files to listen to different than localhost addresses. Any thoughts? Localhost is on a mac

    opened by mva78 0
  • Installation Error

    Installation Error

    Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for fbf/laravel-blog dev-master -> satisfiable by fbf /laravel-blog[dev-master]. - fbf/laravel-blog dev-master requires thujohn/rss-l4 dev-master -> no match ing package found.

    Please check the requirements and how should i fix this.

    opened by stanwarri 6
  • Can't save with administrator

    Can't save with administrator

    I can't save new posts with Frozennode Administrator. I used the config file as found here.

    When I click save I get the following error: Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost/admin/posts/0/save.

    I think there is a problem with the config-file but I can't find out what...

    opened by centiveo 1
Releases(v0.7.0)
Owner
Five by Five
Five by Five
A simple blog project I built when learning Laravel 8

Harmonify Blog Disclaimer: All users data previewed on the image are fake data generated with FakerPHP. Introduction Harmonify Blog is a simple blog p

Wendy Surya Wijaya 3 Dec 9, 2021
A simple and useful blog coded with laravel & php.

Blog with Setup Directions npm install composer install Set database infos in the .env php artisan migrate:fresh --seed php artisan serve npm run hot

Mustafa Tofur 1 Oct 11, 2022
A simple, proof-of-concept Laravel blog application powered by a MongoDB ORM.

Mongoblog A simple, proof-of-concept Laravel blog application powered by a MongoDB ORM. Separated API and front-end This is a RESTful application, who

Jayps 4 Nov 8, 2022
Dynamic photo package for blog posts and other features, integrating CKEditor Smart WYSIWYG

Dynamic Photo Dynamic Photo is a package to assist in integration with CKEditor, a powerful WYSIWYG. With the package it is possible to send photos dy

Michael Frank 7 Jul 18, 2022
Project of Simple Blog using: HTML, CSS, PHP, MYSQL, and BOOTSTRAP

Project-Stormwind Project of Simple Blog using: HTML, CSS, PHP, MYSQL, and BOOTSTRAP Functions : A personal blog about Blizzard and their work Main Th

Jan Andrzejewski 2 Aug 24, 2022
Simple blog concept with features such authentication (creating accounts, logging in) and commenting.

Simple blog concept with features such authentication (creating accounts, logging in) and commenting. Styling done with tailwindcss and inline javascript is provided by alpineJS.

null 1 Oct 26, 2021
A very simple Blog with Admin Panel built using Laravel5.7 && VueJs2.5 - Quasar0.17

Q-Blog - A very simple Blog with Admin Panel built using [Laravel5.7, VueJs2.5, Quasar0.17]. - This is kind of implementation on different concepts in

Abdelaziz Sliem 132 Dec 23, 2022
A simple blog project based on a custom-created MVC framework using PHP & MySQL

A simple blog project based on a custom-created MVC framework using PHP & MySQL. That follows the Facade design pattern.

Samiul Arafah Dhrubo 2 May 28, 2022
This is a simple blog system, you can sign up and create post.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Nnadi Chimezie Charles 1 Jan 8, 2022
A powerful open source Laravel Blog with WYSWYG and CRUD (Create Read Update Delete) built on Laravel 5.8 and Bootstrap 4

Larablog A powerful open source Laravel Blog with WYSWYG and CRUD (Create Read Update Delete) built on Laravel 5.8 and Bootstrap 4 Table of contents F

Jeremy Kenedy 144 Oct 11, 2022
This is a blog. A project was written in Laravel 8

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Vladimir Kryazhev 1 Oct 23, 2021
A powerful and responsive blog system powered by laravel 5.5.

Powerful and responsive blog system powered by laravel 5.5. Click https://lufficc.com/blog to view live demo. Xblog 中文 README | Docs This blog is for

Congcong Li 924 Nov 18, 2022
FULL STACK LARAVEL BLOG SITE

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

null 1 Oct 29, 2021
Blog dengan framework laravel 8 sebagai backend dan tailwind sebagai frontend

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Muh Nur Afrizal 2 Dec 24, 2021
Latihan membuat Blog menggunakan LARAVEL

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

taufiq alif r 1 Nov 11, 2021
This Laracast Blog is built with Laravel 8.x taught by Jeffery Way on Laracasts

This Laracast Blog is built with Laravel 8.x taught by Jeffery Way on Laracasts. I followed his tutorial videos and added new features as he mentioned on his Github.

Wai Yan Kyaw 1 Dec 7, 2021
This is a personal portfolio and blog project based on Laravel 5.1.

nahid.co [Laravel 5.1] This is my personal blog project develop with latest Laravel version 5.1. Its opensource for students learning purpose. Install

Nahid Bin Azhar 22 Aug 12, 2022
The completed blog demo project from Laravel 8 From Scratch.

Laravel From Scratch Blog Demo Project http://laravelfromscratch.com Installation First clone this repository, install the dependencies, and setup you

Jeffrey Way 379 Jan 5, 2023
This is a Laravel based Blog post forum.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Hossain Mohammad Shahidullah Jaber 4 Nov 17, 2022