Posts

Showing posts with the label PHP

laravel raw query generator

    $query = User :: where ([ 'dept_id' => $request -> dept_id , 'role' => 'emp' ]);         $sql = $query -> toSql ();         $bindings = $query -> getBindings ();         $sqlWithBindings = Str :: replaceArray ( '?' , $bindings , $sql );         dd ( $sqlWithBindings );

Laravel Auth Registration and Login with Bootstrap

  composer require laravel/ui php artisan ui bootstrap php artisan ui bootstrap --auth npm install npm run dev npm run production

Number OR Amount to Word Conversion in php

Image
function getIndianCurrency(float $number) { $decimal = round($number - ($no = floor($number)), 2) * 100; $hundred = null; $digits_length = strlen($no); $i = 0; $str = array(); $words = array(0 => '', 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten', 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen', 16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen', 19 => 'nineteen', 20 => 'twenty', 30 => 'thirty', 40 => 'forty', 50 => 'fifty', 60 => 'sixty', 70 => 'seventy', 80 => 'eighty', 90 => 'nine...

PHP age calculator according to DOB

Image
$dob="10-10-2000";  if(!empty($dob)){                             $birthdate = new DateTime($dob);                             $today   = new DateTime('today');                             $age = $birthdate->diff($today)->y;                         }else{                           $age=0;                                                     }

Codeigniter Inner Join Example

Image
public function funcname ( $id ) { $this ->db->select( '*' ); $this ->db->from( 'Album a' ); $this ->db->join( 'Category b' , 'b.cat_id=a.cat_id' , 'left' ); $this ->db->join( 'Soundtrack c' , 'c.album_id=a.album_id' , 'left' ); $this ->db->where( 'c.album_id' , $id ); $this ->db->order_by( 'c.track_title' , 'asc' ); $query = $this ->db->get(); if ( $query ->num_rows() != 0 ) { return $query ->result_array(); } else { return false ; } }

How to disable CSRF Token in Laravel and why we have to disable it?

Image
  You can Disable CSRF on few routes by editing. App\Http\Middleware\VerifyCsrfToken and add your own routes name in protected  Disable for all routes protected $except = [ '*' , ]; Disable for some routes protected $except = [ 'mobile/*' , 'news/articles' , ];

Steps after get cloned from github Laravel Project

Image
  Clone your project . Go to the folder application using cd command on your cmd or terminal. Run composer install on your cmd or terminal. Copy .env.example file to .env on the root folder. ... Open your project Run php artisan key:generate. Run php artisan migrate. Run php artisan serve.

phpmailer not working in online server

  Two things we have to do for sending mail using GMAIL in online : -  1)Allow less secure app  2)DisplayUnlockCaptcha https://accounts.google.com/b/0/displayunlockcaptcha replace 0 with your logged in user number

Find Unique value from array by custome method

Image
  <?php $arr=array(1,1,1,2,1,1,1,1); $temp=""; $unique=""; $i=1; foreach($arr as $value){   if($temp!="" && $temp!=$value){       $unique=$value;       break;     }       $temp=$value;   $i++; } echo "Unique Value is ".$unique; ?>

PHP mysql Database Backup

