PHP code example of agenciamav / laravel-ifood

1. Go to this page and download the library: Download agenciamav/laravel-ifood library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

agenciamav / laravel-ifood example snippets


// .env
IFOOD_CLIENT_ID=******
IFOOD_CLIENT_SECRET=******

namespace App\Models;

use Agenciamav\LaravelIfood\LaravelIfood;

class User extends Model
{
	use LaravelIfood;
}

$user = request()->user(); // Ou qualquer model que use o trait

// 1. Obtém USER CODE para inserir no portal do iFood
$user->getUserCode();  // Retorna: 'XXXX-XXXX'

// 2. Após informar o USER CODE no portal do iFood, um AUTHORIZATION CODE será gerado
$auth_code = 'XXXX-XXXX'; // O código de autorização gerado pelo iFood

// 3. Passando o AUTHORIZATION CODE, obtém-se o token de acesso
$user->getAccessToken($auth_code); // Retorna o ACCESS TOKEN

use Agenciamav\LaravelIfood\Models\Merchant;

Merchant::all(); // Obtém todas as lojas conectadas
Merchant::show('xxx...'); // Obtém detalhes de uma loja via UUID
sh
php artisan vendor:publish --provider=Agenciamav\LaravelIfood\LaravelIfoodServiceProvider

/config
	/ifood.php

/resources
	/js
		/Pages
			/Ifood
				Auth.vue
				Merchant.vue
				Header.vue
				...