Routes in laravel

Laravel is having great feature for the nice urls. We can use the controllers and functions for custom urls

ex:

 Route::get('sample/getdata/{id}', array('uses' => 'controllername@functionname')); 

In the above routing concept if we give

 www.sample.com/sample/getdata/25

it will point to the controller function like

class controllername extends BaseController
{
public function functionname($id = null) {

}
}

from the above controller function we can get the id value as parameter
Here we are going to look into the function to get the submitted values inside the controller function

Route::match(array('GET', 'POST'), 'submit/submiturl', array('uses' => 'SubmitController@submitfunction'));

in the above code if  we submitting the values to a url like

http;//www.sample.com/submit/submiturl

and we can get the values in the function submitfunction inside the SubmitController

i.e.,

class SubmitController extends BaseController
{
public function submitfunction() {
$submitedData = Input::get();
}
}
} 

the Input::get(); function is for getting the submitted post value

Here we have to think about another thing.If we are submitting a value to the url which may or may not have the parameter.
For that we have to use the following code

Route::match(array('GET', 'POST'), 'submitted/submitfunction/{id?}', array('uses' => 'SubmitController@submitFunction'));

Redis with laravel

Redis

Redis is an open source, advanced key-value store. Which is mainly using for the cache purpose and its having Strings, Lists, Sets and Hashes datatypes.We can store the data into the redis and we can fetch it when we want to use.

For using the redis first we have to install redis in our system. Please refer the following url for installing redis in the system

Redis installation

Redis in laravel

Laravel is having the support for using the redis with laravel. For that we have to follow the following steps

For establising redis connection first we have to configure the redis in app/config/database.php

i.e.,

 
'redis' => array(
    'cluster' => false,
    'default' => array(
    'host' => '127.0.0.1',
    'port' => 6379,
    ),
 )

In the above configuration the cluster is using for the large data with multiple access. If we are using small amount of data we can assign cluster false. Also redis cluster in alpha stage.

and host we have to mention host to establish redis connection and default port of redis is ‘6379’

For establishing the redis connection. We have to use the following code

Establish redis connection

 
$this->redis = Redis::connection();

Check the redis server availability using Exception Handler

The following code will check whether connection available or not if not it will through the exception error

 
try {
 $this->redis->ping();
 } catch (Exception $e) {
 // exception error
 }

Set redis value

For setting redis value we have to use the following code. If we want to store array values we have to serialise it. Because array is php data type. Redis will not aware of php array variable type

 
$this->redis->set("redis_name", serialize($newArr));

Get redis value

 
$this->redis->get("redis_name");