First Metabase should be installed . You can get more info Here.
You can install ehsan9/metabase-laravel with Composer directly in your project:
$ composer require ehsan9/metabase-laravel
Run this command in your project directory:
php artisan vendor:publish --provider="Ehsan9\MetabaseLaravel\MetabaseServiceProvider"
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'
];
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');