0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LaravelでEbica APIを利用した飲食店予約機能の実装

Posted at

皆さん、こんにちは。

今回は【LaravelでEbica APIを利用した飲食店予約機能の実装】について紹介させていただきます。

飲食店の予約管理システムを開発する際、外部の予約プラットフォームと連携することで効率的に予約情報を扱うことができます。本記事では Laravel を使って Ebica API と連携し、基本的な飲食店予約機能を実装する方法について紹介します。

Ebica APIとは

Ebicaは飲食店向けの予約・顧客管理サービスです。
外部のシステムから利用可能なAPIが提供されており、例えば以下のような処理が可能です。

  • 予約の新規登録
  • 予約一覧の取得
  • 予約キャンセル
  • 顧客情報の参照

これにより、自社アプリやWebサービスとシームレスに連携できます。

実装ステップ

Ebica APIの認証

Ebica APIは API Key による認証が必要です。.env ファイルに以下を設定しておきます。

EBICA_API_KEY=your_api_key
EBICA_BASE_URL=https://api.ebica.jp/v1

APIクライアントの作成

LaravelでEbica APIを利用するために、Httpファサードを使ってAPIクライアントを作成します。

// app/Services/EbicaService.php
namespace App\Services;

use Illuminate\Support\Facades\Http;

class EbicaService
{
    protected $baseUrl;
    protected $apiKey;

    public function __construct()
    {
        $this->baseUrl = config('services.ebica.base_url');
        $this->apiKey = config('services.ebica.api_key');
    }

    public function createReservation(array $data)
    {
        return Http::withHeaders([
            'Authorization' => 'Bearer ' . $this->apiKey,
        ])->post($this->baseUrl . '/reservations', $data)->json();
    }

    public function getReservations($date)
    {
        return Http::withHeaders([
            'Authorization' => 'Bearer ' . $this->apiKey,
        ])->get($this->baseUrl . '/reservations', [
            'date' => $date,
        ])->json();
    }
}

コントローラーでの利用例

// app/Http/Controllers/ReservationController.php
namespace App\Http\Controllers;

use App\Services\EbicaService;
use Illuminate\Http\Request;

class ReservationController extends Controller
{
    protected $ebica;

    public function __construct(EbicaService $ebica)
    {
        $this->ebica = $ebica;
    }

    public function store(Request $request)
    {
        $data = [
            'shop_id' => $request->shop_id,
            'date' => $request->date,
            'time' => $request->time,
            'people' => $request->people,
            'name' => $request->name,
            'phone' => $request->phone,
        ];

        $response = $this->ebica->createReservation($data);

        return response()->json($response);
    }
}

実際のAPIレスポンス例

{
  "reservation_id": "123456",
  "status": "confirmed",
  "shop_id": "abc123",
  "date": "2025-09-20",
  "time": "19:00",
  "people": 2
}

まとめ

  • LaravelとEbica APIを組み合わせることで、飲食店の予約機能を効率的に実装できる
  • Httpファサードを使うとAPI連携がシンプルになる
  • 今回は予約登録と取得の基本的な部分を紹介したが、顧客管理やキャンセル処理なども拡張可能

今後は、予約キャンセル機能 や 顧客情報の管理機能 を追加することで、より実用的な予約管理システムに発展させることができます。

今日は以上です。

ありがとうございました。
よろしくお願いいたします。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?