Laravel migrations change default value of column

I have a table with a default value already assigned. For an example we can look at the following: Schema::create(‘users’, function (Blueprint $table) { $table->increments(‘id’)->unsigned(); $table->integer(‘active’)->default(1); }); I now want to change my default value on the active field. I am expecting to do something like this: if (Schema::hasTable(‘users’)) { Schema::table(‘users’, function (Blueprint $table) { … Read more

How to prevent code injection attacks in PHP?

I am a bit confused, there are so many functions in PHP, and some using this, some using that. Some people use: htmlspecialchars(), htmlentities(), strip_tags() etc Which is the correct one and what do you guys usually use? Is this correct (advise me a better one, if any): $var = mysql_real_escape_string(htmlentities($_POST[‘username’])); This line can prevent … Read more

Why I have to call ‘exit’ after redirection through header(‘Location..’) in PHP?

You know that if you want to redirect an user in PHP you can use the header function: header(‘Location:’); It is also well known that it is a good practice to put also an exit; after the header call, to prevent execution of other php code. So my question is: could the code after … Read more

json_encode(): Invalid UTF-8 sequence in argument

I’m calling json_encode() on data that comes from a MySQL database with utf8_general_ci collation. The problem is that some rows have weird data which I can’t clean. For example symbol �, so once it reaches json_encode(), it fails with json_encode(): Invalid UTF-8 sequence in argument. I’ve tried utf8_encode() and utf8_decode(), even with mb_check_encoding() but it … Read more

Get the files inside a directory

How to get the file names inside a directory using PHP? I couldn’t find the relevant command using Google, so I hope that this question will help those who are asking along the similar lines. Answer There’s a lot of ways. The older way is scandir but DirectoryIterator is probably the best way. There’s also … Read more

Keeping session alive with Curl and PHP

I’m trying to connect to an API, authenticate a user and then view the user details. This is accomplished by first accessing the login endpoint at<username>/<password> to log in and then the following to view user details: This all works in a web browser. However, once I try to use Curl, the login … Read more

Fatal error while upgrading Laravel 5.1 to 5.2

I’m following the official upgrade guide from 5.1 to 5.2. First sub-section says: If you are installing a beta release of Laravel 5.2, add “minimum-stability”: “beta” to your composer.json file. Update your composer.json file to point to laravel/framework 5.2.*. Add symfony/dom-crawler ~3.0 and symfony/css-selector ~3.0 to the require-dev section of your composer.json file. Now, after … Read more