Go is an open source, procedural, compiled and statically typed programming language. It was designed and developed at Google by Rob pike, Ken Thompson and Robert Griesemer. It is syntactically similar to C, also provides some additional features memory safety, garbage collection, dynamic types. Some people called it golang also.
What is Accessor in Laravel?
As we know laravel accessor is very userful feature. It is used for creating the virtual attribute on the object which you want to access it as database column name.
So for example if you want to show full name and in your database table (users) has first_name
and last_name
columns, you can write:
public function getFullNameAttribute()
{
return $this->first_name . " " . $this->last_name;
}
Then you can call $user->full_name
and it will return the first and last name collectively. Naming convention for accessor is a snake_case attribute, so getFullNameAttribute
function would be accessible through $user->user_name
.
prefix must be added as get and suffix would be Attribute
What is De structuring?
Decompsoing a structure into its individual parts is called de structuring.
PHP var_export() Function
Outputs or returns a parsable string representation of a variable. It will gives you structured information about the given variable.
Syntax :
var_export ( mixed $expression [bool $return = FALSE ]);
$expression – The variable you want to export.
$return – This is optional. If it is used and set to true then it will return the variable representation instead of outputting it else it will return NULL.
Example :
$x = array("red", "green", "blue");
echo var_export($x);
Output:
array ( 0 => 'red', 1 => 'green', 2 => 'blue', )
Pushing to a Remote Branch with a Different Name
You just have to run the following command
git push origin local-name:new-name-for-remote
How to Install Composer In Your Project ?
Run this in your command line:
curl -sS https://getcomposer.org/installer | php
For more information please follow.
https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos
How to remove primary key from table?
ALTER table table_name
DROP PRIMARY KEY;
How to add primary key in table?
ALTER table table_name
ADD PRIMARY KEY column_name;
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 : $.response.name
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.
1 2 | RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L] |
Here yourdomain stands for website name for which you want to redirect to https.