PHP code example of ozankurt / imgur-laravel

1. Go to this page and download the library: Download ozankurt/imgur-laravel 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/ */

    

ozankurt / imgur-laravel example snippets




namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Http\Request;

use Kurt\Imgur\Imgur;

class HomeController extends Controller
{
    /**
     * Imgur instance.
     *
     * @var \Kurt\Imgur\Imgur
     */
    private $imgur;

    public function __construct(Imgur $imgur)
    {
        $this->imgur = $imgur;
    }

    /**
     * Retrieve an image by its id.
     * 
     * @return \Imgur\Api\Model\Image
     */
    public function getImage(Request $request)
    {
        $imageApi = $this->imgur->getImageApi();

        $imageModel = $imageApi->image(
            $request->input('id')
        );

        return $imageModel;
    }

    /**
     * Upload an image with a given url or a file.
     * 
     * @return \Imgur\Api\Model\Image
     */
    public function getUpload(Request $request)
    {
        // Upload with a url.
        $imageModel = $this->imgur->uploadFromUrl(
            $request->input('image_url')
        );

        // Upload with a file.
        $imageModel = $this->imgur->upload(
            $request->file('image')
        );

        return $imageModel;
    }
}


composer 

    'imgur' => [
        'client_id' => env('IMGUR_CLIENT_ID'),
        'client_secret' => env('IMGUR_CLIENT_SECRET'),
    ],

IMGUR_CLIENT_ID=
IMGUR_CLIENT_SECRET=

    'providers' => [
        // ...

        Kurt\Imgur\ImgurServiceProvider::class,
    ],