Category Archives: Laravel

Requires Doctrine DBAL Laravel migration

If you are running a migration to change the data type of a column in a table. You might come across this error message in terminal.

This error message is telling you to install doctrine/dbal to make this work. You can learn more about this package here https://github.com/doctrine/dbal

To install this package through composer, run following command in terminal.

Now you can run your migration by running

This should work now.

Install Mcrypt PHP extension on Ubuntu (PHP-FPM + Nginx)

To install Mcrypt PHP extension on Ubuntu / Debian run following command ( this step is same for Nginx and apache )

This will create a mcrypt module in /etc/php5/mods-available directory. If it doesnt we need to create symlink for this.

Now enable mcrypt by running

After this restart php5-fpm service by

 

Remove # from url in Angular JS and Laravel 5

To remove # from Angular JS application built with Laravel , add following line in your config.

Add this in your head tag

Now it will work fine till you do not refresh the page. If you refresh your page at this point, you will see page not found error, it is because now browser sends request to server and server doesn’t have the route.

To do this we will add this route at the end of routes.php

 

 

PHP Fatal error: Uncaught exception ‘UnexpectedValueExcepti$

After fresh installation of Laravel 5.1, it was not showing up the welcome page. Further investigating into this issue revealed that “storage” directory is not writable.

To make storage directory writable run following commands

Then run:

Resize image in Laravel

To re size image in laravel we will use a library called Intervention.

Intervention Image is an open source PHP image handling and manipulation library. It provides an easier and expressive way to create, edit, and compose images and supports currently the two most common image processing libraries GD Library and Imagick. ( from their website)

So lets start with installation, the easiest way to install intervention is through composer. So run the following command in your terminal inside your application folder

composer require intervention/image

If it asks for specify version to be installed, add current stable version for this I will enter  2.1.2 (which is latest version at the time of writing this post) .

After you have installed Intervention Image, open your Laravel config file config/app.php and add the following lines.

In the $providers array add the service providers for this package.

‘Intervention\Image\ImageServiceProvider’

Add the facade of this package to the $aliases array.

‘Image’ => ‘Intervention\Image\Facades\Image’

Now the Image Class will be auto-loaded by Laravel.

Now we are done with the installation part, lets create a route to test our image re sizing.

// usage inside a laravel route

Route::get(‘/’, function() {

$img = Image::make(‘foo.jpg’)->resize(300, 200);

return $img->response(‘jpg’);

});

This will resize the provided image into 300 * 200 jpeg image. There some other options also, lets see them.

// To resize only the width of the image
$img->resize(300, null);

// To resize only the height of the image

$img->resize(null, 200);

// To resize the image to a width of 300 and constrain aspect ratio (auto height)
$img->resize(300, null, function ($constraint) {
$constraint->aspectRatio();
});

// To resize the image to a height of 200 and constrain aspect ratio (auto width)
$img->resize(null, 200, function ($constraint) {
$constraint->aspectRatio();
});

Besides image resize, intervention provides whole lot of functions to perform image manipulation. No matter if you want to create image thumbnails, watermarks or format large image files Intervention Image helps you to manage every task in an easy way with as little lines of code as possible.

Adding SMTP header in Laravel 4

I was working with Mandrill api to send emails, to track the emails I needed to add smtp header. Here is how you can add smtp header to emails.

 

Deploying Laravel on Heroku

Use Buildpack

https://github.com/winglian/heroku-buildpack-php

Download Heroku client tool

Try by typing heroku in command prompt

Log into Heroku

enter your account username and password

Now neter

This buildpack also supports custom Document Roots in your application. Simply add an environment variable. If your document root is public in the root of your repo, then run

Composer Warning: openssl extension is missing

While installing Laravel via composer on Wamp server I got this error

You must enable the openssl extension to download files via https

To resolve this issue, go to

c:/wamp/bin/php/{your php version} and open php.ini file. Uncomment the line by removing the semi colon in front of it

extension=php_openssl.dll

restart all service, it should work. Remember do not edit php.ini file from Wamp UI because it edits apache’s php.ini file.

 

Laravel Migration : add column to existing table

To add a new column to an existing table after specific column user ‘after’  using Schema builder in Laravel 4