How to search JSON data in MySQL?

If you have JSON type columns in your database and want to run query on JSON type field. You can use the following query.

SELECT JSON_EXTRACT('<json_column>', "$.response") AS name
FROM table
WHERE JSON_EXTRACT('<json_column>', "$.id") > 3

In the above query <json_column> must be replace by your column name.

$.id and $.response contains the JSON key of your columns. You can use for multiple values also.

For example : $

How to get table name by Model in Laravel 5?

Some times we requires get what’s the table name for particular Model. There is a function defined in Laravel itself name


Please look below example:

    $transaction = new Transaction;
    $table = $transaction-&gt;getTable();

How to redirect from http to https using .htaccess ?

Redirect to https

If you want to redirect each request coming should go to https instead of HTTP without any plugin. then

Step1: Go to root directory of your website and look for .htaccess file. It should be exist in root directory.

Step2: Find the ‘RewriteEngine On’ Add the following code after that.

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

Here yourdomain stands for website name for which you want to redirect to https.

How to create custom helper functions in Laravel 5?

From the laravel official
Laravel includes a variety of global "helper" PHP functions. Many of these helper functions are used by the framework itself; however, you are free to use them in your own applications if you find them convenient.

Helpers are pre built utility functions in laravel which we can use directly without any class import/extend. e.g. str_random() – generates a random string of the specified length.
dd() – dumps the given variables and ends execution of the script.

We can also create our own helpers in laravel. Here are the steps.

Step1 : Create a folder in app folder with named Helpers(You can create with other name also).
Step2 : Now create a file with name helpers.php(You can create with other name also) file in Helpers folder
Step3 : Add the utility functions in that file.
Step3 : Now add the open composer.json locate autoload block and add the following line

"files": ["app/Helpers/helpers.php"]

Step3 : Now,load it up with composer – composer dump-autoload

Now you can use your utility functions anywhere in the application.

How to find duplicate rows from query ?

If you want to find duplicate rows from your table use the following query.

SELECT column1,column2 COUNT(*) users GROUP BY column1, column2 HAVING COUNT(*) > 1

Following are steps :

To test the above query on sample table

Step1 : First of all you need a table (Assuming you have database)

CREATE TABLE `users` (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`age` int(11) NOT NULL

Step2 : Insert the dummy values

INSERT INTO `users` (`id`, `name`, `email`, `age`) VALUES
(1, 'shyam', '', 31),
(2, 'ram', '', 23),
(3, 'shyam', '', 31),
(4, 'ram', '', 23),
(5, 'shyam1', '', 31),
(6, 'ram1', '', 23),
(7, 'shyam1', '', 31),
(8, 'ram1', '', 23);

Result would be :

name email COUNT(*)
shyam 2
ram 2


How to display image from database in PHP?

Step1 : Fetch/Retrieve the image from datbase using database functions.
Step2 : Now use the image tag below.

$convertedImage ='CONVERTED_IMAGE_FROM_DB';
<img src="data:image/jpg|gif|png;charset=utf8;base64,$convertedImage" />
jpg/gif/png depends on the type of image.