PHPackages                             waltersilvacruz/laravel-meli - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. waltersilvacruz/laravel-meli

ActiveLibrary[HTTP &amp; Networking](/categories/http)

waltersilvacruz/laravel-meli
============================

A Laravel wrapper for Mercado Livre Rest API

v1.1.8(2y ago)3540—0%2MITPHPPHP ^7.2|^8.0

Since Nov 5Pushed 2y ago1 watchersCompare

[ Source](https://github.com/waltersilvacruz/laravel-meli)[ Packagist](https://packagist.org/packages/waltersilvacruz/laravel-meli)[ RSS](/packages/waltersilvacruz-laravel-meli/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)DependenciesVersions (11)Used By (0)

MercadoLibre API Integration for Laravel
========================================

[](#mercadolibre-api-integration-for-laravel)

Integrate your Laravel Application with MercadoLibre's API.

Based on [vcoud/mercadolibre](https://github.com/vcoud/mercadolibre) (thank you, man!).

PHP client wrapper for [MercadoLibre API](https://developers.mercadolibre.com/).

This package was designed to work with [Laravel](https://www.laravel.com), so it was written with Laravel in mind.

Installation
------------

[](#installation)

1. Install with composer:

```
$ composer require waltersilvacruz/laravel-meli
```

2. Run the migration command to create the `meli_app_tokens` table:

```
$ php artisan migrate --package=waltersilvacruz/laravel-meli
```

The package uses the [auto registration feature](https://laravel.com/docs/packages#package-discovery) of Laravel.

Configuration
-------------

[](#configuration)

**IMPORTANT**: Before you start, check the following:

- You **must** have a MercadoLibre account
- You **must** create an APP into ML's [DevSite](https://developers.mercadolibre.com/devcenter/)
- The APP **must** have the `offline_access` scope enabled (otherwise the *refresh token* will not be generated)
- You **must** have both APP Code and Client Secret in hands to setup into your Laravel application.

1. Add the appropriate values to your `.env`

    ```
    MELI_APP_ID=
    MELI_CLIENT_SECRET=
    MELI_REDIRECT_ROUTE=     # The user will be redirected to this route after connect/disconnect
    ```

    example:

    ```
    MELI_APP_ID=4181152627684157
    MELI_CLIENT_SECRET=kbJ1YVaWpqmFYhj1PsnKSOcVKEvWxp1a
    MELI_REDIRECT_ROUTE=home
    ```
2. Publish configs &amp; views *\[optional\]*

    #### Config file

    [](#config-file)

    A configuration file named `meli.php` can be published to `config/` by running the following command:

    ```
    php artisan vendor:publish --tag=meli-config
    ```

    #### Publishing Views

    [](#publishing-views)

    View files can also be published by using:

    ```
    php artisan vendor:publish --tag=meli-views
    ```

    The blade's templates will be published into `resources/views/vendor/meli` folder, so you can customize the templates to apply your application's look and feel.
3. Clear your route and config caches:

    ```
    php artisan config:clear && php artisan route:clear

    ```

Usage
-----

[](#usage)

### First, connect your Laravel Application into MercadoLibre via Oauth

[](#first-connect-your-laravel-application-into-mercadolibre-via-oauth)

You can connect to ML opening this link on browser: `/meli/connect/`. Here, the `` parameter is mandatory!

This wrapper uses `` as unique identifier for each authentication token, allowing your site to connect to multiples ML accounts.

Example:

```
https://my-awesome-site.com/meli/connect/store-demo-1

```

### Using methods to retrieve data from ML

[](#using-methods-to-retrieve-data-from-ml)

Once connected, you can perform queries to ML's API using one of the following methods:

```
MeliAppService::get(string $path, array $params = [], bool $assoc = false): stdClass
MeliAppService::post(string $path, array $body = []): stdClass
MeliAppService::put(string $path, array $body = [], array $params = []): stdClass
MeliAppService::delete(string $path, array $params = []): stdClass
MeliAppService::options(string $path, array $params = []): stdClass
```

Sample code:

```
