Saturday 31 October 2015

Adding external js and css file in Laravel 5.1

Adding CSS File :-

<link rel="stylesheet" href="{{URL::asset('assets/css/bootstrap.min.css')}}">

Adding JS File :-

<script type="text/javascript" src="{{URL::asset('assets/js/angular/angular.min.js')}}"></script>

Validate passwords with Laravel 5.1

validate a password using following condition:

1) Password is at least 8 characters long

2) Password should contains at least 1 uppercase, 1 lowercase and 1 special character letter


  $rules = array(
        'username' => 'required',
        'email' => 'required | between:5,100 | email ',
        'password' => 'required | confirmed |regex:/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()+]+.*)[0-9a-zA-Z\w!@#$%^&*()+]{8,}$/'
    );

    $input = Input::all();

    $validation = Validator::make($input, $rules);

    if ($validation->fails()){
        //if validation fails redirect with inputs
        return redirect()->route('/')->withInput()
            ->withErrors($validation);
    }

Remove back button press behaviour of browsers

In most of online examination, developer uses concept of remove browser back button press behaviour, to implements user unable to press browser back button to go previous page .
   This can be acheived using Jquery:-
  This is the code - cheers :)


  window.location.hash="no-back-button";
  window.location.hash="Again-No-back-button";//again because google chrome don't insert first hash into history
  window.onhashchange=function(){
    window.location.hash="";
    history.replaceState('', document.title, window.location.pathname);
  }

  // remove fragment as much as it can go without adding an entry in browser history:
  window.location.replace("#");

  // slice off the remaining '#' in HTML5:    
  if (typeof window.history.replaceState == 'function') {
    history.replaceState({}, '', window.location.href.slice(0, -1));
  }

Add Attachment PHPmailer

PHPmailer Probably the world's most popular code for sending email from PHP! 
$mail->AddAttachment('path_for_pdf', $name = 'Name_of_pdf',  $encoding = 'base64', $type = 'application/pdf');

Adding a Right-click context menu to a webpage

This is the code by which users can add customize right click context menu to web page.