• laravel

    Laravel – the requested url was not found on this server

    This error is mostly cause .htaccess file is not set up.

    write the below coding in .htaccess file in laravel

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>
    
        RewriteEngine On
    
        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)/$ /$1 [L,R=301]
    
        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    
        # Handle Authorization Header
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    </IfModule>

  • Wordpress

    how to count the hit of post

    Count the post hit and save it to the database

    • Create a database table with fields postid, numberofcounts…

    logic

    onload of the post page , get its id and store it in the datatable with count

    On every load the count number will be increased

    Example

    Let us consider the table name is tb_hit_count with field postid , and numbercount

    global $wpdb;
       $table = $wpdb->prefix.'tb_hit_count';
    	$post_id = $wpdb->get_results("SELECT ncount,post_id FROM ".$table." WHERE post_id = ". $id);	if(!empty($post_id))
    	{
    		$newcount = $post_id[0]->ncount +1;
    		//echo $newcount;
    		$where = array('post_id'=>$id);
    		$data= array('ncount'=>$newcount);
    		//echo $cat_parent;
    	$wpdb->update( $table, $data, $where);
    	}
    	else{
    		
    $datab = array('post_id' => $id, 'parent_category' => 'golf-videos', 'ncount' => 1, );
    $wpdb->insert($table,$datab);
    	}

    if the post_id is already in the table , we just update the count , else we insert the post_it values in table.

  • Wordpress

    Get the parent category of post in wordpress

    get current post id

    $id = get_the_ID();
    echo $id;


    get current post parent category slug

    $category = get_the_category();
    $category_parent_id = $category[0]->category_parent;
    if ( $category_parent_id != 0 ) {
    $category_parent = get_term( $category_parent_id, ‘category’ );
    $cat_parent_slug = $category_parent->slug;

    } else {
    $cat_parent _slug = $category[0]->slug;
    }

  • laravel,  php,  phpmyadmin

    Laravel join sql query syntax with where between group by

    Its a query to join two tables and get the details in between given date format ,according to month (month wise) and of specific city .

    sample work

    Simple SQL query

    the query in simple SQL to be added in any language .

    select count(*) as count , city , MONTH(`abctable`.`created_at`) as mm, YEAR(`abctable`.`created_at`)as yy from `abctable` join `xyztable` on `abctable`.`entity_id` = `xyztable`.`parent_id` where `abctable`.`created_at` between '2019-04-24 00:00:00' and '2019-09-12 12:12:12' AND `xyztable`.`city`='Pune' GROUP BY YEAR(`abctable`.`created_at`),MONTH(`abctable`.`created_at`)

    Laravel SQL query

    the sql query in laravel controller form data.

     $users = DB::table('abctable')
            ->select(DB::raw('count(*) as count, MONTH(abctable.created_at) as MM, YEAR(abctable.created_at) as YY'))
            ->join('xyztable', 'n3d_sales_flat_order_grid.entity_id', '=', 'xyztable.parent_id')
            ->whereBetween('abctable.created_at',[new Carbon($fdate),new Carbon($gdate)])
            ->where('xyztable.city','like',$city)
            ->groupBy(DB::raw('MONTH(abctable.created_at)'),DB::raw('YEAR(abctable.created_at)'))
            ->get();
  • Wordpress

    Run wordpress in subfolder of domain

    To run the website as blog in subfolder of domain i.e www.example.com/blog

    you need to change .htaccess .

    Normal .htaccess file is as follows

    # BEGIN WordPress
    
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    # END WordPress

    you have to change few line here i.e. folder name where the wordpress files lies in eg. blog folder

    # BEGIN WordPress
    
    RewriteEngine On
    RewriteBase /blog
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    
    # END WordPress

  • Wordpress

    Set cookies in wordpress

    set cookies in wordpress to pop msg if new visitor .

    in function.php write the code below :

    function bloggolfoy_set_new_user_cookie() {
    if ( ! is_admin() && ! isset( $_COOKIE[‘bloggolfoy_new_visitor’] ) ) {
    setcookie( ‘bloggolfoy_new_visitor’, 1, time() + 3600 * 24 * 10, COOKIEPATH, COOKIE_DOMAIN, false );
    }
    }
    add_action( ‘init’, ‘bloggolfoy_set_new_user_cookie’);

    now where you have coded popup : write

    <?php if ( isset( $_COOKIE[‘bloggolfoy_new_visitor’] ) ) {

    // echo ‘Welcome back!’;

    } else {?> script code to pop <?php } ?>

  • javascript,  laravel,  mysql,  php

    Laravel-date format variable SQL query for API value

    given date value in string format , getting error in SQL query , so have to change it into date format in Laravel using Carbon function ( for date time )

    laravel controller sample work to get values in json [RestAPI]
    <?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use App\Http\Resources\OrdersCollection;
    use Illuminate\Support\Facades\DB;
    use App\Http\Controllers\Controller;
    use app\Orders;
    use Response;
    use Carbon\Carbon;
    
    class OrdersController extends Controller
    {
        //
        public function index(Request $request)
        {
            $fdate = $request->query('fdate');
            $gdate = $request->query('gdate');
    
    
            $users = DB::table('abctable')
                ->select(DB::raw('count(*) as count, city'))
                ->join('n3d_sales_flat_order_address', 
             'abctable.entity_id', '=', 'xyztable.parent_id')
                ->whereBetween('abctable.created_at',[new Carbon($fdate),new Carbon($gdate)])
                ->groupBy('xyztable.city')
                ->get();
               
           return Response::json($users);
        }
    }
    

    Carbon function

    $users = DB::table(‘abctable’)
    ->select(DB::raw(‘count(*) as count, city’))
    ->join(‘n3d_sales_flat_order_address’,
    ‘abctable.entity_id’, ‘=’, ‘xyztable.parent_id’)
    ->whereBetween(‘abctable.created_at’,[new Carbon($fdate),new Carbon($gdate)])
    ->groupBy(‘xyztable.city’)
    ->get();

  • laravel

    how to add image , url in laravel view

    add image to view

    <img src=” {{ asset(‘img/myimage.png’) }} ” >

    Explaination : here asset is pointed to public folder in laravel , where lies the img folder containing images.

    Reference : https://stackoverflow.com/a/36441835/12423259

    Add url of next page in view

    <a href=” {{url(‘/main/dashboard’)}} “> click </a>

    Explaination : here main is controller class name and dashboard is a method where code for view is placed in laravel.

  • php,  phpmyadmin

    #1067 – Invalid default value for ‘time’ – solution

    when altering the database table error displays – 1067 – Invalid default value for ‘time’

    Solution is : There might be a datetime field with Null and default value 0000-00-00 00:00:00.

    change the datetime field Null uncheck and default value None

    change the date time field default value to none and uncheck NULL

    Thus you can alter the database now for other field add, remove and further operations.