Rapid or fast development in Sublime Text 3

We, developers like to write codes, but what if you need to write 1000000000 lines of code?
Let me know your answer on comment 😉

Here comes snippet, What is snippet?
Snippet a small piece or brief extract. it’s a brunch of code that is generate by shortcut key.

Now we know create some snippets for faster our development time. And we need function every where, so we will create a snippet, that we dont need to write same code again and again

Step-1: Open Subline
Step-2:Tools > Developer > New Snippet, Now you will get a file like this

Step-3: Update the codes with below codes

Look at the underline area the function is public and we use ${1} and ${2}. what does it mean?

Continue….

Advertisements

External API calling in Laravel by Guzzle Package

Recently I am working on a project that need to access some external API. And it’s a Laravel project, so I am looking for some package that can save my time and meet the deadline too.

 

I am using GuzzleHttp package for accessing external API and its really easy

 

Installation:

composer require guzzlehttp/guzzle:~6.0

Uses:
on your controller file just put before your class ClassName

use GuzzleHttp\Client;

 

Now call this Guzzle Client in your method

//create an instance of Client wiht base url of the API

$client = new Client(['base_uri' => 'http:127.0.0.1/path/to/api/']);

// Send a GET request to http:127.0.0.1/path/to/api/ 
// and method name is apiName 
// with api authentication (username and password)
$response = $client->request('GET', apiName', [
                 'auth' => ['username', 'password']
                 ]);

// check the response by

dd($response);

// Get the response status code

dd($response->getStatusCode());

// Get the response phase
dd($response->getReasonPhrase());

// Get all/full header
dd($response->getHeaders());

// Get specific specific entity of header, 
// here we retrive content-type
dd($response->getHeader('content-type'));

// Get api content. it return the main content the we need

dd($response->getBody()->getContents());

 

this post will continue as i go with this Guzzle package..

 

Repository – https://github.com/guzzle/guzzle

and here is the main document – http://docs.guzzlephp.org/en/latest/

 

Laravel: php artisan commands

Here I am trying to list all Laravel PHP Artisan commands one by one for my reference and your too.

 

– To create and update table by migration

php artisan make:migration Create_Table_Name  -> create a new table

php artisan make:migration Update_Table_Name_Column_Name -> update table

php artisan make:migration Add_Column_Name_Table_Name  -> add a new column to a table

 

– To create a Controller

php artisan make:controller pathControllerName –resource

path = directory/place of the controller, i usually create controller directory wise . i.e.: site/SiteController – all site related controller will store here and admin/AdminController – all admin related controller will store here or test/TestController – all test related controller will store here.

ControllerName = Name of the controller

–resource = a parameter to create controller with default CRUD functions (index, create, store, show, edit, update, destroy)

 

– To create a Model

php artisan make:model pathModelName

path = directory/place of the model (optional). Same as controller

ControllerName = Name of the model

 

Update – Please visit skpaul.me for latest posts and updates

skpaul.me

Hi,

Greetings!!

