Month: January 2014

Laravel 4.x setting in production and development

Surely, in production use you don’t want to show any error to the user. In simple way, you can set debug to false:
/app/config/app.php

return array (

'debug' => false,

[...]

)

For complete setting for development and production, you can try;
/app/bootstrap/start.php

$env = $app->detectEnvironment(array(
	'local' => array('localURL.com'),
	'production' => array('productionURL.com')
));

Define your file/folder configuration for every situation (development/production):

app
app/config
app/config/local
app/config/local/app.php
app/config/local/database.php
app/config/production
app/config/production/app.php
app/config/production/database.php
Advertisements

Easiest way to write library in Laravel

Sometimes you have change a lot in your Laravel configuration and folder. This will avoiding running composer again.

First, just open your /app/start/global.php. Add a folder libraries (whatever you want):

app_path().'/commands',
app_path().'/controllers',
app_path().'/models',
app_path().'/database/seeds',
app_path().'/libraries',

And now you can add any file in your libraries folder.

Example:

<?php

/* File: Bantu.php */

class Bantu {

    public static function write( $message ) {

        echo $message;

    }

}

Non Alpha Numeric Regex with Javascript

Using javascript regular expressions to stop users from entering non-aphanumeric characters or white spaces

Say you want to stop users from entering non-aphanumeric characters or white spaces.

Using regular expressions would be the easiest method:

Here is my javascript code:

<script language="Javascript">
function alphaNumericCheck(){
    var regex=/^[0-9A-Za-z]+$/; //^[a-zA-z]+$/
    if(regex.test(document.add_data.password.value)){
        alert("Good")
        return true;
    } 
    else {
        alert("Please fix: password")
        return false;
    }
}
</script>

For numbers only use /^[0-9]+$/

For mixed text and numbers, with spaces /^[0-9a-zA-Zs]+$/

Here are more useful regular expressions:

[a-zA-Z] any letter
d any number; same as [0-9]
D any NOT number; same as [^0-9]
w any alphanumeric character; same as [a-zA-Z-0-9_]
W any NON-alphanumeric character; same as [^a-zA-Z0-9_]
s any whitespace (tab, space, newline, etc...)
S any NON-whitespace
n newline
t tab

To view a full html sample of the above code click the links below using regular expressions in JavaScript