What’s New in Laravel 5.5

Laravel 5.5 is scheduled to be released in August of 2017 and is slated for the next major release.

Below are the few useful links, which will have all the latest features and improvements in Laravel 5.5

Happy Learning!

 

Roadmap To Learn PHP & Laravel

Recently, I got an opportunity to train new joiners at the Cygnet Infotech. And I found this very helpful blog post related to that.

Roadmap To Learn PHP & Laravel

Thanks to  @introwit for the blog post.

This roadmap lists the complete course from step 1 to the end that will help a beginner learn PHP in the correct order right from scratch understanding almost all aspects of the language.

To be up to date with Laravel, you can follow top 15 Laravel Heros. You will learn many tips and tricks which will helpful into your day to day development.

If you are ever stuck somewhere while learning, hit me up on twitter at @solaniviral and I will be glad to help you.

Happy Learning!

Laravel : Best Practices

There are Many PHP Frameworks Available And I’ve worked with Zend, CakePHP, CodeIgniter then I picked up Laravel in 2014 and with version 4.2. Trust me, I totally love it now.

Speaking about Laravel, it is simple and comfortable to use, suitable to start with writing the production code, and gives a great boost to a development process. One thing that I love about Laravel is that it’s built using the best practices used in programming available in the current times.

Here are some simple things worth having in mind when developing in Laravel:

  • Try to make use of your .env file to the max you can.
  • Don’t create tables or index directly via PHPMyAdmin or console. Use Database Migration to create table, add/alter any fields, and commit those to Git repository.
  • Don’t insert fake values directly into the database for testing purposes. Create Seeder files or user Model Factory to populate your database.
  • Prefer to use Artisan CLI more than manually creating stuff, it’ll fasten up your productivity.
  • Make sure to boost performance using some artisan commands:
    php artisan route:cache
    php artisan config:cache
    php artisan optimize — force
  • Try not to write closures into your routes.php file, instead move them to your controller.
  • Use Named based Routing.
  • Be careful with the naming conventions when creating custom classes and functions, especially with your Models. Laravel works on a principle such that, for a table named users, it would expect it’s model name to be User.
  • Try to make Validation Requests separately for each request.
  • Although PHP has a class named DateTime to help you when reading, writing, comparing or calculating with date and time. It is recommended that you use the Carbon Library for dealing with dates.
  • Always keep yourself updated with the latest version, Laravel is updating real fast, so keep up the pace.
  • Always use gulp, Laravel Mix for compiling your scripts and sass into minified version for better performance, Laravel did the basic housekeeping for you.

Feel free to add more to the list…

How to replace plain URLs with links in JavaScript or PHP?

Hello Friends

If you want to convert plain text in to URLs in JavaScript or PHP. This is good solution for you.

In PHP :

public function makeLinks($str)
{
    $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
    $urls = array();
    $urlsToReplace = array();
    if(preg_match_all($reg_exUrl, $str, $urls)) {
        $numOfMatches = count($urls[0]);
        $numOfUrlsToReplace = 0;
        for($i=0; $i<$numOfMatches; $i++) {
            $alreadyAdded = false;
            $numOfUrlsToReplace = count($urlsToReplace);
            for($j=0; $j<$numOfUrlsToReplace; $j++) {
                if($urlsToReplace[$j] == $urls[0][$i]) {
                    $alreadyAdded = true;
                }
            }
            if(!$alreadyAdded) {
                array_push($urlsToReplace, $urls[0][$i]);
            }
        }
        $numOfUrlsToReplace = count($urlsToReplace);
        for($i=0; $i<$numOfUrlsToReplace; $i++) {
            $str = str_replace($urlsToReplace[$i], "<a target='_balnk' href=\"".$urlsToReplace[$i]."\">".$urlsToReplace[$i]."</a> ", $str);
        }
        return $str;
    } else {
        return $str;
    }
}

In JavaScript

function makeLinks(text) {
 var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
 return text.replace(exp,"<a target='_blank' href='$1'>$1</a>");
}

Hope it helps.

Set php.ini Values Using .htaccess

Did you know that you can set php.ini values right inside the .htaccess file? It’s actually very easy.

The .htaccess Code

#format
php_value setting_name setting_value#example
php_value  upload_max_filesize  10M

Of course you could simply place these in the .htaccess file, but .htaccess is a viable alternative if your host doesn’t allow you to touch the php.ini file.

Resource :

http://davidwalsh.name/php-values-htaccess

Prevent Your CSS and JavaScript Files From Being Cached

Some websites use highly volatile, oft-changing CSS and JavaScript files. In the case of these files, it’s important that the developer prevent browsers from caching them. How do we do that? By using a phantom querystring, of course. We’ll use PHP to tack the current time onto the file reference.

The PHP

<link href="/stylesheet.css?<?php echo time(); ?>" rel="stylesheet" type="text/css" >
<-- RENDERS -->
<link href="/stylesheet.css?1234567890" rel="stylesheet" type="text/css">

<script type="text/javascript" src="/site-script.js?<?php echo time(); ?>"></script>
<-- RENDERS -->
<script type="text/javascript" src="/site-script.js?1234567890"></script>

It’s a very simple technique and doesn’t affect your CSS or JavaScript code in any way.

Resource :

http://davidwalsh.name/prevent-cache

Android Detection with JavaScript or PHP

Hello Friends

You have a web application and you want to detect that if your Application is opened from android device than it will be redirect to any other URL that will be Android compatible.This is a good solution for you.

What’s obvious is that Android development is a hot topic that will only grow. Here are a few methods by which you can detect iOS‘ main competitor: Android.

The JavaScript

Searching the user agent string for “Android” is the quickest method:

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid)
{
// Do something! // Redirect to Android-site? window.location = 'http://android.viralsolani.co';
}

The PHP

Again, we’ll use PHP’s strstr function to search for Android in the user agent:

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if(stripos($ua,'android') !== false){// && stripos($ua,'mobile') !== false) {
header('Location: http://android.viralsolani.co');
exit();
}

Bonus! .htaccess Detection

We can even use .htaccess directives to detect and react to Android devices!

RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
 RewriteRule ^(.*)$ http://android.viralsolani.co [R=301]

And there you have it: three different Android device detection! Have fun with your mobile development!

Resource :

http://davidwalsh.name/detect-android

Thanks