Author: therichpost

  • Vue Laravel Bootstrap Owl Carousel Working Example

    Vue Laravel Bootstrap Owl Carousel Working Example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Vue Laravel Bootstrap Owl Carousel Working Example.

    If you are new in laravel and vuejs, then you can check below links to get vue laravel basics information.

    https://therichpost.com/category/laravel

    https://therichpost.com/category/laravl-5-7

    https://therichpost.com/category/vuejs

    Here I am showing Bootstrap Owl Carousel working in Vue Laravel:

    Vue Laravel Bootstrap Owl Carousel Working Example

    Installation & Coding:

    Here are the some basic commands need to run into your terminal to install fresh laravel setup:

    $ composer create-project --prefer-dist laravel/laravel vuelaraveowlcarousel //install fresh laravel setup
    
    $ cd vuelaraveowlcarousel //go laravel setup
    
    $ npm install //node modules for vuejs

    Now come to the vue code into laravel:

    Here is the code, you need to add into vuelaraveowlcarousel/resources/js/components/ExampleComponent.vue

    <template>
        <div class="container">
            <div class="row justify-content-center">
                <div class="col-md-8">
                     <center><h2>Vue Laravel Bootstrap Owl Carousel Working Example:</h2></center>  
             <div id="demo" class="carousel slide" data-ride="carousel">
              <!-- Indicators -->
              <ol class="carousel-indicators">
                <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                <li data-target="#myCarousel" data-slide-to="1"></li>
                <li data-target="#myCarousel" data-slide-to="2"></li>
              </ol>
    
              <!-- Wrapper for slides -->
              <div class="carousel-inner">
                <div class="carousel-item active">
                <img src="https://responsivedesign.is/wp-content/uploads/2016/11/Owl-Carousel-2_ri92wj.jpg" alt="Los Angeles" style="width:100%;">
                </div>
    
                <div class="carousel-item">
                <img src="https://responsivedesign.is/wp-content/uploads/2016/11/Owl-Carousel-2_ri92wj.jpg" alt="Chicago" style="width:100%;">
                </div>
              
                <div class="carousel-item">
                <img src="https://responsivedesign.is/wp-content/uploads/2016/11/Owl-Carousel-2_ri92wj.jpg" alt="New york" style="width:100%;">
                </div>
              </div>
    
              <!-- Left and right controls -->
                <a class="carousel-control-prev" href="#demo" data-slide="prev">
                <span class="carousel-control-prev-icon"></span>
                </a>
                <a class="carousel-control-next" href="#demo" data-slide="next">
                <span class="carousel-control-next-icon"></span>
                </a>
              </div>
                </div>
            </div>
        </div>
    </template>
    
    <script>
        export default {
            mounted() {
                console.log('Component mounted.')
            }
        }
    </script>
    

    Here is the code you need to add
    vuelaraveowlcarousel/resources/js/ app.js file:

    /**
     * First we will load all of this project's JavaScript dependencies which
     * includes Vue and other libraries. It is a great starting point when
     * building robust, powerful web applications using Vue and Laravel.
     */
    window.Vue = require('vue');
    import 'bootstrap/dist/css/bootstrap.min.css';
    import 'bootstrap/dist/js/bootstrap.min.js';
    /**
     * Next, we will create a fresh Vue application instance and attach it to
     * the page. Then, you may begin adding components to this application
     * or customize the JavaScript scaffolding to fit your unique needs.
     */
    
    Vue.component('example-component', require('./components/ExampleComponent.vue'));
    
    const app = new Vue({
        el: '#app'
    });
    

    Now come to the laravel code to display vue output:

    Here is the code you need to add into
    vuelaraveowlcarousel/resources/ views/welcome.blade.file:

    <div id="app"><example-component></example-component></div>
    <script src="{{asset('js/app.js')}}"></script>

    This is done. Now run php artisan serve command to see the working output and if you have any query related to this post then please do comment below or ask question.

    Thank you

    Ludhiane wala ajay

    TheRichPost

  • How to add Chart js Datatables Fullcalendar in Angular single Component?

    How to add Chart js Datatables Fullcalendar in Angular single Component?

    Hello to all, welcome to therichpost.com. In this post, I will tell you, How to add Chart js Datatables Fullcalendar in Angular single Component?

    Angular 7 is getting more popularity day by day and we will include Chartjs, Datatables and Fullcalendar in Angular 7 and this is the best. Here I am showing the working example picture:

    how to add chart js datatables fullcalendar in angular single component

    Here are the coding snippets, you need to follow:

    1. Very first, you need to run common below commands to add Angular 7 project on your machine:

    $ npm install -g @angular/cli 
    $ ng new chartjsangular //Install Angular Project
    $ cd chartjsangular // Go to project folder
    $ ng serve //Run Project
    http://localhost:4200/ //Run On local server

    2. Now you need to run below commands to add chart js into your Angular application:

    $ npm install --save chart.js
    
    $ npm install ng-fullcalendar --save
    
    $ npm install angular-datatables --save
    
    $ npm install datatables.net --save
    
    $ npm install datatables.net-dt --save
    
    $ npm install @types/jquery --save-dev
    
    $ npm install @types/datatables.net --save-dev
    
    $ npm install ngx-bootstrap bootstrap --save

    3. After that, add below code into your angular.json file:

    ....  
     "styles": [
       "src/styles.css",
       "node_modules/datatables.net-dt/css/jquery.dataTables.css",
       "node_modules/bootstrap/dist/css/bootstrap.min.css",
      ],
    "scripts": [
      "node_modules/datatables.net/js/jquery.dataTables.js",
      "node_modules/bootstrap/dist/js/bootstrap.js",]
    ....

    4. After that, add below code into your app.module.ts file:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { FullCalendarModule } from 'ng-fullcalendar';
    import { AppComponent } from './app.component';
    import {DataTablesModule} from 'angular-datatables';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        FullCalendarModule,
        DataTablesModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

    5. After that, add below code into your app.component.ts file:

    import { Component, AfterViewInit } from '@angular/core';
    import * as Chart from 'chart.js';
    import { Options } from 'fullcalendar';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'chartjsangular';
      canvas  : any;
      ctx     : any;
    
      canvas1 : any;
      ctx1    : any;
    
      canvas2 : any;
      ctx2    : any;
    
      canvas3 : any;
      ctx3    : any;
    
      calendarOptions: Options;
    
      public data = [
        {name: 'test', email: 'test@gmail.com', website:'test.com'},
        {name: 'test', email: 'test@gmail.com', website:'test.com'},
        {name: 'test', email: 'test@gmail.com', website:'test.com'},
        {name: 'test', email: 'test@gmail.com', website:'test.com'},
      ];
      dtOptions: DataTables.Settings = {};
      ngOnInit() {
    
        this.canvas = document.getElementById('myChart');
        this.ctx = this.canvas.getContext('2d');
    
        let myChart = new Chart(this.ctx, {
          type: 'pie',
          data: {
              labels: ["New", "In Progress", "On Hold"],
              datasets: [{
                  label: '# of Votes',
                  data: [1,2,3],
                  backgroundColor: [
                      'rgba(255, 99, 132, 1)',
                      'rgba(54, 162, 235, 1)',
                      'rgba(255, 206, 86, 1)'
                  ],
                  borderWidth: 1
              }]
          },
          options: {
            responsive: false,
            display:true
          }
        });
    
        this.canvas1 = document.getElementById('myChart1');
        this.ctx1 = this.canvas1.getContext('2d');
    
        let myChart1 = new Chart(this.ctx1, {
          type: 'line',
          data: {
              labels: ['January', 'February', 'March', 'April'],
              datasets: [{
                  label: '# of Votes',
                  fill: false,
                  data: [5,3,4,2],
                  backgroundColor: [
                      'rgba(255, 99, 132, 1)',
                      'rgba(54, 162, 235, 1)',
                      'rgba(255, 206, 86, 1)'
                  ],
                  borderColor: "#ffbd35",
                  borderWidth: 1
              }]
          },
          options: {
            responsive: false,
            display:true,
            scales: { yAxes: [{ display: false }],xAxes: [{
                    display: false //this will remove all the x-axis grid lines
                }] }
          },
    
    
        });
    
        this.canvas2 = document.getElementById('myChart2');
        this.ctx2 = this.canvas2.getContext('2d');
    
        let myChart2 = new Chart(this.ctx2, {
          type: 'line',
          data: {
              labels: ['January', 'February', 'March', 'April'],
              datasets: [{
                  label: '# of Votes',
                  fill: false,
                  data: [5,3,4,2],
                  backgroundColor: [
                      'rgba(255, 99, 132, 1)',
                      'rgba(54, 162, 235, 1)',
                      'rgba(255, 206, 86, 1)'
                  ],
                  borderColor: "#ffbd35",
                  borderWidth: 1
              }]
          },
          options: {
            responsive: false,
            display:true,
            scales: { yAxes: [{ display: false }],xAxes: [{
                    display: false //this will remove all the x-axis grid lines
                }] },
            elements: {
            line: {
              tension: 0.000001
            }
        },
          },
    
    
        });
    
    
        this.canvas3 = document.getElementById('myChart3');
        this.ctx3 = this.canvas3.getContext('2d');
    
         let myChart3 = new Chart(this.ctx3, {
          type: 'bar',
          data: {
              labels: ["New", "In Progress", "On Hold"],
              datasets: [{
                  label: '# of Votes',
                  data: [3,4,3],
                  backgroundColor: [
                      'rgba(255, 99, 132, 1)',
                      'rgba(54, 162, 235, 1)',
                      'rgba(255, 206, 86, 1)'
                  ],
                  borderWidth: 1
              }]
          },
          options: {
            responsive: false,
            display:true,
            scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                }
            }]
        }
          }
        });
    
         this.calendarOptions = {
            editable: true,
            eventLimit: false,
            header: {
              left: 'prev,next today',
              center: 'title',
              right: 'month,agendaWeek,agendaDay,listMonth'
            }
            
          };
    
          this.dtOptions = {
          pagingType: 'full_numbers',
          pageLength: 5,
          processing: true
        };
      } 
    
    }

    6. Finally add below code into your app.component.html file:

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.6.1/fullcalendar.min.css">
    <div style="text-align:center; width: 100%;">
      <h1>
        {{ title }}!
      </h1>
      <div style="float: left;width: 20%;border: 1px solid #000;margin: 2px; padding: 5px;background: #ffbd35">
       <canvas id="myChart" width="200" height="200"></canvas>
      </div>
    
       <div style="float: left;width: 20%;border: 1px solid #000;border: 1px solid #000;margin: 2px; padding: 5px;background: #019efb">
        <canvas id="myChart1" width="200" height="200"></canvas>
       </div>
    
       <div style="float: left;width: 20%;border: 1px solid #000;border: 1px solid #000;margin: 2px; padding: 5px;background: #c2fcc9">
        <canvas id="myChart2" width="200" height="200"></canvas>
       </div>
    
       <div style="float: left;width: 20%;border: 1px solid #000;border: 1px solid #000;margin: 2px; padding: 5px;background: #fae7eb">
        <canvas id="myChart3" width="200" height="200"></canvas>
       </div>
    
       <div *ngIf="calendarOptions" style="float: left;width: 40%;border: 1px solid #000;border: 1px solid #000;margin: 2px; padding: 5px;background: #fae7eb">
        <ng-fullcalendar #ucCalendar [options]="calendarOptions" (eventClick)="eventClick($event.detail)" (eventDrop)="updateEvent($event.detail)"
            (eventResize)="updateEvent($event.detail)" (clickButton)="clickButton($event.detail)"></ng-fullcalendar>
      </div>
    
      <table style="float: left;width: 40%;border: 1px solid #000;border: 1px solid #000;margin: 2px; padding: 5px;background: #fae7eb" class="table table-striped table-bordered table-sm row-border hover" datatable [dtOptions]="dtOptions">
      <thead>
        <tr>
          <th>Name</th>
          <th>Email</th>
          <th>Website</th>
        </tr>
      </thead>
      <tbody>
       <tr *ngFor="let group of data">
             <td>{{group.name}}</td>
             <td>{{group.email}}</td>
             <td>{{group.website}}</td>
         </tr>
      </tbody>
    </table>
    
    </div>

    This is it and in the end, run ng serve command into your terminal and see the output like above image and if you have any query related to this post then please do comment below or ask question.

    Thank you

    Ludhiane wala ajay

    TheRichPost

  • How to show multiple charts in one Component in Angular?

    How to show multiple charts in one Component in Angular?

    Hello to all, welcome to therichpost.com. In this post, I will tell you, How to show multiple Charts in one Component in Angular?

    If you are new in Angular then you can check my old angular posts.

    In this post, I will show multiple charts from chart js in one Angular component and here is the working example picture:

    How to show multiple charts in one Component in Angular?

    Here is the working code snippets need to follow:

    1. Very first, you need to run common below commands to add Angular 7 project on your machine:

    $ npm install -g @angular/cli 
    $ ng new chartjsangular //Install Angular Project
    $ cd chartjsangular // Go to project folder
    $ ng serve //Run Project
    http://localhost:4200/ //Run On local server

    2. Now you need to run below commands to add chart js  into your Angular application:

    npm install --save chart.js

    3. After that, add below code into your app.component.ts file:

    import { Component, AfterViewInit } from '@angular/core';
    import * as Chart from 'chart.js';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'chartjsangular';
      canvas  : any;
      ctx     : any;
    
      canvas1 : any;
      ctx1    : any;
    
      canvas2 : any;
      ctx2    : any;
    
      canvas3 : any;
      ctx3    : any;
    
      ngOnInit() {
    
        this.canvas = document.getElementById('myChart');
        this.ctx = this.canvas.getContext('2d');
    
        let myChart = new Chart(this.ctx, {
          type: 'pie',
          data: {
              labels: ["New", "In Progress", "On Hold"],
              datasets: [{
                  label: '# of Votes',
                  data: [1,2,3],
                  backgroundColor: [
                      'rgba(255, 99, 132, 1)',
                      'rgba(54, 162, 235, 1)',
                      'rgba(255, 206, 86, 1)'
                  ],
                  borderWidth: 1
              }]
          },
          options: {
            responsive: false,
            display:true
          }
        });
    
        this.canvas1 = document.getElementById('myChart1');
        this.ctx1 = this.canvas1.getContext('2d');
    
        let myChart1 = new Chart(this.ctx1, {
          type: 'line',
          data: {
              labels: ['January', 'February', 'March', 'April'],
              datasets: [{
                  label: '# of Votes',
                  fill: false,
                  data: [5,3,4,2],
                  backgroundColor: [
                      'rgba(255, 99, 132, 1)',
                      'rgba(54, 162, 235, 1)',
                      'rgba(255, 206, 86, 1)'
                  ],
                  borderColor: "#ffbd35",
                  borderWidth: 1
              }]
          },
          options: {
            responsive: false,
            display:true,
            scales: { yAxes: [{ display: false }],xAxes: [{
                    display: false //this will remove all the x-axis grid lines
                }] }
          },
    
    
        });
    
        this.canvas2 = document.getElementById('myChart2');
        this.ctx2 = this.canvas2.getContext('2d');
    
        let myChart2 = new Chart(this.ctx2, {
          type: 'line',
          data: {
              labels: ['January', 'February', 'March', 'April'],
              datasets: [{
                  label: '# of Votes',
                  fill: false,
                  data: [5,3,4,2],
                  backgroundColor: [
                      'rgba(255, 99, 132, 1)',
                      'rgba(54, 162, 235, 1)',
                      'rgba(255, 206, 86, 1)'
                  ],
                  borderColor: "#ffbd35",
                  borderWidth: 1
              }]
          },
          options: {
            responsive: false,
            display:true,
            scales: { yAxes: [{ display: false }],xAxes: [{
                    display: false //this will remove all the x-axis grid lines
                }] },
            elements: {
            line: {
              tension: 0.000001
            }
        },
          },
    
    
        });
    
    
        this.canvas3 = document.getElementById('myChart3');
        this.ctx3 = this.canvas3.getContext('2d');
    
         let myChart3 = new Chart(this.ctx3, {
          type: 'bar',
          data: {
              labels: ["New", "In Progress", "On Hold"],
              datasets: [{
                  label: '# of Votes',
                  data: [3,4,3],
                  backgroundColor: [
                      'rgba(255, 99, 132, 1)',
                      'rgba(54, 162, 235, 1)',
                      'rgba(255, 206, 86, 1)'
                  ],
                  borderWidth: 1
              }]
          },
          options: {
            responsive: false,
            display:true,
            scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                }
            }]
        }
          }
        });
      } 
    
    }

    4. Finally add below code into your app.component.html file:

    <!--The content below is only a placeholder and can be replaced.-->
    <div style="text-align:center">
      <h1>
        {{ title }}!
      </h1>
      <div style="float: left;width: 250px;border: 1px solid #000;margin: 2px; padding: 5px;">
       <canvas id="myChart" width="250" height="200"></canvas>
      </div>
    
       <div style="float: left;width: 250px;border: 1px solid #000;border: 1px solid #000;margin: 2px; padding: 5px;">
        <canvas id="myChart1" width="250" height="200"></canvas>
       </div>
    
       <div style="float: left;width: 250px;border: 1px solid #000;border: 1px solid #000;margin: 2px; padding: 5px;">
        <canvas id="myChart2" width="250" height="200"></canvas>
       </div>
    
       <div style="float: left;width: 250px;border: 1px solid #000;border: 1px solid #000;margin: 2px; padding: 5px;">
        <canvas id="myChart3" width="250" height="200"></canvas>
       </div>
    
    </div>

    This is it and in the end, run ng serve command into your terminal and see the output like above image and if you have any query related to this post then please do comment below or ask question.

    Thank you

    Ludhiane wala ajay

    TheRichPost

  • How to upload image with Laravel Angular?

    How to upload image with Laravel Angular?

    Hello to all, welcome to therichpost.com. In this post, I will tell you, How to upload image with Laravel Angular?

    If you are new in Laravel or Angular then you can check my previous posts related to Angular and laravel.

    Here is the second part of this post : How to get image from laravel and show in angular?

    Angular Installation and Working:


    1. Very first, you need to run common below commands to add Angular 7 project on your machine:

    $ npm install -g @angular/cli
    
    $ ng new angularlaraveluploadimage //Install fresh Angular setup
    
    $ cd angularlaraveluploadimage //go inside angular fresh setup

    2. Now you need to add the below code into your src\app\app.module.ts file:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { HttpClientModule } from '@angular/common/http';
    import { AppComponent } from './app.component';
    import { FormsModule }   from '@angular/forms';
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        HttpClientModule,
        FormsModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

    3. Now you need to add below code into your Angular 7 src\app\app.component.ts file:

    import { Component } from '@angular/core';
    import { HttpClient, HttpHeaders } from '@angular/common/http';
    import {NgForm} from '@angular/forms';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'angularlaraveluploadimage';
      filedata:any;
        fileEvent(e){
            this.filedata = e.target.files[0];
        }
      constructor(private http: HttpClient) {
      }
    
       onSubmit(f: NgForm) {
           
                var myFormData = new FormData();
                const headers = new HttpHeaders();
              headers.append('Content-Type', 'multipart/form-data');
              headers.append('Accept', 'application/json');
        	    myFormData.append('image', this.filedata);
          	this.http.post('http://localhost/blog/public/api/sample-restful-apis', myFormData, {
      headers: headers
    }).subscribe(data => {
          		console.log(data);
          });
            
          }
    }

    4. Now you need to add into your Angular 7 app.component.html file:

    <div style="text-align:center">
      <h1>
        Welcome to {{ title }}!
      </h1>
      <img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
    <h2>Here are some links to help you start: </h2>
    <form #f="ngForm" (ngSubmit)="onSubmit(f)">
    <input type="file"  name="myFile" (change)="fileEvent($event)"/>
    <button>Upload Image</button>
    </form>
    </div>

     

    5. Now run ng serve command into your terminal and you will see below output:

    How to upload image with Laravel Angular?

    Laravel Working:


    1. Here is the code for your laravel 5.7 routes/api.php file:

    Route::post("/sample-restful-apis" , "Controller@uploadimage");

    2. Now you need to all below code into app\Http\Controllers\Controller.php file:

    <?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Foundation\Bus\DispatchesJobs;
    use Illuminate\Routing\Controller as BaseController;
    use Illuminate\Foundation\Validation\ValidatesRequests;
    use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
    use Illuminate\Http\Request;
    
    class Controller extends BaseController
    {
        use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
        public function uploadimage(Request $request)
        {
          //dd($request->all());
          if ($request->hasFile('image'))
          {
                $file      = $request->file('image');
                $filename  = $file->getClientOriginalName();
                $extension = $file->getClientOriginalExtension();
                $picture   = date('His').'-'.$filename;
                $file->move(public_path('img'), $picture);
                return response()->json(["message" => "Image Uploaded Succesfully"]);
          } 
          else
          {
                return response()->json(["message" => "Select image first."]);
          }
        }
    }

    This is it and also php artisan serve command into your second terminal and check the angular laravel working If you have any query related to this post, then do comment below or ask question.

    Thank you,

    Ludhiane wala ajay,

    TheRichPost

  • How to connect with Mongodb with Nodejs and fetching data?

    How to connect with Mongodb with Nodejs and fetching data?

    Hello to all, welcome to therichpost.com. In this post, I will tell you, How to connect with Mongodb with Nodejs and fetching data?

    MongoDB is NoSQL database. Now I am learning this and this is very interesting and I am going to share some working examples.

    We can also save the mongodb data into custom json file and this feature makes mongodb better.

    Mongodb data with command prompt query:

    mongodb data with command prompt query

    Here is the working coding steps you need to follow:

    1. First you need to run below query to install mongodb into your node app:

    $ npm install mongodb

    2 . Here is the code you need to add into testcode.js(you can choose you name) file:

    var MongoClient = require('mongodb').MongoClient;
    var url = "mongodb://localhost:27017/";
    MongoClient.connect(url, function(err, db) {
      if (err) throw err;
      var dbo = db.db("test");
      dbo.collection("test").findOne({}, function(err, result) {
        if (err) throw err;
        console.log(result.Field);
        db.close();
      });
    });

    3. After this, run below command into your terminal and see the output:

    $ node testcode.js
    node output with data

    Now this is it, if you have any query related to this post then do comment below or ask question.

    Thank you,

    ludhiana wala ajay,

    TheRichPost

  • Vue Laravel Image Upload

    Vue Laravel Image Upload

    Hello to all, welcome to therichpost.com. In this post, I will do, Vue Laravel Image Upload.

    I have shared the multiple image upload in laravel and now I will upload the image into laravel folder with the help of vuejs and I have done this easily.

    Here I am sharing some working images:

     




    Now come to the coding point and here are steps need to follow:

     

    1. Here are some basics commands need to run into terminal to install laravel setup and node modules for vuejs:

    $ composer create-project –prefer-dist laravel/laravel vuelaraveluploadimage

    $ cd vuelaraveluploadimage

    $ npm install

    $ composer create-project --prefer-dist laravel/laravel vuelaraveluploadimage
    $ cd vuelaraveluploadimage
    $ npm install

     

    2. Now, here is the below code, you need to add into your resources\js\components\ExampleComponent.vue file:

    I have used axios post method to upload file and this behaves like ajax:

    <template>
        <div class="container">
            <h2>Vue Laravel Image Upload</h2>
            <form @submit="checkForm" ref="myForm">
            <div class="form-group">
                <label for="email">Upload Profile Pic:</label>
                <input type="file" name="profile_pic" id="profile_pic">
            </div>
            <button type="submit" class="btn btn-default">Submit</button>
            </form>
        </div>
    </template>
    
    <script>
        export default {
            methods:{
                checkForm: function (e) {
                    var myFormData = new FormData(this.$refs.myForm)
                    axios({
                        method: 'post',
                        url: '/vueuploadimage',
                        data: myFormData,
                        config: { headers: {'Content-Type': 'multipart/form-data' }},
                    }).then(function (response) {
                      alert(response.data.message);
                    });
                    e.preventDefault();
                }
            },
        }
    </script>

     

    3. Now, here is the below code, you need to add into resources\js\app.js file:
    require('./bootstrap');
    window.Vue = require('vue');
    import "bootstrap/dist/css/bootstrap.css";
    Vue.component('example-component', require('./components/ExampleComponent.vue'));
    const app = new Vue({
        el: '#app'
    });

     

    4. Now here is the code, you need to add into your resources\views\welcome.blade.php file:
    <div id="app"><example-component></example-component></div>     
    <script src="{{asset('js/app.js')}}"></script>

     

    5. Now here is the code, you need to add into your routes/web.php file:
    Route::post("/vueuploadimage" , "Controller@uploadimage");

     

    6. Now here is the code, you need to add into your app\Http\Controllers\Controller.php file:

    In this file, I have wrote the file upload code in folder and also please img folder into public folder:

    ...
    use Illuminate\Http\Request;
    public function uploadimage(Request $request)
        {
        	if ($request->hasFile('profile_pic'))
        	{
                $file      = $request->file('profile_pic');
                $filename  = $file->getClientOriginalName();
                $extension = $file->getClientOriginalExtension();
                $picture   = date('His').'-'.$filename;
                $file->move(public_path('img'), $picture);
                return response()->json(["message" => "Image Uploaded Succesfully"]);
        	} 
          else
          {
              	return response()->json(["message" => "Select image first."]);
          }
        }
    ...

     

    7. After all above set up, run php artisan serve command into your terminal and check the Vue laravel Image Upload working and if you have any query related to this post then do comment below or ask questions.

    Thank you,

    Ludhiane wala ajay,

    TheRichPost

  • Vue Laravel Auth Login

    Vue Laravel Auth Login

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Vue Laravel Auth Login.

    Vue laravel combination is very good for spa(single page application). In this post, we will login laravel auth with vuejs and this is very interesting.

    Also I have added vue form validation in it.

    Here are the some working images:

    Vue Laravel Auth Login
    vue input fields validation
    Vue laravel auth Login Success
    Now come to the coding area. Every laravel developer knows laravel default auth or if you don’t familiar with this then please check this below link:

    How to Setup Laravel Default Login Authentication?

     

    Now here are the coding steps you need to follow for Vue Laravel Auth Login:

     

    1. Here are the some basic commands to you need to run into your terminal to install fresh laravel setup and vue setup:
    $ composer create-project --prefer-dist laravel/laravel vuelaravelauthlogin //install fresh laravel setup
    $ cd vuelaravelauthlogin //go laravel setup
    $ npm install //node modules for vuejs
    

     

    2. Now, here is the below code, you need to add into your resources\js\components\ExampleComponent.vue file:

    In this file, you can see, I have added vue form validation and I have used axios.post to send the vue form data to laravel controller:

    <template>
        <div class="container">
            <div class="row justify-content-center">
                <div class="page-header">
                  <h2>Vue Laravel Auth Login</h2>
                </div>
                <div class="col-md-12 text-center">
                    <p v-if="errors.length">
                        <b>Please correct the following error(s):</b>
                        <ul class="list-group">
                          <li v-for="error in errors" class="list-group-item list-group-item-danger">{{ error }}</li>
                        </ul>
                    </p>
                </div>
                <div class="col-md-6" v-if="loginfalse = true">
                    <form @submit="checkForm" id="createAdministrator">
                      <div class="form-group">
                        <label for="email">Email address:</label>
                        <input v-model="email" type="email" class="form-control" id="email" placeholder="Enter Email" name="email">
                      </div>
                      <div class="form-group">
                        <label for="pwd">Password:</label>
                        <input v-model="password" type="password" class="form-control" id="password" placeholder="********" name="password">
                      </div>
                      <button type="submit" class="btn btn-default">Submit</button>
                    </form>
                </div>
            </div>
        </div>
    </template>
    
    <script>
        export default {
            mounted() {
                console.log('Component mounted.')
            },
    
             data() {
                return {
                    errors: [],
                    state: {
                        email: '',
                        password: ''
                    }
                }
            },
            methods:{
            checkForm: function (e) {
               
              this.errors = [];
              if (!this.email) {
                this.errors.push('Email required.');
              }
              if (!this.password) {
                this.errors.push('Password required.');
              }
            else
            {
            var formContents = jQuery("#createAdministrator").serialize();
            
            
              axios.post('/vuelogin', formContents).then(function(response, status, request) {  
                                alert(response.data.user);
                            
                            
                        }, function() {
                            console.log('failed');
                        });
            }
            
              e.preventDefault();
            }
          }
        }
    </script>

     

    3. Now, here is the below code, you need to add into resources\js\app.js file:
    require('./bootstrap');
    import "bootstrap/dist/css/bootstrap.css";
    window.Vue = require('vue');
    Vue.component('example-component', require('./components/ExampleComponent.vue'));
    const app = new Vue({
        el: '#app'
    });

     

    4. Now here is the code, you need to add into your  resources\views\welcome.blade.php file:
    <div id="app"><example-component></example-component></div>
    <script src="{{asset('js/app.js')}}"></script>

     

    5. Now here is the code, you need to add into your routes/web.php file:
    Route::post('/vuelogin', 'Auth\LoginController@vuelogin');

     

    6. Now here is the code, you need to add into your app\Http\Controllers\Auth\LoginController.php file:
    <?php
    
    namespace App\Http\Controllers\Auth;
    
    use App\Http\Controllers\Controller;
    use Illuminate\Foundation\Auth\AuthenticatesUsers;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Auth; 
    use App\User;
    class LoginController extends Controller
    {
        /*
        |--------------------------------------------------------------------------
        | Login Controller
        |--------------------------------------------------------------------------
        |
        | This controller handles authenticating users for the application and
        | redirecting them to your home screen. The controller uses a trait
        | to conveniently provide its functionality to your applications.
        |
        */
    
        use AuthenticatesUsers;
    
        /**
         * Where to redirect users after login.
         *
         * @var string
         */
        protected $redirectTo = '/home';
    
        /**
         * Create a new controller instance.
         *
         * @return void
         */
        public function __construct()
        {
            $this->middleware('guest')->except('logout');
        }
    
        public function vuelogin(Request $request)
        {
            if(Auth::attempt(['email' => $request->email, 'password' => $request->password])){ 
              $user                  = Auth::user();
              $username = $user->name;
              return response()->json([
                'status'   => 'success',
                'user' => $username,
    
              ]); 
            } else { 
              return response()->json([
                'status' => 'error',
                'user'   => 'Unauthorized Access'
              ]); 
            } 
        }
    }

     

    7. Don’t forget to add your database details into your .env file. After all above set up, run php artisan serve command into your terminal and check the Vue laravel Auth Login working and if you have any query related to this post then do comment below or ask questions.

    Thank you,

    Ludhiane wala ajay,

    TheRichPost

  • Vue Laravel Chart js with Dynamic Data

    Vue Laravel Chart js with Dynamic Data

    Hello to all, welcome to therichpost.com. In this post, I will share with you, Vue Laravel Chart js with Dynamic Data.

    I have shared many post related to Vue laravel and this is also for same topic.

    In this post, I will show laravel dynamic data into chart js bar chart added in vuejs component.

    Here is the working picture:

    Vue Laravel Chart js with Dynamic Data

    Here is the working coding steps need to follow, please do steps wise if you want good results:

    1. Here are the basics command to install fresh laravel setup on your machine:

    $ composer create-project --prefer-dist laravel/laravel blogvuechartjs //install frest laravel setup
    
    $ cd blogvuechartjs // go inside laravel setup

    2. Here are the important commands, you need to run into your terminal to install chart js:

    $ npm install //install node modules
    
    $ npm install vue-chartjs chart.js --save //install chartjs package

    3. After run above commands, now we will move coding area and I must tell you, laravel gives us default vue setup and this is the best thing and here you can find vue setup inside laravel:

    vuefiles

    4. Now, here is the below code, you need to add into your resources\js\components\ExampleComponent.vue file:

    <template>
    <div class="container">
    <center><h1>Vue laravel Chartjs</h1></center>
               <canvas ref="chart"></canvas>
           </div>
    </template>
    
    <script>
        export default{
            mounted() {
            let uri = 'http://localhost:8000/chartjs';
            axios.get(uri).then((response) => {
            var chart = this.$refs.chart;
                var ctx = chart.getContext("2d");
                var myChart = new Chart(ctx, {
                    type: 'bar',
                    data: {
                        labels: response.data.month,
                        datasets: [{
                            label: '# of Votes',
                            data: response.data.data,
                            borderWidth: 1
                        }]
                    },
                    options: {
                        scales: {
                            yAxes: [{
                                ticks: {
                                    beginAtZero: true
                                }
                            }]
                        }
                    }
                });
            }).catch(error => {
            console.log(error)
            this.errored = true
          });
            }
        }
    </script>

    5. Now, here is the below code, you need to add into resources\js\app.js file:

    require('./bootstrap');
    window.Vue = require('vue');
    import axios from 'axios';
    Vue.use(axios);
    import {Bar} from 'vue-chartjs';
    Vue.component('example-component', require('./components/ExampleComponent.vue'));
    
    const app = new Vue({
        el: '#app'
    });
    

    6. Now, here is the below code, you need to add app\Http\Controllers\Controller.php file:

    ....
    public function Chartjs(){
        $month = array('Jan', 'Feb', 'Mar', 'Apr', 'May');
        $data  = array(1, 2, 3, 4, 5);
        return response()->json(['month' => $month, 'data' => $data]);
      }
    ....

    7. Now. here is the code, you need to add routes\web.php file:

    Route::get("/chartjs", "Controller@Chartjs");

    8. Now here is the code, you need to add into your  resources\views\welcome.blade.php file:

    <div id="app"><example-component></example-component></div>
    <script src="{{asset('js/app.js')}}"></script>

    Now you are done and if you have any query related to this post, then do comment below or ask question.

    Thank you,

    Jatt,

    TheRichPost

    Note: Every Post has been made by heart.

  • How to Save Angular 7 Form Data into Php Mysql with Laravel 5.7?

    How to Save Angular 7 Form Data into Php Mysql with Laravel 5.7?

    Hello to all, welcome to therichpost.com. In this post, I will tell you, How to Save Angular 7 Form Data into Php Mysql with Laravel 5.7?

    Angular 7 and Laravel 5.7 both are launched recently. Both came with new features. Today we will save Angular 7 form data into Php MySQL database with the help of Laravel 5.7. 

     

    Here are the some working example pictures:

     

     

    Save Angular 7 Form Data into Php Mysql with Laravel 5.7

     

    In this post, I have used Bootstrap 4 for responsive layout, Angular 7 Reactive form module, Angular 7 HttpClient Module for sending and receiving data.  For add Bootstrap 4 into your Angular 7 app, you can get this from :

     https://therichpost.com/add-bootstrap-4-to-angular-6

    For backend, I have used laravel 5.7 Api’s for get Angular 7 data and save it into Php Mysql Database.

     

    Here is the working and tested code you need to follow:

     

    1. Very first, you need to run common below commands to add Angular 7 project on your machine:

    $ npm install -g @angular/cli 
    
    $ ng new angulardatasavelaravel //Install Angular Project
    
    $ cd angulardatasavelaravel // Go to project folder
    
    $ ng serve //Run Project
    
    http://localhost:4200/ //Run On local server

    2. Now you need to add the below code into your app.module.ts file:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { AppComponent } from './app.component';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { ReactiveFormsModule } from '@angular/forms';
    import { HttpClientModule } from '@angular/common/http';
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
      BrowserAnimationsModule,
      ReactiveFormsModule,
      HttpClientModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

    3. Now you need to add below code into your Angular 7 app.component.ts file: 

    import {Component} from '@angular/core';
    import { FormBuilder, FormGroup, Validators } from '@angular/forms';
    import { HttpClient, HttpParams } from '@angular/common/http';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      registerForm: FormGroup;
      submitted = false;
    
        constructor(private formBuilder: FormBuilder, private http: HttpClient) { }
    
        ngOnInit() {
            this.registerForm = this.formBuilder.group({
                firstName: ['', Validators.required],
                email: ['', [Validators.required, Validators.email]],
            });
        }
    
        // convenience getter for easy access to form fields
        get f() { return this.registerForm.controls; }
        onSubmit() {
            this.submitted = true;
    
            // stop here if form is invalid
            if (this.registerForm.invalid) {
                return;
            }
        // Initialize Params Object
        let Params = new HttpParams();
    
        // Begin assigning parameters
        Params = Params.append('firstParameter', this.registerForm.value.firstName);
        Params = Params.append('secondParameter', this.registerForm.value.email);
        return this.http.post('http://localhost/laravel57/public/api/adduserdetails'
        ,{
        params: { params: Params }
        }).subscribe((res: Response) => {
            alert(res);
        //this.registerForm.reset();
          })
        
          
        }
      
    }

    4. Now you need to add into your Angular 7 app.component.html file:

    <div class="jumbotron text-center">
      <h1>Angular 7 Save Form Data into PhpMysql with Laravel 5.7
    </h1>
    </div>
        <div class="container">
            <div class="row">
                <div class="col-md-6 offset-md-3">
                    <form [formGroup]="registerForm" (ngSubmit)="onSubmit()">
                        <div class="form-group">
                            <label>First Name</label>
                            <input type="text" formControlName="firstName" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.firstName.errors }" />
                            <div *ngIf="submitted && f.firstName.errors" class="invalid-feedback">
                                <div *ngIf="f.firstName.errors.required">First Name is required</div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>Email</label>
                            <input type="text" formControlName="email" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.email.errors }" />
                            <div *ngIf="submitted && f.email.errors" class="invalid-feedback">
                                <div *ngIf="f.email.errors.required">Email is required</div>
                                <div *ngIf="f.email.errors.email">Email must be a valid email address</div>
                            </div>
                        </div>
                        <div class="form-group">
                            <button class="btn btn-primary">Submit</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

    5. Laravel Code Start:

     

    6. Here is the code for your laravel 5.7 routes/api.php file:

    Route::post("/adduserdetails", "UserDetailsController@userDetails");

    7. H ere is the command you need to run to make new laravel contoller file:

    $ php artisan make:controller UserDetailsController

    8. Now you need to all below  code into app\Http\Controllers\UserDetailsController.php file:

    <?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use DB;
    
    class UserDetailsController extends Controller
    {
        public function userDetails(Request $req)
      {
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Methods: PUT, GET, POST");
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
        foreach($req->params as $postdata)
        {
          $datainserted = DB::table('userdata')->insert(
          ['name' => $postdata['updates'][0]['value'], 'email' => $postdata['updates'][1]['value']]
            );
          if($datainserted)
          {
            return response()->json("Data Added Successfully");
          }
        }
        
      }
    }

    Now run your Angular project and save your angular data into laravel database and don’t forget to add your database details into laravel .env file.

    if you have any query related to this post, then do comment below or ask question.

    Thank you,

    Jassa Put,

    TheRichPost

     

  • How to implement Fullcalendar in Vue Laravel?

    How to implement Fullcalendar in Vue Laravel?

    Hello dev’s, welcome to therichpost.com. In this post, I will tell you, How to implement Fullcalendar in Vue Laravel?

    I have wrote many posts related to full-calendar and Now I will implement full-calendar in Vue Laravel and this is interesting.

    Here I am showing the working picture of full calendar in Vue Laravel web app:

     

    How to implement Fullcalendar in Vue Laravel

     

    Vue and laravel combination is the best and I have done lots of working examples in my blog.

    Here is the working and tested coding steps for implement Fullcalendar in Vue Laravel:

     

    1. Here are the basics command to install fresh laravel setup on your machine:

    $ composer create-project --prefer-dist laravel/laravel blogvuefullcalendar
    
    $ cd blogvuefullcalendar

    2. Now here are the some npm commands you need to run into your terminal to install node module and fullcalendar:

    $ npm install //install node modules
    
    $ npm install --save vue-full-calendar //install full calendar
    
    $ npm install --save babel-runtime //full calendar dependency
    
    $ npm install babel-preset-stage-2 --save-dev //full calendar dependency

    3. Now, you need to add below code into resources\js\app.js file:

    /**
     * First we will load all of this project's JavaScript dependencies which
     * includes Vue and other libraries. It is a great starting point when
     * building robust, powerful web applications using Vue and Laravel.
     */
    
    require('./bootstrap');
    import 'fullcalendar/dist/fullcalendar.css';
    window.Vue = require('vue');
    import FullCalendar from 'vue-full-calendar'; //Import Full-calendar
    Vue.use(FullCalendar);
    
    
    /**
     * The following block of code may be used to automatically register your
     * Vue components. It will recursively scan this directory for the Vue
     * components and automatically register them with their "basename".
     *
     * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
     */
    
    Vue.component('example-component', require('./components/ExampleComponent.vue'));
    
    // const files = require.context('./', true, /\.vue$/i)
    // files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key)))
    
    /**
     * Next, we will create a fresh Vue application instance and attach it to
     * the page. Then, you may begin adding components to this application
     * or customize the JavaScript scaffolding to fit your unique needs.
     */
    
    const app = new Vue({
        el: '#app'
    });

    4. Now, you need to add below code into resources\js\components\ExampleComponent.vue file:

    <template>
        <div class="container">
            <div class="row justify-content-center">
                <div class="col-md-8">
                    <div class="card card-default">
                        <full-calendar :events="events"></full-calendar>
                    </div>
                </div>
            </div>
        </div>
    </template>
    
    <script>
        export default {
        data() {
        return {
        events: [
        {
        title : ‘event1’,
        start : ‘2018-12-13’,
        }
        ]
        }
        },
        mounted() {
        console.log(‘Component mounted.’)
        }
      }
    </script>

    5. Now, you need to add below code into resources\views\welcome.blade.php file:

    <div id="app"><example-component></example-component></div>
    <script src="{{asset('js/app.js')}}"></script>

    6. Finally, you need to run below command into your terminal and you will see working full calendar example:

    $ php artisan serve

    This is it. If you have any query related to this post, then do comment below or ask questions.

    Thank you,

    Bullet Jatt Da,

    TheRichpost