Giter VIP home page Giter VIP logo

larablog's Introduction

Larablog

A package for easier maintenance of the blog (or news) articles.

Installation, Configuration and Usage

Via Composer:

$ composer require gorankrgovic/larablog

Configuration

Once you install the package, it should be automatically discovered by the Laravel. To check this, in your terminal simply run the:

$ php artisan

Once you run the command, you shoul dbe able to find all larablog commands available.

First step is to publish the vendor files. In this case only the config file.

$ php artisan vendor:publish --tag="larablog"

After you inspect the configuration file, it depends on your skills :). I recommend running the:

$ php artisan larablog:setup

The above command will install models, make the migration file and add a trait to your User model.

After the setup please run the migration command

$ php artisan migrate

Which will create the tables for this package: articles and categories. (you can change the names in your config file).

Once the tables are ready, please make sure to seed the initial category.

$ php artisan larablog:seeder

The above command will create a seeder class. After you created a seeder, please run the

$ composer du

And then run the seeder

$ php artisan db:seed --class=LarablogSeeder

Thats. basically it.

Usage

Create your controller resource or whatever and then simply:

$article = new Article([
            'title' => 'This is my title',
            'slug' => 'this-is-my-slug',
            'excerpt' => 'This is my excerpt',
            'content' => 'This is my content',
            'is_featured' => false,
            'status' => 'publish',
            'publish_at' => Carbon::now()
]);

// associate the user
$article->associateUser(1);
// save the article
$article->save();

// attach the category
$article->attachCategory('uncategorized'); // name or the ID

// or multiple categories
$article->attachCategories([1, 2, 3]); // names or ID's

To get the article you can, for example:

$article = Article::find(1);

// get the categories (cacheable)
$article->getCategories();

Or you can fetch all articles from a user

$user = User::find(1);

$articles = $user->getArticles();

// or
$articles = $user->getArticlesPaginated(20);

// or
$articles = $user->articles()->get();

Also you can use provided scopes

$articles = Article::whereCategoriesAre([1, 2, 3])->get(); // pass an array of IDs

// or

$articles = Article::whereCategoryIs(1)->get(); // pass an id

Facade

Larablog provides you with convenient helpers to make your life easier

use Gorankrgovic\Larablog\Facades\Larablog;

// ... and then in your methods...

// to generate a unique slug which will append number at the end of the slug if the same slug exists
$slug = Larablog::slug($title);

// to convert string to paragraph delimited text
$text = Larablog::autop($content);

// to generate the excerpt
$excerpt = Larablog::excerpt($content);

// to just sanitize the title and to get a slug
$slug = Larablog::sanitize_title($title);

Basically thats it...

larablog's People

Contributors

gorankrgovic avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.