PHP code example of enadstack / blogify

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

    

enadstack / blogify example snippets


'tenancy' => ['mode' => 'single'],   // single | shared | isolated

use Enadstack\Blogify\Facades\Blogify;

Blogify::resolveOwnerUsing(fn () => app()->bound('currentTenant')
    ? app('currentTenant')
    : $this->tenantFromHost(request()->getHost()));

Post::query()->get();               // the current owner only
Post::query()->forOwner($tenant);   // one specific owner
Post::query()->platform();          // platform-level content
Post::query()->ownedByAnyone();     // every tenant, excluding the platform
Post::query()->allOwners();         // everything — admin and moderation views

$post = Post::create(['type' => 'post', 'status' => 'draft']);

$post->setTranslations([
    'en' => ['title' => 'Ten Tips for Better Sleep', 'body' => '...'],
    'ar' => ['title' => 'عشر نصائح لنوم أفضل', 'body' => '...'],
]);

$post->t('title', 'ar');   // 'عشر نصائح لنوم أفضل'
$post->slug('ar');         // 'عشر-نصائح-لنوم-أفضل'

$category = Term::create(['taxonomy' => 'category']);
$category->setTranslation('ar', ['name' => 'قانون الأسرة']);

$post->terms()->attach($category);

$media = app(MediaAdapter::class)->store($request->file('image'), [
    'attachable' => $post,
    'collection' => 'hero',
    'alt' => ['en' => 'A clinic room', 'ar' => 'غرفة في العيادة'],
]);

$url = fn (string $locale, string $slug) => route('blog.show', [$locale, $slug]);

Blogify::seo($post, 'ar', $url);      // title, description, canonical, robots, OG, Twitter, hreflang
Blogify::schema($post, 'ar', $url);   // JSON-LD, @type from the post's schema_type column
Blogify::sitemap($owner, $url);       // a Generator of sitemap entries

if ($post = Blogify::resolveHistoricalSlug($slug, $locale)) {
    return redirect()->route('blog.show', [$locale, $post->slug($locale)], 301);
}

Blogify::findBySlug($slug, $locale);   // published, scoped to the current owner

'database' => ['key_type' => 'id'],   // id | ulid | uuid

'tenancy' => ['

Route::get('/{slug?}', [PageController::class, 'show'])->where('slug', '[a-z0-9-]+');
bash
composer blogify:install
php artisan migrate
bash
php artisan vendor:publish --tag=blogify-migrations-tenant