Can’t install extensions on VSCode?

If you are trying to install extensions on VSCode but you can’t. Try to visit this site from your browser:

http://cdn.vsassets.io/

Most probably you will get a “This site can’t be reached” message, to solve this you have to change your default DNS to google free public DNS

8.8.8.8
8.8.4.4

If that may not work for you then yo can try to change the DNS for IPv6 to:

2001:4860:4860::8888
2001:4860:4860::8844

Here is a link for more details on changing the DNS to google DNS

https://developers.google.com/speed/public-dns/docs/using

How to install composer on Godaddy cPanel

If you want to install composer on a godaddy shared hosting, you can follow these steps:

On root folder type:

wget https://getcomposer.org/installer
php installer --check
php installer
rm -f installer

to return the path of composer type:

which composer

it’ll return something like: /opt/cpanel/composer/bin/composer

then you can use composer using its full path:
php-cli /opt/cpanel/composer/bin/composer install

for ex. :

php-cli /opt/cpanel/composer/bin/composer install
php-cli /opt/cpanel/composer/bin/composer update

Also if you want to run php artisan , you can type:

/usr/bin/php-cli artisan

Can’t access DB or phpmyadmin locally

If you got an error like: “Host ‘localhost’ is not allowed to connect to this MariaDB server” you can edit the file xampp\mysql\bin\my.ini

Add this line:
skip-grant-tables
after [mysqld] group.

Example:
[mysqld]
skip-grant-tables
port=3306
socket=/tmp/mysql.sock

After that, login to phpmyadmin and repair the users table as it mostly is corrupted.

Also try to rename :

xampp\mysql\data\ibdata1
to
xampp\mysql\data\ibdata1.bak

How to view latest SQL statement excuted in Laravel

To view the latest sql query executed in Laravel you can

DB::enableQueryLog();

print_r(DB::getQueryLog());

Note that you have to enable the query log before executing the query and view/print it after execution ..

A good practice is to enable it only in Local environment

if (App::environment('local')) {
    // The environment is local
    DB::enableQueryLog();
}

 

How to sanitize raw data in Laravel

When doing a raw data query from user input like this:

$someVariable = Input::get("some_variable");

$results = DB::select( DB::raw("SELECT * FROM some_table WHERE some_col = '$someVariable'") );

we are at risk of SQL injection , to avoid that we can bin parameters to our query like this:

$someVariable = Input::get("some_variable");

$results = DB::select( DB::raw("SELECT * FROM some_table WHERE some_col = :somevariable"), array(
   'somevariable' => $someVariable,
 ));

 

Another point is that if we want to do a raw that doesn’t return a value, we can do it like this

DB::statement( 'ALTER TABLE HS_Request AUTO_INCREMENT=1111' );

and that way can take parameters as well

DB::statement( 'ALTER TABLE HS_Request AUTO_INCREMENT=:incrementStart', array('incrementStart' => 1111) );