Get Started with Laravel

Get Started with Laravel

Reference for the Magic Admin SDK for Laravel: https://github.com/magiclabs/magic-laravel

note

Looking for a PHP SDK instead? Check out:

šŸ‘‰ Magic Admin SDK for PHP

Overview

The Magic Laravel SDK makes it easy to leverage Decentralized ID Tokens to authenticate your users for your app. This guide will cover some important topics for getting started with server-side APIs and to make the most of Magic's features.

  • Install the Magic Laravel SDK to get started

  • View the API documentation below to learn the methods you'll be using

  • Go to Examples for an introduction to common patterns and use-cases

note

Looking for a client-side API instead? Check out:

šŸ‘‰ Magic Client SDK for Web

šŸ‘‰ Magic Client SDK for React Native

Installation

Current SDK is built for Laravel 5.3 or newer.

Composer

You can install the bindings via Composer. Run the following command:

composer require magiclabs/magic-laravel

Older Laravel Installation

If you are using Laravel 5.5 or newer then skip this part. Otherwise you will need to manually register the service provider and facade alias by going to config/app.php

Add to the providers array:

MagicLaravel\ServiceProvider::class

Add to the aliases array:

'Magic' => MagicLaravel\Facade::class

Setup

Publish config file.

php artisan vendor:publish --provider="MagicLaravel\ServiceProvider"

Add MAGIC_SECRET_API_KEY to your .env file by going to the Magic Dashboard.

MAGIC_SECRET_API_KEY=sk_XXXX_XXXXXXXXXXXXXXXX

Creating an SDK Instance

Get instance using the app helper

$magic = app('MagicLaravel\Magic'); $magic->token->validate('<did_token>'); $magic->user->get_metadata_by_token('<did_token>');

Get instance using the facade

use Magic; Magic::token()->validate('<did_token>'); Magic::user()->get_metadata_by_token('<did_token>');