Installation
composer require baks-dev/vk-board
php artisan vendor:publish --provider="BaksDev\VkBoard\VkBoardServiceProvider" --tag="config"
php artisan baks:assets:install
config/vk-board.php exists and update API credentials (VK app ID, secret, etc.).First Use Case: Fetching Board Data
use BaksDev\VkBoard\Facades\VkBoard;
$board = VkBoard::getBoard('your_board_id');
dd($board->topics); // Returns a collection of topics
Key Files to Review
config/vk-board.php (API credentials, defaults)app/Providers/VkBoardServiceProvider.php (Service binding)routes/vk-board.php (Predefined routes, if any)CRUD Operations
// Create a topic
$topic = VkBoard::createTopic([
'title' => 'New Topic',
'message' => 'Hello, world!',
'board_id' => 'your_board_id'
]);
// Update a topic
$topic->update(['title' => 'Updated Title']);
// Delete a topic
$topic->delete();
Event-Driven Integration
use BaksDev\VkBoard\Events\TopicCreated;
event(new TopicCreated($topic));
API Wrapper Abstraction
$response = VkBoard::api()->method('boards.getTopics', [
'board_id' => 'your_board_id',
'count' => 10
]);
Model Integration
use BaksDev\VkBoard\Models\Topic;
class MyTopic extends Topic {
protected $table = 'my_topics';
}
Middleware for Auth
Route::get('/board', function () {
return VkBoard::getUserBoard();
})->middleware('vk.auth');
API Rate Limits
$topics = Cache::remember("vk_board_{$boardId}_topics", now()->addHours(1), function () use ($boardId) {
return VkBoard::getBoard($boardId)->topics;
});
Locale/Encoding Issues
mb_internal_encoding('UTF-8');
Webhook Delays
use BaksDev\VkBoard\Jobs\ProcessWebhook;
ProcessWebhook::dispatch($payload)->onQueue('vk-webhooks');
Board Permissions
boards, messages, etc.) in the VK Developer Console.Enable Debug Mode
Add to config/vk-board.php:
'debug' => env('APP_DEBUG', false),
Logs API calls and responses to storage/logs/vk-board.log.
Mock API Responses
Use the VkBoardMock trait in tests:
use BaksDev\VkBoard\Testing\VkBoardMock;
public function testTopicCreation()
{
VkBoardMock::shouldReceive('createTopic')->once()->andReturn(new Topic());
// ...
}
Custom API Methods
Extend the BaksDev\VkBoard\Api\Client class:
namespace App\Services;
use BaksDev\VkBoard\Api\Client;
class CustomVkClient extends Client
{
public function customMethod(array $params)
{
return $this->call('custom.method', $params);
}
}
Model Observers Add observers to track changes:
use BaksDev\VkBoard\Models\Topic;
use Illuminate\Database\Eloquent\Builder;
Topic::observe(TopicObserver::class);
class TopicObserver
{
public function saved(Topic $topic)
{
// Log or notify on topic updates
}
}
Command-Line Tools Create custom Artisan commands:
php artisan make:command SyncVkBoard
Example:
use BaksDev\VkBoard\Facades\VkBoard;
class SyncVkBoard extends Command
{
protected $signature = 'vk:sync {board_id}';
public function handle()
{
$board = VkBoard::getBoard($this->argument('board_id'));
// Sync logic here
}
}
Webhook Handling
Extend the BaksDev\VkBoard\WebhookHandler:
namespace App\Services;
use BaksDev\VkBoard\WebhookHandler;
class CustomWebhookHandler extends WebhookHandler
{
protected function handleTopicCreate(array $payload)
{
// Custom logic for topic creation
}
}
Bind it in AppServiceProvider:
$this->app->bind(
\BaksDev\VkBoard\Contracts\WebhookHandler::class,
\App\Services\CustomWebhookHandler::class
);
How can I help you explore Laravel packages today?