Page 2 of 3

Global Config values In Laravel

Today I want to create a page for sending contact us mail in site,

For that I have to define admin mail id and admin name as a config value and i want to access the same in same in many  places,

I had googled for some time , to find out how can i define my constant in laravel and one of my friend (Ranjith) help to do that ,

Here i am writing how we can use a  Config values   in laravel,

1. If we want to define all our constants in a custom page ,

We can create a page (Here i am calling constants.php )
and inside that we can define like key value pair

return array(
 'custome_name' =>'custome_value',
)

And we call the values as below

$cvalue = Config::get('filename.custome_name');

Here we will get our custom_value in $cvalue

Let us look an example

<?php

return array(

    'admin_email' =>'mail@shabeebk.com',
    'admin_name' =>'Admin',
  

);
?>

Now let us see How we can retrieve the config in your code somewhere

echo  Config::get('constants.admin_email');
echo  Config::get('constants.admin_name')

Hope it will help some one 🙂

Thank you Ranjith

I made small changes,

thank you Martin Tonev for correcting from variable to config

9,905 total views, 3 views today

Install Constant Contact in Laravel

To setup an option for newsletter signup with Constant Contact and Laravel Framework

  1. Install PHP5 Curl using the below command
    sudo apt-get install php5-curl
    
  2. Add the below code in composer.json
    "require": {
               "laravel/framework": "4.2.*",
               "curl/curl": "1.2.*",
               "constantcontact/constantcontact": "1.2.*"
    	},
    
  3. Run the below command to install constant contact in laravel
    composer update
    

     

1,303 total views, no views today

How to install Laravel in MAMP-MAC

Today i was trying to install laravel in MAMP , While going through their step on laravel site mentioned i found that i didn installed mycript extension. I had googled for lot of time and lastly i installed .

I am writing this will help some one to install laravel in Mac using MAMP.

Install composer

Before installing laravel we have to install composer . We can go to https://getcomposer.org/ and we can install from from there or we can follow the following steps step

1. first we have to check curl is enabled . step 2. we can install composer globally as mentioned in their site

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

Install Laravel 

1.once we installed composer we have to move to htdocs and to our directory from our terminal

cd /directory/folder

2. We can tell composer to download laravel  and install by following commands

composer global require "laravel/installer=~1.1"
composer create-project laravel/laravel your-project-name --prefer-dist

And here it will come to as for mycrypt extension .

Mcrypt PHP extension required.

To solve this issue we have to check the php version frist

php -v

shabeebk.com-php-version-check

   3.Now let us have our PHP version, in my case 5.6.2, we can open our .bash_profile script

nano .bash_profile

4. Add our MAMP PHP version after the code already present ,Exit the file and Save   it.

export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.10/bin
export PATH="$MAMP_PHP:$PATH"

5. Now we can try to install Laravel  again That is it!.

composer create-project laravel/laravel your-project-name --prefer-dist

 

6. We can see Laravel is downloading and installing

laraval-install-mac_1

laraval-install-2

laraval-install-3

laraval-install-4

  Finally it will show like installed. Application key (*******) installed successfully.

 

Now let us go to browser and check the URL.

Screen Shot 2014-12-25 at 9.56.18 pm

That is it!

 

 

 

6,101 total views, 1 views today

jquery scrollTop – with animation

The jquery scrolltop () method gets the top offset of the first matched element.

Let us have a look,

If we want to know vertical scroll postion of current window we can use,

scroll_leng= $(window).scrollTop();

It will return the vertical scrollbar position of corresponding to window.

like the same we can set the vertical scrollbar position of window into some postion as below

 $(window).scrollTop(position);

If we want to know vertical scroll postion of a perticular element window we can use,

scroll_leng= $(selector).scrollTop();

It will return the vertical scrollbar position of particular element.

like the same we can set the vertical scrollbar position of particular element into some postion as below

 $(selector).scrollTop(position);

Sometime we have to give animation also , it is simple by using animate function in jquery

$(selector).animate({scrollTop: scroll_value}, delay);

sample demo below:




Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.



0 px

Now Let us look a demo with window object ,
Enter a value to scroll top


Now letus look scrollTo with animations

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.



0 px

Now Let us look a demo with window object animated ,
Enter a value to scroll top


768 total views, no views today

Hidden Features in Mac

Today i saw some interesting hidden features in Mac, Which most of them not using. Here i am giving which i like to use with short keywords.

mac_features

-Take a Full screenshot

You can holding down command + shift + 3 to take the complete screenshot of your mac

if you want to save it copy board, can holding down command + ctrl + shift + 3

– Part of screen
For taking screenshot of a special part of screen you can holding down command + shift + 4 Then cursor will change to + and can drag where you want to take screenshot. It will be saved in folder (Desktop by default).

if you want to save it copy board, can holding down command + ctrl + shift + 4

– Spotlight search
you can holding down Command + Spacebar to show Spotlight search, type and search on your mac an internet.

