lopatin96 / laravel-blog
Laravel blog
Installs: 8 174
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.0
- jaybizzle/crawler-detect: ^1.2
- lopatin96/laravel-ui-components: ^1.0
- orhanerday/open-ai: ^5.2
- spatie/laravel-sluggable: ^3.4
Requires (Dev)
- orchestra/testbench: ^8.0
- dev-master
- 1.0.45
- 1.0.44
- 1.0.43
- 1.0.42
- 1.0.41
- 1.0.40
- 1.0.39
- 1.0.38
- 1.0.37
- 1.0.36
- 1.0.35
- 1.0.34
- 1.0.33
- 1.0.32
- 1.0.31
- 1.0.30
- 1.0.29
- 1.0.28
- 1.0.27
- 1.0.26
- 1.0.25
- 1.0.24
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
This package is auto-updated.
Last update: 2024-12-20 22:09:22 UTC
README
Trait
Add HasPosts
trait to User model.
use Atin\LaravelBlog\Traits\HasPosts; class User extends Authenticatable { use HasPosts;
Nova
Metrics
PostsPerDay
<?php namespace App\Nova\Metrics; use Atin\LaravelBlog\Models\Post; use Laravel\Nova\Http\Requests\NovaRequest; use Laravel\Nova\Metrics\Trend; class PostsPerDay extends Trend { public $width = '1/4'; public function calculate(NovaRequest $request): \Laravel\Nova\Metrics\TrendResult { return $this->countByDays($request, Post::class); } public function ranges(): array { return [ 7 => __('7 Days'), 30 => __('30 Days'), 60 => __('60 Days'), 90 => __('90 Days'), 180 => __('180 Days'), 365 => __('1 Year'), 730 => __('2 Years'), ]; } public function cacheFor(): \DateInterval|float|\DateTimeInterface|\Illuminate\Support\Carbon|int|null { return now()->addMinute(); } }
Resources
Post
<?php namespace App\Nova; use Illuminate\Support\Facades\Storage; use Laravel\Nova\Fields\BelongsTo; use Laravel\Nova\Fields\Boolean; use Laravel\Nova\Fields\DateTime; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Image; use Laravel\Nova\Fields\Line; use Laravel\Nova\Fields\Number; use Laravel\Nova\Fields\Stack; use Laravel\Nova\Fields\Text; use Laravel\Nova\Fields\Trix; use Laravel\Nova\Fields\URL; use Laravel\Nova\Http\Requests\NovaRequest; class Post extends Resource { public static string $model = \Atin\LaravelBlog\Models\Post::class; public static $title = 'id'; public static $search = [ 'title', 'feature', ]; public function fields(NovaRequest $request): array { return [ ID::make() ->sortable(), BelongsTo::make('User') ->displayUsing(fn ($user) => mb_strimwidth($user->name, 0, 32, '…')), URL::make('Open', fn () => '/blog/' . $this->slug), Text::make('Title') ->sortable() ->displayUsing(fn () => mb_strimwidth($this->title, 0, 32, '…')), Text::make('Slug') ->hideFromIndex(), Trix::make('Body'), Image::make('Image') ->disk('s3') ->path('posts/' . date('Y/m/d')) ->thumbnail(function ($image) { return $image ? Storage::disk('s3') ->temporaryUrl($image, now()->addMinute()) : null; }) ->preview(function ($image) { return $image ? Storage::disk('s3') ->temporaryUrl($image, now()->addMinute()) : null; }), Text::make('Feature') ->sortable(), Text::make('Meta title') ->hideFromIndex(), Text::make('Meta description') ->hideFromIndex(), Boolean::make('Published'), Number::make('Views') ->sortable() ->readonly(), Stack::make('Last View At', [ DateTime::make('Last View At'), Line::make(null, function () { return $this->last_view_at ? "({$this->last_view_at->diffForHumans()})" : null; }) ->asSmall(), ]) ->sortable() ->readonly(), Stack::make('Created At', [ DateTime::make('Created At'), Line::make(null, function () { return "({$this->created_at->diffForHumans()})"; }) ->asSmall(), ]) ->sortable() ->readonly(), ]; } public function cards(NovaRequest $request): array { return [ new Metrics\PostsPerDay, ]; } }
Post generator
Config
Fill in content_generation_data
in laravel-blog.php
with data for which countries (languages) and with which probability from 0 to 100 (where 0 - do not generate, 50 - generate every 2 days, 100 - generate every day) you want to automatically generate new posts.
Important! Provide a wide description of your website in site_description
.
Publishing
Migrations
php artisan vendor:publish --tag="laravel-blog-migrations"
Localization
php artisan vendor:publish --tag="laravel-blog-lang"
Views
php artisan vendor:publish --tag="laravel-blog-views"
Config
php artisan vendor:publish --tag="laravel-blog-config"