PHP code example of ojessecruz / simple-blog

1. Go to this page and download the library: Download ojessecruz/simple-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/ */

    

ojessecruz / simple-blog example snippets


// Via a specific Gate
'admin_middleware' => ['web', 'auth', 'can:manage-blog'],

// Via a separate guard
'admin_middleware' => ['web', 'auth:admin'],

// Combo of your app's own middleware
'admin_middleware' => ['web', 'auth', 'verified', 'super.admin'],

Gate::define('manage-blog', fn ($user) => $user->is_admin === true);

// config/blog.php
'author_model' => App\Models\User::class,

use Jessecruz\SimpleBlog\Contracts\Author;

class User extends Authenticatable implements Author
{
    public function getBlogAuthorName(): string
    {
        return $this->name;
    }

    public function getBlogAuthorInitials(): string
    {
        $words = preg_split('/\s+/', trim($this->name)) ?: [];
        $initials = array_map(
            fn (string $w) => mb_strtoupper(mb_substr($w, 0, 1)),
            array_slice($words, 0, 2),
        );

        return implode('', $initials);
    }

    public function getBlogAuthorAvatarUrl(): ?string
    {
        return $this->avatar_url; // or null if you don't have avatars
    }
}

'layouts' => [
    'public' => 'layouts.blog-public',
    'admin' => 'blog::layouts.admin',
],

'public' => 'layouts.blog-public',

'admin' => 'layouts.app',  // your <x-app-layout> view, no wrapper needed

'cta_view' => 'components.blog-cta',

use Jessecruz\SimpleBlog\Models\Post;

$posts = Post::published()->with('category')->latest('published_at')->get();
bash
php artisan simple-blog:install
bash
php artisan vendor:publish --tag="simple-blog-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="simple-blog-config"
bash
php artisan vendor:publish --tag="simple-blog-views"
js
content: [
    // ... your existing paths ...
    './vendor/ojessecruz/simple-blog/resources/views/**/*.blade.php',
],