Thanks for visiting my blog, I have open a blog (http://skpaul.me). So from now, you will get all latest posts and updates on http://skpaul.me.

 

Please take a look on my personal blog (http://skpaul.me), and let me know your comments and review.

 

Thanks in Advance

sk paul

http://skpaul.me

How to define Global Variable or Constant in Laravel

We often need to define global variables/constants for our application, like Status, Conditions, Countries (we can put all countries in table as it will be along array/object), also weekdays, weekends and e.t.c. vary on projects.

Status (Active, Inactive) and Conditions (Ok, Good, Better, Best) or Grade (F, C, D, A, A-, A+), so like these type of variables/constants,  we write same code multiple times. But if we set all of these as Global Variables then we can use these anytime, anywhere in application.

 

 

And here I am presenting how to define GLOBAL Variable/Constant in Laravel 5.2. (This is not the only way, but I like it)

  1. First create a file named constants.php on config directory
  2. And code some variables like below

return [

‘STATUS’ => [

1 => ‘Active’,

0 => ‘Inactive’

],

‘Conditions’ => [

1 => ‘Ok’,

2 => ‘Good,

3 => ‘Better,

4 => ‘Best’

 

],

‘GRADE’ => [

‘A+’ => ‘A+’,

‘A’ => ‘A’,

‘A-’ => ‘A-’,

‘B’ => ‘B’,

‘C’ => ‘C’,

‘D’ => ‘D’,

‘F’ => ‘F’

]

];

  1. Now, how can we use/access this Global Variables? Very easy, and we can also access these variables on view too.

Config::get(‘constants. STATUS’); // it will output status array.

Or, if we want a specific one element then

Config::get(‘constants. GRADE.F’); // output: F

  1. And lastly we can also set Global variable only for the current request. This will not persist.

Config::set(‘constants. Conditions.5’, ‘Not Stable’)

 

And finally – if you like this article please inspire me by posting a comment (at below) for the next article 😉 . And I don’t mind if you want to share among with your friends, bocz. Sharing’s Caring.

 

Credit: google, stackoverflow, Laravel.io, Laravel docs and etc.

Update (custom) XAMPP/WAMP/LAMP default landing page layout

We are building website and applications on localhost and I use XAMPP package on Linux for my local development.
Screenshot from 2015-10-07 20:20:51

 

After installing Xampp, we always get a default home page from Xampp and most of the time we don’t need that. Basically before writing this article I always delete all items of htdocs/www folder, but sometimes we need to know things like versions and if functions are enable or not and also the limits various variables. So by using the below script you can easily get a good view of your localhost’s projects (as a list) and as well as databases from phpmyadmin. And you dont need to delete anything on htdocs folder and get all thing whenever you need.

 

In the header put this css code into the style tag for a better view

 

body {

background: #fcfcfc;

color: #111;

font-family: verdana, sans-serif;

padding: 0;

margin: 0;

}

#main {

width: 100%;

position: relative;

}

.container {

padding: 1em;

}

#menu { float: left; width: 24%;  }

#menu ul { padding: 0; border-right: 3px solid white; margin: 0; }

ul li { list-style-type: none; }

ul li a {

display: block;

background: #eee;

padding: 4px 7px;

border-top: 2px solid #fff;

}

ul li a:hover {

background: #B6C6D7;

color: black;

}

iframe {

border: 0 none;

overflow: hidden;

width: 74%;

height: 95%;

padding-left: 1%;

}

.clear-block {

width: 100%;

height: 1px;

clear: both;

}

Add this css file for a look like phpmyadmin

<link rel=”stylesheet” type=”text/css” href=”phpmyadmin/phpmyadmin.css.php”></script>

 

Put this code into the body

</div>

</div>

Now you are done 🙂 . And save this file as index.php at htdocs

Or download from here

 

 

Update: 07.10.2015

If there is issue of viewing your phpmyadmin, here is the solution. You just need to add an extra line to allow the third party framing on your phpmyadmin/config.inc.php file.

$cfg[‘AllowThirdPartyFraming’] = true;

 

Laravel 5.1: Unsupported operand types (FatalErrorException in …)

Ok. When I am upgrading my application from Laravel 5.0 to 5.1 I get an falat error that this showing “Unsupported operand types”

 

What did I do on Laravel 5.0:

I add two array with in + operator, and that is the problem. So, I looking for solution and get this on Laracast

$item_list = array(”=>’–Select–‘) + Model::lists(‘name’, ‘id’);

what do I do on Laravel 5.1

this is a quick fix: just add another function at the end of the line ( and just before of the ; )  ->toArray()

so, here is the updated code

$item_list = array(”=>’–Select–‘) + Model::lists(‘name’, ‘id’)->toArray();

 

Why this: the reason for this update.

In 5.1, in Colleciton.php, it uses this:

return new static(Arr::pluck($this->items, $value, $key));

instead of this:

return array_pluck($this->items, $value, $key);

which, in turn does this:

return (Arr::pluck($this->items, $value, $key));

So it looks like the new behavior is to return a collection vs an array, thus the need to specify the toArray()

 

credit: @scottlaurent