Similar Posts
get user ip laravel
To get current user ip in php, laravel \Request::ip(); or $request->ip(); Here is what the above code is Doing: 1. We are using the Request facade to get the current request. 2. We are using the ip() method to get the current user’s IP address.
wp override home url with php
// add these 2 lines to your wp-config.php, // exactly before requiring wp-settings.php define( ‘WP_HOME’, ‘http://localhost/site’ ); define( ‘WP_SITEURL’, ‘http://localhost/site’ ); // NOTE: you’r overriting the homeurl locally, without changing the value in DB. Here is what the above code is Doing: 1. It’s defining the WP_HOME and WP_SITEURL constants in your wp-config.php file. 2….
how to add extra days from a date php
Here is what the above code is Doing: 1. We first declare a date variable and assign it a value of “2019-05-10”. 2. We then use the date() function to add 10 days to the date variable. 3. The date() function takes two parameters: the format of the date and the date to be formatted….
php check if json
function isJson($string) { json_decode($string); return (json_last_error() == JSON_ERROR_NONE); } Here is what the above code is Doing: 1. It’s checking if the string is a valid JSON string. 2. If it is, it’s decoding the JSON string into a PHP array. 3. It’s then checking if the array has a key called “error”. 4. If…
foreach range php
Here is what the above code is Doing: 1. The foreach loop is going to loop through the range function. 2. The range function is going to return an array of numbers from 0 to 12. 3. The foreach loop is going to loop through each number in the array and echo it out. The…
foreign key in laravel migration
Schema::table(‘posts’, function (Blueprint $table) { $table->unsignedBigInteger(‘user_id’); $table->foreign(‘user_id’)->references(‘id’)->on(‘users’); }); OR Schema::table(‘posts’, function (Blueprint $table) { $table->foreignId(‘user_id’)->constrained(); }); Here is what the above code is Doing: 1. We’re adding a new column to the posts table called user_id. 2. We’re telling Laravel that the user_id column references the id column on the users table. 3. We’re telling…