[Laravel 4] change column name in Migration

In Laravel 3, you can change column name in migration file. From Laravel 4, If you are using the renameColumn function in your migrations, you will need to add the doctrine/dbal dependency to your composer.json file. This package is no longer included in Laravel by default.

So, just  include "doctrine/dbal":"*", as a dependency in composer.json.
Update by running composer update:



In migration class, you can use renameColumn method like the following:
Schema::table('TABLE_NAME', function($table)
{
    $table->renameColumn('OLD_COLUMN_NAME', 'NEW_COLUMN_NAME');
});

[Laravel 4] Class not Found error when using migrate:rollback


Run composer dump-autoload  in terminal to update autoload class file. After that, run migrate:rollback again

Sublime text 2 - Setting vertical line after 80 characters

Hold on !  Why 80 characters ?

Well, I think It's common coding standard (May be it's a result of the IBM's 1928 80 column punched card format )


In Sublime text 2, we can add one or more vertical lines after amount of characters (basing on what you setted) like the following: As you can see, I have 3 vertical line on the right side of screen.To set them, just open up your setting file in "Prefernce/ settings-User" menu , and add "rulers": [80,90,100] option :
/* Preferences / settings-User*/
{
 "color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
 "font_size": 15,
 "ignored_packages":
 [
  "Vintage"
 ],
 "rulers": [80,90,100]


}

The values of array : [80,90,100] are the number of characters  alternately.

Generate migration from existed database in Laravel 4

Laravel supports migration function which help us manage database and collaborate with team members better. We write code to define schema, execute the migration to evolve the database schema.
Synchronize our source code with all team members, each person will knows about any scheme change. When you deloy for app on a production server , it's also a robust way to upgrade our database schema, I think.

I'm using Laravel with mySQL database. For quick database design, For some project, we need some database design first (It sounds  not in Agile way ^^). I use mySQL workbench and synchronize between local database and MySQL Workbench's EER model. We have EER diagram for document, live database in right place. And, we need migrate source in right place ,too.

Let's think about the work - flow in this situation:

For the first time.

ER analysis --> create EER diagram in mySQL workbench --> synchronize with dev database --> generate migration source code.
Change database schema when developing: 

Edit migration source --> migrate into DB --> synchronize with EER diagram in mySQL workbench to update EER diagram.

Thank to JeffreyWay  and Xethron who created  2 amazing tools which  help us generate migration source code from existed database in Laravel 4.

We need some config.

 Install Laravel 4 generator &  Laravel migrations Generator.

Edit your  project's composer.json and add an "require-dev" section:
 "require-dev":{
  "xethron/migrations-generator": "dev-master" 
 },
Run
composer update
You should see that xethron/migrations-generator has required way/generators package. way/generators
package is also installed.

Edit your config/app.php file (I recommend to create dev or local enviroment and make them separate from production )
  'Way\Generators\GeneratorsServiceProvider',
  'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider',
Run php artisan command you would see generate command is added to migrate


Generate migration from existed database

Run php artisan migrate:generate command to generate migrate file of all tables in current connection.
It will creates migration files of all tables and foreign keys in your databases.

(To be continue ....)

Auto complete for Phalcon framework in Eclipse

Phalcon is a web framework implemented as a C extension , every Phalcon's fan know that. It mean we cannot view source code of framework like another PHP framework.

Thank for Phalcon Developer tool. It provide useful interface & class declaration scripts which support IDE auto complete function.

Assuming that, Phalcon developer tools  is installed.

In Eclipse, you just need to add devtool path : phalcon-devtools/ide/PHALCON_VERSION by adding external Source Folder in PHP include Path / Libraries tab.



Install Phalcon & Phalcon developer tool in Ubuntu 13.10

I installed  Phalcon on Ubuntu 13.10 from  Official manual and faced some problems may make beginner confused.

I.  install Phalcon 

First of all. I installed php development resources & GCC compiler:
sudo apt-get install php5-dev php5-mysql gcc
Download & install phalcon:

