Friday, March 22, 2013

Create a Custom Validation Rules in Laravel 3


1.Open Start.php in the application folder and add a path map to your class that you are going to use in validation

Autoloader::map(array(

 'customValidator' => __DIR__.DS.'libraries'.DS.'Cvalidator.php',

));






in this code,   the name of my custom validator class is: 'Cvalidator.php'
and reside in  the directory : application/libraries/
Now, The system will know the place of your class .
2. Also in the smae file 'start.php' register your new validation rule as follows:


Laravel\Validator::register('customrule', function($attribute, $value, $parameters)

{

 return customValidator::CheckThis($attribute, $value, $parameters);

});




3.Next you need to create your class with methodes that will handle the validation staff. but assure that you put in the right path that you map it in start.php, here an example: 

Don't Extend the Laravel Validation Class



<?php class Cvalidator{ public static

 CheckThis(){ 

 //do the validation heare then: return true or false only return true;
}

Saturday, March 16, 2013

php artisan key setup on laravel

First When I tried to generate an application key for Laravel application I got this error :

'php' is not recognized as an internal or external command,
operable program or batch file.  


That means the system does not know what this command is , you have to tell your system what is 'php' and that can be done by adding php folder to the system path :
1-  On start command line type environment and choose from results the system environment not the account environment.




2.Click on Environments Variables 
3.click on Edit then add the path to php.exe on the end of the line , dont add the file name php.exe to the path, just the folder that contain the file.
4. reboot the system.








Now for Laravel to run artisan :

1. Go to the application folder in your Laravel project and open the file application.php, and find the key value :
'key' => ''.
this value must be empty nothing inside it .
2.opend the command screen by typing cmd.exe on the start run line.
3. on the command prompt change directory to Laravel Directory.
4. Type  php artisan key:generate.
the system will response by this message " Configuration  updated with secure key"
the Key value in application.php file will be changed by the system.
Thats All ,

For Laravel-4 the same process can be  applied