ehsan9/metabase-laravel

connect to the Metabase web service in Laravel project and have the output of reports

v1.0 2022-12-29 14:27 UTC

This package is auto-updated.

Last update: 2024-04-30 00:27:14 UTC


README

First Metabase should be installed . You can get more info Here.

Installation

Step 1 - Install the package

You can install ehsan9/metabase-laravel with Composer directly in your project:

$ composer require ehsan9/metabase-laravel

Step 2 - Publish

Run this command in your project directory:

php artisan vendor:publish --provider="Ehsan9\MetabaseLaravel\MetabaseServiceProvider"

Step 3 - Set config

Now you must define your Metabase Url, Username and Password to project. for this head to config/metabase-api.php then put your metabase info in the code:

return [
    'url' => 'https://yoursmetabase.com',
    'username' => 'your_metabase_username',
    'password' => 'your_metabase_pass'
];

Usage

You can use the package where ever you want.

  • Method 1:

    • First use the class:
      use Ehsan9\MetabaseLaravel\MetabaseApi;
    • Then use this pattern to connect Metabase api:
      $metabaseApi = new \Ehsan9\MetabaseLaravel\MetabaseApi(
          config('metabase-api.url'), config('metabase-api.username'), config('metabase-api.password')
      );
              $parameters = [
                  [
                      "type" => "category",
                      "value" => "YOUR_VALUE",
                      "target" => [
                          "variable",
                          [
                              "template-tag",
                              "member_id"
                          ]
                      ]
                  ]
              ];
      
      $result = $metabaseApi->getQuestion('questionId', 'json', $parameters);
  • Method 2:

    • use MetabaseApi Facade in ServiceProvider
    use Ehsan9\MetabaseLaravel\Facades\MetabaseApi;
    • then use this pattern
      MetabaseApi::getQuestion('questionId');