Setting custom configuration values

With Laravel, setting configuration values is quite easy. All config values are within an array and will be defined as a key=>value pair.

Now let’s make a new configuration file. Save this file as image.php in config:

Installing a third-party library

We should make an upload form and then a controller for our image site. But before doing that, we will install a third-party library for image processing as we will be benefiting from its methods. Laravel 4 uses Composer , so it’s quite easy to install packages, update packages, and even update Laravel. For our project, we will be using a library called Intervention . The following steps must be followed to install the library:

  1. First, make sure you have the latest composer.phar file by running php composer.phar self-update in your terminal.
  2. Then open composer.json and add a new value to the require section. The value for our library is intervention/image: "dev-master".Currently, our composer.json file’s require section looks as follows:
    "require": {
      "laravel/framework": "5.1.*",
      "intervention/image": "dev-master"
    }

    You can find more packages for Composer at www.packagist.org.

  3. After setting the value, open your terminal, navigate to the project’s root folder, and type the following command:
    php composer.phar update
    

    This command will check composer.json and update all the dependencies (including Laravel itself) and if new requirements are added, it will download and install them.

  4. After successfully downloading the library, we will now activate it. For this, we refer to the website of the Intervention class. Now open your app/config/app.php, and add the following value to the providers key:
    Intervention\image\imageServiceProvider
  5. Now, we need to set an alias so that we can call the class easily. To do this, add the following value to the aliases key of the same file:
    'image' => 'Intervention\image\Facades\image',
  6. The class has a notation that is quite easy to understand. To resize an image, running the following code will suffice:
    image::make(Input::file('image')->getRealPath())->resize(300, 200)->save('foo.jpg');

Note

For more information about the Intervention class, go to the following web address:

http://intervention.olivervogel.net

Now, everything for the views and the form processing is ready; we can go on to the next step of our project.