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.

Multiple sessions or Different logins at the same time on firefox

Multifox – is an awesome and very useful plugin for me. If you need to login multiple accounts at the same time, what did we do naturally, we used multiple browsers. But with this plugin on Firefox, you can access as many accounts as you want.

Mozilla Addons link -> click here

But if your browser’s version doesn’t support the plugin, you can try here with an old version from their website Getmultifox.com

For details and getting started check here

 

N.B.: Chrome already have this feature builtin on Settings > People > Add preson

How to find a column or filed name of a table from an entire database?

If you are working on a BIG project with lots of tables in the database, then it will be a good trick query for you to find out a column name of any table from that database.

 

My scenario was a bit different, I had to start work in the middle of a project and there was no one to guide/help me regarding  anything. And you know, about the deadline… really messed up. So, I didn’t hopeless and as usual did some google and prepare this query.

 

“SELECT TABLE_NAME, COLUMN_NAME

FROM INFORMATION_SCHEMA.COLUMNS

WHERE column_name LIKE ‘your_column_name’ “

 

As you can see it search information schema for the column name you are finding after the LIKE clause. And this query saved me and my ass 😉

 

I am writing this article for my future reference. Hope it will also help you and save your ass too 😉 as like mine. If this article save your time then you can comment and share this article to save others too. [sharing is caring]

 

 

[Note: May be you can find this query on other sites. As I said I did some google and make for me. Sorry forgot those site otherwise I put those on ref. section like my other post.]

How to print query or debug queries in Laravel

We often need to debug large queries in Laravel. And laravel have built-in functions almost for everything. Here is a simple query in laravel for example.

$data = User::where(‘status’, 1)

->select(‘name’, ‘username’, ‘email’, ‘password’)

->get();

 

but we want to see the sql query. So we have to use toSql() in the place of get() and to print the query we use dd() – die and dump function of laravel, so here is out update query

$data = User::where(‘status’, 1)

->select(‘name’, ‘username’, ‘email’, ‘password’)

// ->get()

->toSql();

And dump it

dd($data);

and the output is

“SELECT ‘name’, ‘username’, ‘email’, ‘password’ FROM user WEHRE status = 1”

 

n.b.: it also can be done by DB listen

DB::listen(function($sql) {

var_dump($sql);

});

 

Here is another option with Laravel DebugBar. It’s a full featured package and gives lots on insight of the application.

 

 

——————————————————————

Reff: https://scotch.io/tutorials/debugging-queries-in-laravel

 

Sublime Text Editor – User Preference Setting

If you working in any editor, you would like to set the environment as you want. And in Sublime Text you can set your preferences in a easy way.

– Go to Preferences > Settings – User  and put the below preferences. You can also tweak the settings by blocking/unblocking the setting by double front slash (//) and see the magic 🙂

**keep all settings within curly brackets. And here is my settings 😉

{
“bold_folder_labels”: true, // set the sidebar’s folder name to bold
“caret_style”: “phase”,
“wide_caret”: true, // set the cursor
“color_scheme”: “Packages/User/SublimeLinter/Monokai (SL).tmTheme”,
“fade_fold_buttons”: false,
“font_size”: 11, // set font size of the editor
“tab_size”: 4, // set the tab size to 4 space
“highlight_line”: true, // highlight the line
“highlight_modified_tabs”: true, // highlight the (file) tab if the file is modify/edit
“ignored_packages”:
[

// ignore packages going here
//”Vintage”
],
“line_padding_bottom”: 1, // set the bottom padding of each line
“line_padding_top”: 1, // set the top padding of each line
“word_wrap”: true // set the word wrapper to true to stop horizontal scrolling
}

Let me know your settings in comment.

WordPress or WooCommerce user manual on adding categories and products

How to add Categories?
———————-
Mouse Hover Product
Click on the Category, you will get a form
Just fill up teh below fields
– Name: Type the category name
– Slug: no need to fill it, leave it
– Parent: Select is your category is a sub category> Otherwise leave it.
– Description: Type a little intro about the category if you have, or leave it.
– Display type: No Need, Leave It
– Thumbnail: Click on the “Upload/Add image” button, Upload a image and add that image.

Click on the “Add New Product Category” button and
you are done.Check the list on the right.

How to add author?
————————-
Mouse Hover Product
Click on the Author, you will get a form
Just fill up the below fileds
– Name: Type the author name
– Slug: no need to fill it, leave it
– Description: Type a little intro about the Author if you have, or leave it.
Click on the “Add New Author” button and
you are done. Check the list on the right.

 

How to add Products?

—————————
Mouse Hover Product
Click on the Add Product, you will get a form
Just fill up the below fileds
– Product Name: Type the book name
– Below Product name there is a large text area. Enter here all information of the book.
– Product Short Description: Enter short description of the book.
– Product Data: No Need to fill anything here, Leave this secion
– Custom Fields: No Need to fill anything here, Leave this secion
– Author: “Choose from the most used authors”by clicking this link you will get all enlsted authors, just click on the author name or write and add if there is a new author
– Product Categories: Select category from this section
– Featured Image: Set a Image from here
– Product Tags: No need, leave it
– Product Gallery: No need, leave it

Now scroll up and hit the “Publish” Button and
You are done. Check the Products > Products (left menu) and also on the website.

Photoshop like interface(Shortcuts & Icons) of GIMP on Ubuntu/Linux

I was a windows user and recently transfer to Linux (Ubuntu). I try GIMP on Ubuntu as an alternative of Photoshop, but facing some issues, bcoz the interface is not exactly like Photoshop and I need a quick solution. So, I google and find a GIMP Photoshop Tweaks and here it is..

and Here is the process how can you change your GIMP  default interface like Photoshop

0. Close GIMP, if it is open.
1. Download the Tweak File from Here
2. Keep a backup of your present GIMP configuration.
– just type below command on your terminal

mv ~/.gimp-2.8 ~/.gimp-2.8.backup

OR
– Go to the Home folder and press Ctrl+H (to view hidden files & folders).
– Find the folder named .gimp-2.8
– Rename .gimp-2.8 to .gimp-2.8.backup or wahtever you want

3. Extract the downloaded zip file in your Home folder. You will get a hidden folder named .gimp-2.8 with new configuration like Photoshop. (Press Ctrl+H to see the hidden folders/files.)
4. Now Open the GIMP and check out the toolbox, right side panel and interface..
5. If you are done and everything ok, then do a comment here and share this article, bcoz sharing is caring :p

 

N.B.: And if you don’t like/need Photoshop Like interface and want to roll back to the default GIMP Interface just type below command on your terminal

rm -r ~/.gimp-2.8

mv ~/.gimp-2.8.backup ~/.gimp-2.8

 

Thanks 🙂

#HappyLinuxing
#doWorkCreateNetwork

 

 

ref: doctormo.deviantart.com