PHP code example of wangta69 / laravel_board

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

    

wangta69 / laravel_board example snippets


public function __construct()
{
    $this->middleware('auth');

    // Example: Check for administrator role
    // if (!Auth::user()->hasRole('administrator')) {
    //     abort(403, 'Unauthorized action.');
    // }
}

// config/pondol-bbs.php
'admin' => [
    'layout' => [
        // 1) Component format (e.g. 'pondol-common::common-admin')
        // 2) Traditional @extends format (e.g. 'admin.layouts.admin')
        // 3) null: Runs standalone with package default layout
        'name' => 'pondol-common::common-admin',

        // LNB sidebar view (set null to use host's native sidebar)
        'lnb' => 'bbs::lnb-partial',

        // Section name for @extends mode (default: 'content')
        'section' => 'content',

        // Title section name for @extends mode (default: 'title')
        'title_section' => 'title',
    ],
],

public function index()
{
    // usage: bbs_get_latest(['table' => 'table_name', 'cnt' => count])
    $notices = bbs_get_latest(['table' => 'notice', 'cnt' => 5]);

    return view('welcome', compact('notices'));
}

use Pondol\Bbs\Events\ArticleCreated;
use Pondol\Bbs\Events\CommentCreated;
use Illuminate\Support\Facades\Event;
use App\Helpers\TelegramHelper;

public function boot()
{
    // Example 1: Send Telegram alert when a new post is created
    Event::listen(ArticleCreated::class, function (ArticleCreated $event) {
        $message = "πŸ“’ [μƒˆ κΈ€ 등둝] <b>{$event->cfg->name}</b>\n";
        $message .= "제λͺ©: {$event->article->title}\n";
        $message .= "μž‘μ„±μž: {$event->article->writer}\n";
        $message .= "링크: " . route('bbs.show', [$event->cfg->table_name, $event->article->id]);

        TelegramHelper::send($message);
    });

    // Example 2: Hook into comment creation
    Event::listen(CommentCreated::class, function (CommentCreated $event) {
        // Custom logic: Notify article author, award points, etc.
    });
}

namespace App\Services;

use Pondol\Bbs\Contracts\BbsQueryCustomizer as BbsQueryCustomizerInterface;

class BbsQueryCustomizer implements BbsQueryCustomizerInterface
{
    /**
     * @param \Illuminate\Database\Eloquent\Builder $query
     * @param \Pondol\Bbs\Models\BbsTables $cfg
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function indexQuery($query, $cfg, $request)
    {
        // Custom join for 'qna' board
        if ($cfg->table_name === 'qna') {
            $query->leftJoin('users as u', 'u.id', '=', 'bbs_articles.user_id')
                  ->leftJoin('agents as a', 'u.agent', '=', 'a.id')
                  ->addSelect([
                      'bbs_articles.*',
                      'a.name as agent_name',
                      'u.email'
                  ]);
        }

        return $query;
    }
}

use Pondol\Bbs\Contracts\BbsQueryCustomizer;
use App\Services\BbsQueryCustomizer as MyBbsQueryCustomizer;

public function register()
{
    $this->app->bind(
        BbsQueryCustomizer::class,
        MyBbsQueryCustomizer::class
    );
}

namespace App\Services;

use Pondol\Bbs\Contracts\BbsMetaResolver;
use Illuminate\Support\Str;

class MyBbsMetaResolver implements BbsMetaResolver
{
    /**
     * @param \Pondol\Meta\Meta $meta
     * @param string $type 'index' or 'show'
     * @param object $cfg Board Configuration (BbsTables)
     * @param object|null $article Article Data (BbsArticles)
     * @param mixed|null $collection Articles Collection (on index)
     */
    public function resolve($meta, $type, $cfg, $article = null, $collection = null)
    {
        if ($cfg->table_name === 'notice') {
            $meta->title("[Notice] " . ($article ? $article->title : $cfg->name));
        }

        if ($type === 'show' && $article) {
            $description = Str::limit(strip_tags($article->content), 160);
            $meta->description($description);

            if ($article->image) {
                $meta->image(\Storage::disk('public')->url($article->image));
            }
        }

        return $meta;
    }
}

public function register()
{
    $this->app->bind(
        \Pondol\Bbs\Contracts\BbsMetaResolver::class,
        \App\Services\MyBbsMetaResolver::class
    );
}
bash
php artisan pondol:install-bbs
html
<!-- usage: bbs_get_thumb($image_path, $width, $height) -->
<img
  src="{{ bbs_get_thumb($article->image, 205, 205) }}"
  alt="{{ $article->title }}"
/>
bash
php artisan vendor:publish --tag=bbs-views