Image
  $date_string   = date("Ymd");  $dbhost = "localhost";     $dbuser = 'dbuser';     $dbpass = 'dbuserpass';     $dbname = 'dbname';     $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);     $backupAlert = '';     $tables = array();     $result = mysqli_query($connection, "SHOW TABLES");     if (!$result) {         $backupAlert = 'Error found.<br/>ERROR : ' . mysqli_error($connection) . 'ERROR NO :' . mysqli_errno($connection);     } else {         while ($row = mysqli_fetch_row($result)) {             $tables[] = $row[0];         }         mysqli_free_result($result);         $return = '...

Adding days to $Date in PHP

Image
  <?php $Date = "2010-09-17" ; echo date( 'Y-m-d' , strtotime( $Date . ' + 1 days' )); echo date( 'Y-m-d' , strtotime( $Date . ' + 2 days' )); ?> And it outputs correctly: 2010 -09 -18 2010 -09 -19

Target class controller does not exist - Laravel 8

Image
  "In previous releases of Laravel, the RouteServiceProvider contained a $namespace property. This property's value would automatically be prefixed onto controller route definitions and calls to the action helper / URL::action method. In Laravel 8.x, this property is null by default. This means that no automatic namespace prefixing will be done by Laravel." Laravel 8.x Docs - Release Notes   You would have to use the Fully Qualified Class Name for your Controllers when referring to them in your routes when not using the namespace prefixing. use App \ Http \ Controllers \ UserController ; Route::get( '/users' , [UserController::class, 'index' ]); // or Route::get( '/users' , 'App\Http\Controllers\UserController@index' );  

Timezone in php for Bharat (India)

Image
  date_default_timezone_set( 'Asia/Kolkata' ); echo date( 'd-m-Y H:i' );

HTML Table to Excel Conversion without using any external library in PHP...

Image

Three Types Page Redirect using HTML,Javascript,PHP

Image
  Today we are going to learn how to redirect a page 1)Using HTML <!DOCTYPE html> <html> <head>     <title>Redirect</title>     <meta http-equiv = "refresh" content = "5; url = https://mwtc.in" /> </head> <body>         <h2>Welcome Redirect</h2> </body> </html> 2)Using Javascript <!DOCTYPE html> <html> <head>     <title>Redirect</title> </head> <body>         <h2>Welcome Redirect Javascript</h2> <script type="text/javascript">     window.location.href="http://facebook.com"; </script> </body> </html>   3)Using PHP  <?php header("Location: https://yahoo.com"); ?> <!DOCTYPE html> <html> <head>     <title>Redirect</title> </head> <body>   ...

Laravel could not open input file artisan

Image
    How we fix it : - This is a very common error message that a Laravel user gets. Now let’s see why does this error appears. 1. Wrong console location This error mainly occurs when a user tries to open a Laravel project outside the project folder. Laravel can only execute the project if we open it inside the project folder. That is what the error says ‘ could not open input file ‘. So whenever customers approach us with this error, we ask the customer to re-check the location where they execute the command. 2. Improper permissions of artisan Sometimes the artisan may not be executable. If the user tries to execute the command, it cannot access it. And the user receives this error. So to make artisan executable, we use the command chmod +x artisan Later try to use the command, and it will work.       

How to load model and use it in Codeigniter (CI)

Image
   Here We are loading model $this -> load -> model ( 'model_name' ); And here we are using model's method  $this -> model_name -> method ();

Remove warning messages in PHP

 You really should fix whatever's causing the warning, but you can control visibility of errors with error_reporting() . To skip warning messages, you could use something like:   error_reporting(E_ERROR | E_PARSE);

Base URL Setting in Codeigniter

Copy below code and paste inside the config.php file in Codeigniter . You will get this file in Application/Config/config.php  $config['base_url'] = $config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ?  "https" : "http")."://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

How to send email with attachment From Local/Online Server using PHPMailer in Hindi | Updated 2020

Image
  PHPMailer is mostly used PHP library for sending the email . This library is very fast and you will get email direct in your inbox whereas when we use php mail function then it send email but email will go inside the SPAM .  Email sending process using PHPMailer : -  Step 1 : Download  PHPMailer Library From https://github.com/PHPMailer/PHPMailer      . Step 2 : Extract Zip File and copy 3 Files from extracted folder named PHPMailer.php , SMTP.php and Exception.PHP . Keep these files in your project and include by using built in function "require" of PHP . Strep 3 : Here we are using GMAIL SMTP but you can use according to you . Set smtp detail and then set username (email id) and password of your account . Note : Here we are not using composer for this so we don't need to include autoload.php file . If you need any help then you can reach us at dular88@gmail.com . For more detail visit at https://github.com/PHPMailer/PHPMailer Demo : ht...