Creating a image model

As you know, for anything related to database operations on Laravel, using models is the best practice. We will take advantage of the Eloquent ORM.

Save the following code as images.php in the app directory:

<?php
class image extends Eloquent {

  //the variable that sets the table name
  protected $table = 'images';

  //the variable that sets which columns can be edited
  protected $fillable = array('title','image');

  //The variable which enables or disables the Laravel'stimestamps option. Default is true. We're leaving this hereanyways
  public $timestamps = true;
}

We have set the table name with the protected $table variable. The content of which columns of the table can be updated/inserted will be decided with the protected $fillable variable. Finally, whether the model can add/update timestamps or not will be decided by the value of the public $timestamps variable. Just by setting this model (even without setting anything), we can easily use all the advantages of Eloquent ORM.

Our model is ready, now we can proceed to the next step and start to create our controller along with the upload forms. But before this, we are missing one simple thing. Where should the images be uploaded? What will be the maximum width and height of the thumbnails? To set these configuration values (think of it like constants of raw PHP), we should create a new configuration file.