– Apple symbol

On any Apple computer, you can create an Apple icon by holding down Option + Shift + K, It will create a apple symbol like this  😉

apple_symbol

Apple_symbol from mac

– Built-in Mac emoticons

On mac we can use emoticons by simply holding down ctrl+⌘+space . it will appear a box of emoticions.

mac-emotions

mac-emotions

– Quick preview with spacebar

We can quick preview any file by selecting the file and pressing the spacebar. Press the space agin it will auto close. On menu you can see compatible apple also .

Mac is awesome 😉

1,370 total views, no views today

Regular expression for at least one number capital letter and a special character


Here we are going to write a regular exprestion for Password to check the condition like , password must contain at least one number,one capital letter and one special character.

First we can write Regex as below,

^(((.*\d.*[A-Z].*[!@#$%^&amp;*? ~].*))|(.*[A-Z].*\d.*[!@#$%^&amp;*? ~].*)|(.*[!@#$%^&amp;*? ~].*[A-Z].*\d.*)|(.*[!@#$%^&amp;*? ~].*\d.*[A-Z].*))$

This will check the string contain at at least one number,one capital letter and one special character,

Here i am going to show examples with Javascript function ,

We can write a function in javascript as below

 function validatePassword(str)
            {
                // patter to match : Atleast one number ,one capital letter, one special charector
                var reg = /^(((.*\d.*[A-Z].*[!@#$%^&amp;amp;*? ~].*))|(.*[A-Z].*\d.*[!@#$%^&amp;amp;*? ~].*)|(.*[!@#$%^&amp;amp;*? ~].*[A-Z].*\d.*)|(.*[!@#$%^&amp;amp;*? ~].*\d.*[A-Z].*))$/;
                if (reg.test(str)) {
                    return true;                                     
                }
                else {
                    return false;                  
                }
            }

and we can pass the string as function argument “str”, It will return if it matches the condition else it will return false.

Let us look on the demo

Javascript function sample

Enter password :


Let us look a jquery demo

Jquery sample

Enter password :


You can download from github

Have a noce day 😉

2,311 total views, 2 views today

How to add integer only in a text field using jquery


To allow integer only in text field we can use the following jquery function .
We can write below code inside a document.ready function and give the class “integer-allowed” for the text box we needed.


 $('.integer-allowed').keyup(function () {
                            this.value = this.value.replace(/[^0-9\.]/g, '');
                            }); 

Working demo


Enter value (Numbers only allowed)

Working code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
 <script  type="text/javascript">
$(document).ready(function() {
   $('.integer-allowed').keyup(function () {
          this.value = this.value.replace(/[^0-9\.]/g, '');
       });
});
</script>


<strong>Enter value (Numbers only allowed)</strong><br />
<input type="text" class="integer-allowed" name="demoname" /><br />
<input type="submit" class="" name="demosubmit" />

872 total views, 1 views today

Ignore files from git without .gitingore

We can remove tracking of git for some file using below comment .

git update-index --assume-unchanged <file full path>

To track the file again we can use below comment

git update-index --no-assume-unchanged <file  full path>

Now let us look How we can list all the files who is included in no-assume

We can type below comment in terminal

git ls-files -v

It will list like

H file 1
H file 2
h file 3
h file 4

Here we can see first character as capital or lower for some file.

If the first character is lowercase, it is marked as “assume unchanged”, else it is marked as “assume changed”

We can simply list all the “assume unchanged”files using below comment.

git ls-files -v | egrep -r "^h .*"

it will list only “assume unchanged” file list

Example

h file 3
h file 4

1,044 total views, 2 views today

How to use crone jobs from Cpanel


Hello gays,

Here i am writing how we can runcrone job on cpanel.

1. First go to cpanl->cron job tab.

cronjob1

2. Then we can see a screen like below .

cronjob2

3. We can set the time either from Common Settings or set each and every fields as we want.

4. Finaly we want to write command to run as below.

/usr/bin/curl --user-agent cPanel-Cronn http://domainname.com/page.php/parameters

That is it
😉

538 total views, no views today

Force download file php


Hi,

Today we are going to learn about force downloading prompt in PHP.

While i am doing my projects, i had a requirement for file download, File type will be changed, So i made a research on this and made simple useful script which can be use any where to prompt download by giving path and file name . Let us create a function download_file and pass full file path and filename , we can use third argument to mention the MIME Type of file

download_file($sourceFile, $fileName, $mime_type = '') 

Next we can check whether we have permission to read the file.if not it will return 404 error

 if (!is_readable($sourceFile)) {
        header("HTTP/1.1 404 Not Found");
        return;
    }

Now we are going to create an array of list of mime types. so we can compare with this array and set correct header content type

 $mime_types_list = array(
        "gif" => "image/gif",
        "png" => "image/png",
        "jpeg" => "image/jpg",
        "jpg" => "image/jpg",
        "pdf" => "application/pdf",
        "csv" => "application/csv",
        "txt" => "text/plain",
        "html" => "text/html",
        "htm" => "text/html",
        "exe" => "application/octet-stream",
        "zip" => "application/zip",
        "doc" => "application/msword",
        "xls" => "application/vnd.ms-excel",
        "ppt" => "application/vnd.ms-powerpoint",
        "php" => "text/plain"
    );

Next we are going to set mime type if we already pass the MIME type into function it will take that MIME ,else we are going to use a function pathinfo to retrieve the extension of file and we will compare with already created array to get content type

 $path_parts = pathinfo($sourceFile); //pathinfo 



    if ($mime_type == '') {

        $file_extension = $path_parts['extension'];
        if (array_key_exists($file_extension, $mime_types_list)) {
            $mime_type = $mime_types_list[$file_extension];
        } else {
            $mime_type = "application/force-download";
        };
    };

After that we will clean and start the output buffer

  @ob_end_clean();

Then we can set the content type and headers

if (ini_get('zlib.output_compression'))
        ini_set('zlib.output_compression', 'Off');

    header('Content-Type: ' . $mime_type);
    header('Content-Disposition: attachment; filename="' . $fileName . '"');
    header("Content-Transfer-Encoding: binary");
    header('Accept-Ranges: bytes');
    header("Cache-control: private");
    header('Pragma: private');

lastly we are going to read each line by line and print that as shown below.

$chunksize = 1 * (1024 * 1024);
    $bytes_send = 0;
    if ($sourceFile = fopen($sourceFile, 'r')) {


        while (!feof($sourceFile) &&
        (!connection_aborted())
        ) {
            $buffer = fread($sourceFile, $chunksize);
            print($buffer); // is also possible
            flush();
        }
        fclose($sourceFile);
    } else {
        header("HTTP/1.1 505 Internal server error");
        return;
    }

That is it !!!!! Now we can have a look, How we can read the file using created function We can make a path file and the name we want to give while downloading and pass to function . It will download prompt for file. example for reading file and download prompt

$filepath = 'sample.pdf';
$filename = 'sample.pdf';

download_file($filepath, $filename);
exit;
?>

Full code

<?php

/**
 * function to download a file from server
 * 
 * list all the values in grid
 * 
 * @auther Shabeeb  <me@blog.shabeebk.com >
 * @createdon   : 06-08-2014
 * @
 * 
 * @param source $sourceFile : file pathe 
 * @param source $fileName : file name for download 
 * @param source $mime_type : MIME type optional field
 * @return type
 * exceptions
 * 
 * 
 */
function download_file($sourceFile, $fileName, $mime_type = '') {

    if (!is_readable($sourceFile)) {
        header("HTTP/1.1 404 Not Found");
        return;
    }

    $size = filesize($sourceFile);
    $fileName = rawurldecode($fileName);


    $mime_types_list = array(
        "gif" => "image/gif",
        "png" => "image/png",
        "jpeg" => "image/jpg",
        "jpg" => "image/jpg",
        "pdf" => "application/pdf",
        "csv" => "application/csv",
        "txt" => "text/plain",
        "html" => "text/html",
        "htm" => "text/html",
        "exe" => "application/octet-stream",
        "zip" => "application/zip",
        "doc" => "application/msword",
        "xls" => "application/vnd.ms-excel",
        "ppt" => "application/vnd.ms-powerpoint",
        "php" => "text/plain"
    );

    $path_parts = pathinfo($sourceFile); //pathinfo 



    if ($mime_type == '') {

        $file_extension = $path_parts['extension'];
        if (array_key_exists($file_extension, $mime_types_list)) {
            $mime_type = $mime_types_list[$file_extension];
        } else {
            $mime_type = "application/force-download";
        };
    };

    @ob_end_clean();

    // if IE, otherwise Content-Disposition ignored
    if (ini_get('zlib.output_compression'))
        ini_set('zlib.output_compression', 'Off');

    header('Content-Type: ' . $mime_type);
    header('Content-Disposition: attachment; filename="' . $fileName . '"');
    header("Content-Transfer-Encoding: binary");
    header('Accept-Ranges: bytes');
    header("Cache-control: private");
    header('Pragma: private');


    $chunksize = 1 * (1024 * 1024);
    $bytes_send = 0;
    if ($sourceFile = fopen($sourceFile, 'r')) {


        while (!feof($sourceFile) &&
        (!connection_aborted())
        ) {
            $buffer = fread($sourceFile, $chunksize);
            print($buffer); // is also possible
            flush();
        }
        fclose($sourceFile);
    } else {
        header("HTTP/1.1 505 Internal server error");
        return;
    }

    die();
}

$filepath = 'sample.pdf';
$filename = 'sample.pdf';

download_file($filepath, $filename);
exit;
?>

Download the source

809 total views, 2 views today

© 2017 shabeeb Blog

Theme by Anders NorénUp ↑