Null coalescing operator in PHP 7

Let us consider a code of checking the age first. It checks whether the ‘age’ is given in the form or not. If it’s not given, then it says ‘not mentioned’. When it’s given it just spits out the age. Very basic thing we normally did when php 7 had not come.

$age = isset($_GET['age']) ? $_GET['age'] : 'not mentioned';

var_dump($age);

As usual it’ll give an output of – ‘not mentioned.’ Now we write this code with the age given.

Continue reading “Null coalescing operator in PHP 7”

Advertisements

Adapter pattern in php

Can we Adapt SMS into MAIL?
Now we’re going to do an impossible task.
Are you prepared?
Can we start?
This chapter is about the adapter pattern. It’s one of the design patterns that you’re currently on. Let us start with a real world example.
You know that internet connection is absolutely necessary for sending emails. Is it true in the real world? You’d say, well, I know that. An internet networking is a must.

Continue reading “Adapter pattern in php”

Chain of responsibility design pattern in php

Let us see how Responsibility can be Unchained!
In object-oriented design, the chain-of-responsibility pattern belongs to behavioral design patterns segment. The simplest example contains a person using ATM. He’s entering pin, receiving payment and receipts etcetera.
What is behavioral design pattern? They are a type of design patterns that generally identify communicating objects.
You may ask, what kind of objects we’re talking about? These objects have common communication patterns between them. While communicating they must realize that patterns.

Continue reading “Chain of responsibility design pattern in php”

Forms in Laravel 5.3

To fill up the forms, you need to feel the forms first. Since laravel 5.2.45 this feeling is little bit different. It’s become little bit tricky.
You need to install HTML form builder so that you can use laravel form blade template and it’s really important for security reasons. But, there is a seize. Since laravel 5.2.45 the old trick will not work. You can no longer use ‘composer require illuminate/html’ command to add form builder templates to your project. Instead, you have to issue this command:

sudo composer require laravelcollective/html

It’ll take few minutes for composer to update your system. Next it’ll search for ‘providers’ and ‘aliases’. So you must open ‘Code/test/blog/config/app.php’ file and this line inside ‘providers’ array.


//Code/test/blog/config/app.php
'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        …
        'Collective\Html\HtmlServiceProvider',
…
        ],

Continue reading “Forms in Laravel 5.3”

Routing in Laravel 5.3

Routing, a Static Method


Routing is the concept of setting up a new URI like http://localhost:8000/hello. It will take you to a destination web page. Laravel makes it extremely simple. It’s a static method that accepts two things: an URI and an anonymous function or Closure.
In the ‘app/Http/routes.php’ it’s been defined primarily. Start your favorite text editor and open the file. What you see?
You see some code like this:

Route::get('/', function () {
return view('welcome');
});

Continue reading “Routing in Laravel 5.3”

Composer Revolution in PHP

Composer is a dependency management tool in PHP. For any PHP project you need to use your library of codes. Composer easily manages that task on your behalf helping you to declare those codes. You can also install or update any code in your library through composer. Please visit https://getcomposer.org for more details.
In the opening page of https://getcomposer.org, click the ‘getting started’ link.

composer home page

composer home page


In the above page you find two links – ‘locally’ and ‘globally’. It stands for two options. Suppose you don’t want to run composer globally or centrally in your system. In that case, you have to download and install composer each time for every project. But the global option is always preferable because once composer is installed in your system bin folder you can call it any time for any project.

Continue reading “Composer Revolution in PHP”

Environment in Laravel 5.3

Laravel comes with many stunning features. One of them is definitely database migrations. In the next chapter we’ll discuss about migration in detail.
Before that we need to understand our environment properly. What is environment in Laravel? If you look at the document root you will find an ‘.env’ file. It basically says about the database connections. Where would we get that default database set up file? In the ‘config’ folder, we have a ‘database.php’ file. Open it up and see the content.

Continue reading “Environment in Laravel 5.3”