rockbuzz/lara-posts

Management of posts

0.0.5 2021-08-20 15:59 UTC

This package is auto-updated.

Last update: 2024-03-20 21:24:05 UTC


README

Management of posts

Build Status

Requirements

PHP >=7.2

Install

$ composer require rockbuzz/lara-posts
$ php artisan vendor:publish --provider="Rockbuzz\LaraPosts\ServiceProvider" --tag="migrations"
$ php artisan migrate

Config

$ php artisan vendor:publish --provider="Rockbuzz\LaraPosts\ServiceProvider" --tag="config"
<?php

return [
    'tables' => [
        'authors' => 'users'
    ],
    'route_key_name' => 'slug',
    'models' => [
        'post' => \Rockbuzz\LaraPosts\Models\Post::class,
        'author' => \App\User::class,
    ]
];

Usage

use Illuminate\Database\Eloquent\Model;
use Rockbuzz\LaraPosts\Traits\HavePosts;

class User extends Model
{
    use HavePosts;
    //
}

$author = User::find(1);
$author->posts(): HasMany
use Rockbuzz\LaraPosts\Models\Post;

$post = Post::find('uuid');
$post->author(): BelongsTo
$post->isDraft(): bool
$post->isModerate(): bool
$post->isPublished(): bool
$post->isArticle(): bool
$post->isPodcast(): bool
$post->isVideo(): bool

Scope

Post::draft(): Builder
Post::moderate(): Builder
Post::approved(): Builder
Post::published(): Builder
Post::articles(): Builder
Post::podcasts(): Builder
Post::videos(): Builder
Post::latestPublished(): Builder

Use Your Model

namespace App;

use Rockbuzz\LaraPosts\Models\Post;

class YourPost extends Post
{
    //
}

//set in the configuration file
'models' => [
    'post' => \App\YourPost::class,
    //
]

License

The Lara Posts is open-sourced software licensed under the MIT license.