git clone --depth=1 git://github.com/phalcon/cphalcon.git
cd cphalcon/build
sudo ./install
Faced first error:
/usr/include/php5/ext/pcre/php_pcre.h:29:18: fatal error: pcre.h: No such file or directory #include "pcre.h" ^ compilation terminated. make: *** [phalcon.lo] Error 1 
After checking for a while, Phalcon need : libpcre3-dev pakage :
apt-get install libpcre3-dev
wee need add new config in additional .ini files/

Create phalcon.ini file in /etc/php5/apache2/conf.d/phalcon.ini add : extension=phalcon.so in this file. 

Reload your server. It works !

II. Install Phalcon developer tool 

After installing Phalcon and Phalcon developer tool successfully . We may got new message when try to use Phalcon developer tool by phalcon command
$ phalcon
ERROR: Phalcon extension isn't installed, follow these instructions to install it: http://docs.phalconphp.com/en/latest/reference/install.html

It means your php cli didn't realase phalcon framework (phalcon.so). Wee need to add phalcon.ini files in configuration file of PHP5 cli. First of all, find Configuration file Path by command
 php -i | grep "Configuration File"
#result:

Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini

#cd to Configuration Path
$ cd /etc/php5/cli/
$ /etc/php5/cli$ ls

#result
conf.d  php.ini
You can see that we have another php.ini file and conf.d folder in Configuration path. Add phalcon.ini which contain extension=phalcon.so into conf.d folder.

Try your  phalcon command again . It works !

Config Apache 2.4 in Ubuntu

From Ubuntu 12.04 LTS, Apche have new version 2.4 which is different from 2.2 and below.
The configuration hierarchy is listed in apache2.conf file 's comment.

# /etc/apache2/
# |-- apache2.conf
# | `--  ports.conf
# |-- mods-enabled
# | |-- *.load
# | `-- *.conf
# |-- conf-enabled
# | `-- *.conf
`-- sites-enabled
#   `-- *.conf

# * apache2.conf is the main configuration file (this file). It puts the pieces
#   together by including all remaining configuration files when starting up the
#   web server.
#
# * ports.conf is always included from the main configuration file. It is
#   supposed to determine listening ports for incoming connections which can be
#   customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
#   directories contain particular configuration snippets which manage modules,
#   global configuration fragments, or virtual host configurations,
#   respectively.
#
#   They are activated by symlinking available configuration files from their
#   respective *-available/ counterparts. These should be managed by 127.using our
#   helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
#   their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
#   the default configuration, apache2 needs to be started/stopped with
#   /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
#   work with the default configuration.


I. How to change DocumentRoot in Apache 2.4

 I found that we need 3 steps:

1. Add more Directory  in  /etc/apache2/apache2.conf

<Directory YOUR_FOLDER>
 Options Indexes FollowSymLinks
 AllowOverride None
 Require all granted
</Directory>

2. Change default documentRoot in /etc/apache2/sites-available/000-default.conf :
   DocumentRoot /var/www

to

  DocumentRoot YOUR_FOLDER

3. Restart your Apache server : sudo service apache2 restart or  sudo /etc/init.d/apache2 restart

II. How to add virtualhost

We need 3 steps to complete this configure

 1. In /etc/apache2/sites-available folder  create SITENAME.conf file
( SITENAME is your name you want to set)
In SITENAME.conf  config your new virtual host
<VirtualHost *:80>
        DocumentRoot  YOUR_NEW_VIRTUAL_HOST_FOLDER
        ServerName YOUR_VIRTUAL_DOMAIN_NAME
        ServerAlias  YOUR_VIRTUAL_DOMAIN_ALIAS
        ServerAdmin webmaster@localhost

        ErrorLog ${APACHE_LOG_DIR}/error.log

        CustomLog ${APACHE_LOG_DIR}/access.log combinedme

</VirtualHost>

Remember : documentRoot should be configured before ServerName.

2. Run command : sudo a2ensite SITENAME.conf  
3. Restart your Apache server : sudo service apache2 restart or  sudo /etc/init.d/apache2 restart

※ Notes: Using debug command : bapache2ctl -S to get to know how your server is configured. 


You can see more how to config in this link