Year: 2018

  • 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

  • Laravel Socialite for Github Login

    Laravel Socialite for Github Login

    Hello to all, welcome to therichpost.com. In this post, I will share working example of Laravel Socialite for Github  Login.

    I personally like Laravel Socialite package very much. With the help of Laravel Socialite package, we can easily login to laravel app with github account details and this is very easy to implement.

    Laravel also provides a simple, convenient way to authenticate with OAuth providers using Laravel Socialite. Socialite currently supports authentication with Facebook, Twitter, LinkedIn, Google, GitHub, GitLab and Bitbucket.

    Here are the working and tested coding step need to follow:

    1. Installation:

    To get started with Socialite, use Composer to add the package to your project’s dependencies: Run this command into your terminal:

    composer require laravel/socialite

    2. Configuration:

    Before using Socialite, you will also need to add credentials for the OAuth services your application utilizes. These credentials should be placed in your config/services.php configuration file, and should use the key facebook, twitter, linkedin, google, github, gitlab or bitbucket, depending on the providers your application requires. For example:

    ...
    'github' => [
        'client_id' => env('GITHUB_CLIENT_ID'),         // Your GitHub Client ID
        'client_secret' => env('GITHUB_CLIENT_SECRET'), // Your GitHub Client Secret
        'redirect' => env('GITHUB_REDIRECT'),
    ],
    ...

    3. After successful installation, time to update the provider and aliases in the default configuration file located at “config/app.php”.

    'providers' => [
        // Other service providers...
        Laravel\Socialite\SocialiteServiceProvider::class,
    ],
    'aliases' => [
        // aliases
        'Socialite' => Laravel\Socialite\Facades\Socialite::class,
    ]

    4. Routing:

    Next, you are ready to authenticate users! You will need two routes: one for redirecting the user to the OAuth provider, and another for receiving the callback from the provider after authentication. We will access Socialite using the Socialite facade. Create new controller file SocialAuthController.php in app\Http\Controllers folder and add below code into it:

    <?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use Socialite;
    class SocialAuthController extends Controller
    {
        public function redirect() {
    
             return Socialite::driver('github')->redirect();
        }
        public function callback() {
            $user = Socialite::with ( 'github' )->user ();
            return view ( 'home' )->withDetails ( $user )->withService ( 'github' );
        }
    }

    The redirect method takes care of sending the user to the OAuth provider, while the user method will read the incoming request and retrieve the user’s information from the provider. Of course, you will need to define routes to your controller methods in routes/web.php file:

    Route::get ( '/redirect/github', 'SocialAuthController@redirect' );
    Route::get ( '/callback/github', 'SocialAuthController@callback' );

    5. Now add below code into your .env file to add variables value, which we add ablove into service.php file:

    .env
    GITHUB_CLIENT_ID = ***********************
    GITHUB_CLIENT_SECRET = *************************
    GITHUB_REDIRECT = 'http://127.0.0.1:8000/callback/github'
    6. After all this done, run php artisan serve command into your terminal and run below url into your browser and your will be login with github id:
    http://127.0.0.1:8000/redirect/github

    7. Here are some working laravel working application and github user profile images to get github client id and client secret information and set callback url in github app setting area:

    Laravel Socialite for Github Login

    Laravel github

    If you have any query related to this post, then do let me know.

    Thank you,

    Jatt Brand,

    TheRichPost

    Note: Save Birds, Save Nation.

  • How to show custom tooltip on Ng Fullcalendar Events?

    How to show custom tooltip on Ng Fullcalendar Events?

    Hello to all, welcome to therichpost.com. Today In this post, I will show working example for How to show custom tooltip on Ng Fullcalendar Events?

    Fullcalendar is very popular for events management and scheduling meeting or future works.

    Today In this post, I will show custom tooltip, when you will mouseover on fullcalendar events. I have done to many working example in ng-fullcalendar  and I am doing this in Angular 7 and for angular 8 please check the below link:

    https://therichpost.com/angular-8-fullcalendar-event-tooltip/

    Here is the working example:

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

    1. Very first, here are the some basics commons commands to include Angular 7 Application on your machine:

    $ npm install -g @angular/cli
    
    $  ng new angularfullcalendar  // Set Angular7 Application on your pc
    
    $ cd angularfullcalendar // Go inside project folder
    
    $ ng serve // Run project
    
    http://localhost:4200/ //Check working Local server

    2. Now, run below command into your terminal, to include fullcalendar module into your Angular 7 app:

    npm install ng-fullcalendar --save

    3. Now run below command into your terminal to update your update your types/jquery(optional):

    npm update @types/jquery

    4. Now add 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 { FullCalendarModule } from 'ng-fullcalendar';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
      FullCalendarModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

    5. Now add below command into your app.component.ts file:

    import { Component } from '@angular/core';
    
    import { CalendarComponent } from 'ng-fullcalendar';
    
    import { Options } from 'fullcalendar';
    
    @Component({
    
      selector: 'app-root',
    
      templateUrl: './app.component.html',
    
      styleUrls: ['./app.component.css']
    
    })
    
    export class AppComponent {
    
      title = 'my-angular-app';
    
      calendarOptions: Options;
    
      ngOnInit() {
    
      this.calendarOptions = {
    
            editable: true,
    
            eventLimit: false,
    
            header: {
    
              left: 'prev,next today',
    
              center: 'title',
    
              right: 'month,agendaWeek,agendaDay,listMonth'
    
            }
    
            
    
          };
    
      } 
    
       //Add tooltip to events  
       eventrender(event, element)
        {
           event.element[0].querySelectorAll(".fc-content")[0].setAttribute("data-tooltip", event.event.title);
        }
    
    }

    6. Now 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">
    
      <h1>
    
        Welcome to {{ title }}!
    
      </h1>
    
      <div *ngIf="calendarOptions">
    
       <ng-fullcalendar #ucCalendar [options]="calendarOptions" (eventClick)="eventClick($event.detail)" (eventDrop)="updateEvent($event.detail)"
    
            (eventResize)="updateEvent($event.detail)" (clickButton)="clickButton($event.detail)" (eventRender)="eventrender($event.detail)"></ng-fullcalendar>
    
    </div>
    
    
    </div>

    7. Now add below code into styles.css file:

     .fc-content {
      cursor: pointer;
      position: relative;
      overflow: visible!important;
    }
    
    .fc-content::before {
      position: absolute;
      top: -64px;
      left: -4px;
      background-color: #000;
      border-radius: 5px;
      color: #fff;
      content: attr(data-tooltip);
      padding: 1rem;
      text-transform: none;
      -webkit-transition: all 0.5s ease;
      transition: all 0.5s ease;
      width: 160px;
    }
    
    .fc-content::after {
      position: absolute;
      top: -13px;
      right: 0px;
      border-left: 5px solid transparent;
      border-right: 5px solid transparent;
      border-top: 5px solid #000;
      content: " ";
      font-size: 0;
      line-height: 0;
      margin-left: -5px;
      width: 0;
    }
    
    .fc-content::before,
    .fc-content::after {
      color: #efefef;
      font-family: monospace;
      font-size: 16px;
      opacity: 0;
      pointer-events: none;
      text-align: center;
    }
    
    .fc-content:hover::before,
    .fc-content:hover::after {
      opacity: 1;
      -webkit-transition: all 0.75s ease;
      transition: all 0.75s ease;
    }

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

    Thank you,

    Harjas,

    TheRichPost

    Notes: This post is just for solve full-calendar tooltip issue with simple custom code.

  • Angular 7 Flash Messages

    Angular 7 Flash Messages

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 7 Flash Messages.

    Angular 7 Has lots of new features and I will share this all. I have shown very simple example and everyone can understand this.

     

    Here is the working image:

    Angular 6 Flash Messages

     Angular provides us so many default features and Flash Message is one of them.

    Here are the steps, you need to follow for Angular Flash Messages:

     

    1. First, you need to run below command into your terminal to add Angular Flash Message Package into your Angular 7 App:
    npm install angular2-flash-messages --save

     

    2. After add 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 { FlashMessagesModule } from 'angular2-flash-messages';
    
    @NgModule({
      declarations: [AppComponent],
      imports: [
        BrowserModule,
      FlashMessagesModule.forRoot(),
      
      ],
      entryComponents: [AppComponent],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

     

    3. After this, you need to add below code into app.component.ts file:
    import {Component} from '@angular/core';
    import { FlashMessagesService } from 'angular2-flash-messages';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
    constructor(private flashMessage: FlashMessagesService) { }
      
      showFlash() {
            // 1st parameter is a flash message text
            // 2nd parameter is optional. You can pass object with options.
            this.flashMessage.show('Welcome To TheRichPost.com', { cssClass: 'alert-success', timeout: 2000 });
        }
    }

     

    4. After it, you need to add below code into your app.component.html file:

    On button click event, flash message will be shown:

    <div class="jumbotron text-center">
      <h1>Angular Flash Messages
    </h1>
    </div>
    <button type="button" (click) = "showFlash()" class="btn btn-primary">Show Flash Messages</button>
    <flash-messages></flash-messages><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

     Now you are done. If you have any query related to this post, then please ask questions or comment below.

    Thank you,

    Jatt,

    TheRichPost