Category: Laravel 6

  • Angular 8 with laravel 6 php mysql data

    Angular 8 with laravel 6 php mysql data

    Hello to all, welcome to therichpost.com. In this post, I will tell you, angular 8 with laravel 6 php mysql data.

    If you are new in Angular 8 or Laravel 6 then you can check my old posts.

    Angular 8 with laravel 6 php mysql data
    Angular 8 with laravel 6 php mysql data

    Here is the complete working code and please use this carefully:

    1. Let start, here are the basics commands to set Angular 8 into your pc:

    $ npm install -g @angular/cli //Setup Angular8 atmosphere
    
    $ ng new angular8phpmyadmindatabse//Install New Angular App
    
    /**You need to update your Nodejs also for this verison**/
    
    $ cd angular8phpmyadmindatabse//Go inside the Angular 8 Project

     

    2. After all above setup, here is code, you need to add into your 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';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        HttpClientModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

     

    3. Here is the code, you need to add app.component.ts file:

    This is laravel project path(http://localhost/laravel57/public/api/sample-restful-apis)where I have set the api from where I am getting the data.

    import { Component } from '@angular/core';
    import { HttpClient } from '@angular/common/http';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'angular8restapi';
      data = [];
      constructor(private http: HttpClient) {
        this.http.get('http://localhost/laravel57/public/api/sample-restful-apis').subscribe(data => {
        this.data.push(data);
        console.log(this.data);
        }, error => console.error(error));
      }
    }

     

    4. Here is the code you need to add into app.component.html file:

    <table>
        <tr>
          <th>Name</th>
          <th>Domain</th>
          
        </tr>
        <tr *ngFor="let mydata of data[0]">
          <td>{{mydata.name}}</td>
          <td>{{mydata.domain}}</td>
        </tr>
    </table>

     

    5. Here is the code, you need add into app.component.css file:

    table {
        font-family: arial, sans-serif;
        border-collapse: collapse;
        width: 100%;
      }
      
      td, th {
        border: 1px solid #dddddd;
        text-align: left;
        padding: 8px;
      }
      
      tr:nth-child(even) {
        background-color: #dddddd;
      }

     

    Laravel Code

    1. Here is the code, you need to into your laravel 6 api.php file, where we will set the route:

    Route::get('/sample-restful-apis','HomeController@getData');

     

    2. Here is the code, you need to laravel57\app\Http\Controllers\HomeController.php file:

    use DB;
    
    class HomeController extends Controller
    {
    ...
    
    
    public function getData()
        {
             $domains = DB::table('emplyee')
            ->select('*')
            ->get(); // you were missing the get method
            return response()->json($domains);
        }
    
    
    ...
    }

     

    In the end here are some important notes to run this all:

    1. Don’t forget to run ng serve command into your terminal.

    2. Don’t forget to start your xampp.

    3. Don’t forget to add your database details into laravel .env file.

    For more information like database and database connectivity and file structure please check this video related to this post.

    Jassa

    Thank you

  • Laravel 6 vue bootstrap owl carousel working example

    Laravel 6 vue bootstrap owl carousel working example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Laravel 6 vue bootstrap owl carousel working example.

    Vue Laravel Bootstrap Owl Carousel Working Example

    Here are the basics steps and coding and please use this carefully:

    1. Before using Laravel, make sure you have Composer installed on your machine.

    2. Now run below command to download laravel installer:

    composer global require laravel/installer

     

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

    composer create-project --prefer-dist laravel/laravel vuelaraveowlcarousel
    
    cd vuelaraveowlcarousel // go inside laravel 6 setup
    npm install // for node setup

     

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

    ...
    
    import 'bootstrap/dist/css/bootstrap.min.css';
    import 'bootstrap/dist/js/bootstrap.min.js';
    
    ...

     

    5. 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">
                     <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>

     

    6. 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>

     

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

    //In first terminal run
    npm run watch
    
    //In second terminal run
    php artisan serve

     

    And you will see working bootstrap owl carousel in laravel 6 vue and if you have any query regarding to this post then please do comment below.

    Jassa Jatt

    Thank you

  • Laravel 6 vuejs fullcalendar working example

    Laravel 6 vuejs fullcalendar working example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Laravel 6 vuejs fullcalendar working example.

    After some time, I will also share youtube working video on this tutorial.

    How to implement Fullcalendar in Vue Laravel with dynamic Events
    Laravel 6 vuejs fullcalendar working example

    Laravel 6 has been released and this laravel 6 has many good features but today I am going to show you working full calendar in Laravel Vue combination and this coming experience was very interesting for me.

    Laravel is the best php mvc framework and vuejs the best in making single page applications.


    Here are the working code snippet and please use this very carefully:


    1. Before using Laravel, make sure you have Composer installed on your machine.

    2. Now run below command to download laravel installer:

    composer global require laravel/installer

     

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

    composer create-project --prefer-dist laravel/laravel fullcalendarvuelaravel
    cd fullcalendarvuelaravel // go inside laravel 6 setup

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

    $ npm install
    
    
    $ npm install --save vue-full-calendar
    
    
    $ npm install --save babel-runtime
    
    
    $ npm install babel-preset-stage-2 --save-dev
    
    
    $ npm install moment --save

     

    5. 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'
    });

     

    6. 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>

     

    7. 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>

     

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

    //In first terminal run
    npm run watch
    
    //In second terminal run
    php artisan serve

     

    And you will see working fullcalendar in laravel 6 vue and if you have any query regarding to this post then please do comment below.

    Jassa Jatt

    Thank you

  • Angular 8 Grouped Bar chart using data Laravel 6 REST API

    Angular 8 Grouped Bar chart using data Laravel 6 REST API

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 8 Grouped Bar chart using data Laravel 6 REST API.

    Today, I am going to show Chartjs Bar Chart in Angular 8 and data is coming from Laravel 6 Rest API.

    This is Part 1 because in next part I will show multiple data working with arrays.


    Angular 8 Grouped Bar chart using data Laravel 6 REST API
    Angular 8 Grouped Bar chart using data Laravel 6 REST API

    Here is the working code snipped please use this carefully:


    1. Here are the basics commands, you need to use into your terminal or command prompt to install Angular 8 fresh set up:

    $ npm install -g @angular/cli //Setup Angular8 atmosphere
    
    $ ng new angular8chartjs //Install New Angular App
    
    /**You need to update your Nodejs also for this verison**/
    
    $ cd angular8chartjs //Go inside the Angular 8 Project

    2. After Install Angular 8 fresh setup and go inside the Angular 8 setup, run below command into your terminal to install chartjs module:

    npm install --save chart.js

    3. After all above setup, here is code, you need to add into your app.component.ts file:

    I have used Angular HTTPCLIENT to get data from third party or other site.

    import { Component } from '@angular/core';
    import * as Chart from 'chart.js';
    import { HttpClient } from '@angular/common/http';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'angular8chartjs';
      canvas: any;
      ctx: any;
      data = [];
      constructor(private http: HttpClient) {
        this.http.get('http://localhost/blog/public/api/sample-restful-apis').subscribe(data => {
        this.data.push(data);
        console.log(this.data);
        this.canvas = document.getElementById('myChart');
        this.ctx = this.canvas.getContext('2d');
        let myChart = new Chart(this.ctx, {
          type: 'bar',
          data: {
              labels: [this.data[0]['month']],
              datasets: [{
                  label: '# of Votes',
                  data: [this.data[0]['sale']],
                  backgroundColor: [
                      'rgba(255, 99, 132, 1)',
                      'rgba(54, 162, 235, 1)',
                      'rgba(255, 206, 86, 1)'
                  ],
                  borderWidth: 1
              }]
          },
          options: {
            responsive: false,
            display:true
          }
        });
        }, error => console.error(error));
      }
    }

    4. Now, here is code, you need to add into your 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';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        HttpClientModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

    5. Now, add below code into your app.component.html file:

    <canvas id="myChart" width="700" height="400"></canvas>

    6. Here is laravel API code in routes/api.php file , from where I am getting the data:

    Route::get('sample-restful-apis', function()
    {
        return response()->json(
            ['month' => 'january', 'sale' => '100']
        );
    });

    In the last, don’t forget to run ng serve command and don’t forget to turn on xampp server.

    This is it and if you have any query related to this post then please do comment below.

    Jassa Jatt

    Thank you

  • Angular 8 with laravel 6 backend working example

    Angular 8 with laravel 6 backend working example

    Hello to all, welcome to therichpost.com. Today, In this post, I will tell you, Angular 8 with laravel 6 backend working example.

    Both Angular 8 and Laravel 6 are the best on their platforms. Today, In this post, I will take Angular 8 as frontend and Laravel 6 as backend.

    If you are new then you can check my old posts related to Laravel 6 and Angular 8.

    Here is the images showing of Angular 8 frontend in which I am getting data from laravel 6.

    Angular 8 with laravel 6 backend working example
    Angular 8 with laravel 6 backend working example

    Here are the complete code snippet for Angular 8 with laravel 6 backend working example and please use this carefully:

    1. Let start, here are the basics commands to set Angular 8 into your pc:

    $ npm install -g @angular/cli //Setup Angular8 atmosphere
    
    $ ng new angularlatest8 //Install New Angular App
    
    /**You need to update your Nodejs also for this verison**/
    
    $ cd angularlatest8 //Go inside the Angular 8 Project

     

    2. After all above setup, here is code, you need to add into your 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';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        HttpClientModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

     

    3. Here is the code, you need to add app.component.ts file:

    This is laravel project path(http://localhost/blog/public/api/sample-restful-apis)where I have set the api from where I am getting the data.

    import { Component } from '@angular/core';
    import { HttpClient } from '@angular/common/http';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'angular8restapi';
      data = [];
      constructor(private http: HttpClient) {
        this.http.get('http://localhost/blog/public/api/sample-restful-apis').subscribe(data => {
        this.data.push(data);
        console.log(this.data);
        }, error => console.error(error));
      }
    }

     

    4. Here is the code you need to add into app.component.html file:

    <table>
        <tr>
          <th>Name</th>
          <th>Domain</th>
          
        </tr>
        <tr *ngFor="let mydata of data[0]">
          <td>{{mydata.name}}</td>
          <td>{{mydata.domain}}</td>
        </tr>
    </table>

     

    5. Here is the code, you need add into app.component.css file:

    table {
        font-family: arial, sans-serif;
        border-collapse: collapse;
        width: 100%;
      }
      
      td, th {
        border: 1px solid #dddddd;
        text-align: left;
        padding: 8px;
      }
      
      tr:nth-child(even) {
        background-color: #dddddd;
      }

     

     

    6. Here is the final code, you need to into your laravel 6 api.php file, where we will have the data to show in angular 8 application:

    ...
    Route::get('sample-restful-apis', function()
    {
        return response()->json([
            [
                'name' => 'Google',
                'domain' => 'Google.com'
            ],[
                'name' => 'Google',
                'domain' => 'Google.com'
            ],[
                'name' => 'Google',
                'domain' => 'Google.com'
            ],[
                'name' => 'Google',
                'domain' => 'Google.com'
            ],[
                'name' => 'Google',
                'domain' => 'Google.com'
                ]
            ]);
    });
    ...

     

    In the end don’t forget to run ng serve command to enjoy the final output.

    If you have any query then please let me know or comment below.

    Jassa Jatt

    Thank you

  • Laravel 6 auth working example

    Laravel 6 auth working example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Laravel 6 auth working example.

    Laravel 6 has been launched recently and Laravel 6 has many good features and in this post, I will share laravel 6 auth feature.

    Laravel is the best PHP MVC framework.

    Here are the commands and code for Laravel 6 auth and please use this carefully.


    1. Here are the basic commands to set laravel 6 working environment:

    First don’t forget to install nodejs latest version and then below commands into your terminal(GIT BASH) or command command prompt:
    composer global require laravel/installer
    
    composer create-project --prefer-dist laravel/laravel laravel6auth
    
    cd laravel6auth

    2. After run the above commands, run below command provides a quick way to scaffold all of the routes and views you need for authentication using a few simple commands:

    composer require laravel/ui --dev

    3. After above command below command should be used on fresh applications and will install a layout view, registration and login views, as well as routes for all authentication end-points:

    php artisan ui vue --auth

    4. Now these two commands will be use to styling view layouts like login form, registration etc:

    npm install
    
    npm run dev

    5. Now run below command and you will see below two images kind of screens:

    php artisan serve


    6. After above please check below post link to set laravel database with laravel migrate command:

    laravel migrate

    If you have any query related to this post, then please do comment below.

    jassa Jatt

    Thank you.

  • laravel 6 comes with great authentication features.

    laravel 6 comes with great authentication features.

    Hello to all, welcome to therichpost.com. In this post, I will tell you, laravel 6 comes with great authentication features.

    laravel the best PHP MVC and now laravel came with laravel 6 with lots of great features and I will tell you all but first, I will tell little about Laravel 6 Authentication feature.

    Jassa Jatt

    Thank you

  • 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