1. Go to this page and download the library: Download dirkblack/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/ */
dirkblack / blog example snippets
use DirkBlack\Blog\Support\BlogRoleResolver;
// In tinker or a seeder:
BlogRoleResolver::assign($user, 'admin');
use DirkBlack\Blog\Traits\HasBlogRole;
class User extends Authenticatable
{
use HasBlogRole;
}
// Then:
$user->assignBlogRole('admin');
'prefix' => 'blog',
'middleware' => [
'web' => ['web'], // Applied to the SPA catch-all route
'api' => ['web'], // Applied to all API routes
],
'user_model' => 'App\\Models\\User',
'comments' => [
'enabled' => true, // Master switch: turn commenting on/off
'auto_approve' => false, // true = publish instantly; false = hold as pending for admin approval
'threading_depth' => 3, // Max nesting depth (0 = flat comments)
],
'markdown_classes' => [
'h1' => 'text-4xl font-bold mb-6',
'h2' => 'text-2xl font-semibold mb-4 mt-8',
'p' => 'mb-4 leading-relaxed',
// ... see config file for all 12 elements
],
use DirkBlack\Blog\Traits\HasBlogRole;
class User extends Authenticatable
{
use HasBlogRole;
}
$user->blogRole(); // Returns BlogRole enum (e.g., BlogRole::Author)
$user->assignBlogRole('author');
$user->revokeBlogRole(); // Reverts to guest
$user->hasBlogRole('author'); // true if author or higher
$user->isBlogAdmin(); // true if admin
$user->isBlogAuthor(); // true if author or admin
use DirkBlack\Blog\Support\BlogRoleResolver;
BlogRoleResolver::resolve($user); // Returns BlogRole enum
BlogRoleResolver::assign($user, 'admin'); // Assign role
BlogRoleResolver::revoke($user); // Remove role (back to guest)
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens;
}
use DirkBlack\Blog\Support\Markdown\MarkdownConverter;
$converter = app(MarkdownConverter::class);
$html = $converter->convert('Some **markdown** text');
use DirkBlack\Blog\Support\Shortcodes\ShortcodeContext;
use DirkBlack\Blog\Support\Shortcodes\ShortcodeInterface;
class NewsletterFormComponent implements ShortcodeInterface
{
public function name(): string
{
return 'newsletter';
}
/**
* @param array<int, string> $params Positional params from {{newsletter|compact}}
*/
public function render(array $params, ShortcodeContext $context): string
{
$style = $params[0] ?? 'full';
// Request-derived state comes through the context, never request():
// shortcodes render inside the JSON API response, so the browser URL
// is only visible via the query the SPA forwards.
$page = $context->page(); // ?page=N, defaults to 1
$source = $context->query('utm_source'); // any query param
$nextHref = $context->queryString(['page' => $page + 1]); // keeps other params
$post = $context->post; // the Post being rendered, or null
return '<form class="newsletter ' . e($style) . '">…</form>';
}
}
// Via API: POST /author/posts/{id}/publish
{ "scheduled_at": "2026-04-01T09:00:00" }
bash
# Publish compiled frontend assets (ssets
# Publish config file (recommended)
php artisan vendor:publish --tag=blog-config
# Publish migrations if you want to customize them
php artisan vendor:publish --tag=blog-migrations
bash
php artisan migrate
markdown
{{recent-posts|5}} <!-- 5 most recent published posts -->
{{featured-posts|3}} <!-- posts flagged meta.featured (falls back to recent) -->
{{tags|cloud}} <!-- tag cloud; also list|popular, with optional limit -->
{{posts|10}} <!-- paginated post list, 10 per page -->
bash
php artisan vendor:publish --tag=blog-styles
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.