GregorSams

GregorSams

Member Since 2 Years Ago

Experience Points 500
Experience
Level
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

30 Dec
2 weeks ago

GregorSams started a new conversation Jquery Datatable Does Not Load In Laravel 5.7

I am using Laravel Framework 5.7.19 and want to recreate the following example in my blade view https://datatables.net/examples/plug-ins/range_filtering.html :

Find below my layout app.blade.php:

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'Laravel') }}</title>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">

    <!-- ag-grid
    <script src="https://unpkg.com/ag-grid-enterprise/dist/ag-grid-enterprise.min.noStyle.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/ag-grid-community/dist/styles/ag-grid.css">
    <link rel="stylesheet" href="https://unpkg.com/ag-grid-community/dist/styles/ag-theme-balham.css">
-->
    <!-- jquery -->
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">


</head>
<body>
<div id="app">
    @include('layouts.nav.mainNav')

    <main class="py-4">
        @yield('content')
    </main>
</div>

<script>
    // out side of ready function
    /* Custom filtering function which will search data */
    $.fn.dataTable.ext.search.push(
        function (settings, data, dataIndex) {
            var min = parseInt($('#min').val(), 10);
            var max = parseInt($('#max').val(), 10);
            var age = parseFloat(data[3]) || 0; // use data for the age column

            if ((isNaN(min) && isNaN(max)) ||
                (isNaN(min) && age <= max) ||
                (min <= age && isNaN(max)) ||
                (min <= age && age <= max)) {
                return true;
            }
            return false;
        }
    );
    // out side of ready function end

    $(document).ready(function () {
        var table = $('#example').DataTable();

        // Event listener to the two range filtering inputs to redraw on input
        $('#min, #max').keyup(function () {
            table.draw();
        });
    });
</script>

</body>

</html>

Find below my current datatable implementation datatable.blade.php:

@extends('layouts.app')

@section('content')
    <div class="container">
        <div class="row justify-content-center">
            <div class="">

                <table border="0" cellspacing="5" cellpadding="5">
                    <tbody>
                    <tr>
                        <td>Minimum age:</td>
                        <td><input type="text" id="min" name="min"></td>
                    </tr>
                    <tr>
                        <td>Maximum age:</td>
                        <td><input type="text" id="max" name="max"></td>
                    </tr>
                    </tbody>
                </table>
                <table id="example" class="display" style="width:100%">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <th>Position</th>
                        <th>Office</th>
                        <th>Age</th>
                        <th>Start date</th>
                        <th>Salary</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td>Tiger Nixon</td>
                        <td>System Architect</td>
                        <td>Edinburgh</td>
                        <td>61</td>
                        <td>2011/04/25</td>
                        <td>0,800</td>
                    </tr>
                    <tr>
                        <td>Garrett Winters</td>
                        <td>Accountant</td>
                        <td>Tokyo</td>
                        <td>63</td>
                        <td>2011/07/25</td>
                        <td>0,750</td>
                    </tr>
                    <tr>
                        <td>Ashton Cox</td>
                        <td>Junior Technical Author</td>
                        <td>San Francisco</td>
                        <td>66</td>
                        <td>2009/01/12</td>
                        <td>,000</td>
                    </tr>
                    <tr>
                        <td>Cedric Kelly</td>
                        <td>Senior Javascript Developer</td>
                        <td>Edinburgh</td>
                        <td>22</td>
                        <td>2012/03/29</td>
                        <td>3,060</td>
                    </tr>
                    <tr>
                        <td>Airi Satou</td>
                        <td>Accountant</td>
                        <td>Tokyo</td>
                        <td>33</td>
                        <td>2008/11/28</td>
                        <td>2,700</td>
                    </tr>
                    <tr>
                        <td>Brielle Williamson</td>
                        <td>Integration Specialist</td>
                        <td>New York</td>
                        <td>61</td>
                        <td>2012/12/02</td>
                        <td>2,000</td>
                    </tr>
                    <tr>
                        <td>Herrod Chandler</td>
                        <td>Sales Assistant</td>
                        <td>San Francisco</td>
                        <td>59</td>
                        <td>2012/08/06</td>
                        <td>7,500</td>
                    </tr>
                    <tr>
                        <td>Rhona Davidson</td>
                        <td>Integration Specialist</td>
                        <td>Tokyo</td>
                        <td>55</td>
                        <td>2010/10/14</td>
                        <td>7,900</td>
                    </tr>
                    <tr>
                        <td>Colleen Hurst</td>
                        <td>Javascript Developer</td>
                        <td>San Francisco</td>
                        <td>39</td>
                        <td>2009/09/15</td>
                        <td>5,500</td>
                    </tr>
                    <tr>
                        <td>Sonya Frost</td>
                        <td>Software Engineer</td>
                        <td>Edinburgh</td>
                        <td>23</td>
                        <td>2008/12/13</td>
                        <td>3,600</td>
                    </tr>
                    <tr>
                        <td>Jena Gaines</td>
                        <td>Office Manager</td>
                        <td>London</td>
                        <td>30</td>
                        <td>2008/12/19</td>
                        <td>,560</td>
                    </tr>
                    <tr>
                        <td>Quinn Flynn</td>
                        <td>Support Lead</td>
                        <td>Edinburgh</td>
                        <td>22</td>
                        <td>2013/03/03</td>
                        <td>2,000</td>
                    </tr>
                    <tr>
                        <td>Charde Marshall</td>
                        <td>Regional Director</td>
                        <td>San Francisco</td>
                        <td>36</td>
                        <td>2008/10/16</td>
                        <td>0,600</td>
                    </tr>
                    <tr>
                        <td>Haley Kennedy</td>
                        <td>Senior Marketing Designer</td>
                        <td>London</td>
                        <td>43</td>
                        <td>2012/12/18</td>
                        <td>3,500</td>
                    </tr>
                    <tr>
                        <td>Tatyana Fitzpatrick</td>
                        <td>Regional Director</td>
                        <td>London</td>
                        <td>19</td>
                        <td>2010/03/17</td>
                        <td>5,750</td>
                    </tr>
                    <tr>
                        <td>Michael Silva</td>
                        <td>Marketing Designer</td>
                        <td>London</td>
                        <td>66</td>
                        <td>2012/11/27</td>
                        <td>8,500</td>
                    </tr>
                    <tr>
                        <td>Paul Byrd</td>
                        <td>Chief Financial Officer (CFO)</td>
                        <td>New York</td>
                        <td>64</td>
                        <td>2010/06/09</td>
                        <td>5,000</td>
                    </tr>
                    <tr>
                        <td>Gloria Little</td>
                        <td>Systems Administrator</td>
                        <td>New York</td>
                        <td>59</td>
                        <td>2009/04/10</td>
                        <td>7,500</td>
                    </tr>
                    <tr>
                        <td>Bradley Greer</td>
                        <td>Software Engineer</td>
                        <td>London</td>
                        <td>41</td>
                        <td>2012/10/13</td>
                        <td>2,000</td>
                    </tr>
                    <tr>
                        <td>Dai Rios</td>
                        <td>Personnel Lead</td>
                        <td>Edinburgh</td>
                        <td>35</td>
                        <td>2012/09/26</td>
                        <td>7,500</td>
                    </tr>
                    <tr>
                        <td>Jenette Caldwell</td>
                        <td>Development Lead</td>
                        <td>New York</td>
                        <td>30</td>
                        <td>2011/09/03</td>
                        <td>5,000</td>
                    </tr>
                    <tr>
                        <td>Yuri Berry</td>
                        <td>Chief Marketing Officer (CMO)</td>
                        <td>New York</td>
                        <td>40</td>
                        <td>2009/06/25</td>
                        <td>5,000</td>
                    </tr>
                    <tr>
                        <td>Caesar Vance</td>
                        <td>Pre-Sales Support</td>
                        <td>New York</td>
                        <td>21</td>
                        <td>2011/12/12</td>
                        <td>6,450</td>
                    </tr>
                    <tr>
                        <td>Doris Wilder</td>
                        <td>Sales Assistant</td>
                        <td>Sidney</td>
                        <td>23</td>
                        <td>2010/09/20</td>
                        <td>,600</td>
                    </tr>
                    <tr>
                        <td>Angelica Ramos</td>
                        <td>Chief Executive Officer (CEO)</td>
                        <td>London</td>
                        <td>47</td>
                        <td>2009/10/09</td>
                        <td>,200,000</td>
                    </tr>
                    <tr>
                        <td>Gavin Joyce</td>
                        <td>Developer</td>
                        <td>Edinburgh</td>
                        <td>42</td>
                        <td>2010/12/22</td>
                        <td>,575</td>
                    </tr>
                    <tr>
                        <td>Jennifer Chang</td>
                        <td>Regional Director</td>
                        <td>Singapore</td>
                        <td>28</td>
                        <td>2010/11/14</td>
                        <td>7,650</td>
                    </tr>
                    <tr>
                        <td>Brenden Wagner</td>
                        <td>Software Engineer</td>
                        <td>San Francisco</td>
                        <td>28</td>
                        <td>2011/06/07</td>
                        <td>6,850</td>
                    </tr>
                    <tr>
                        <td>Fiona Green</td>
                        <td>Chief Operating Officer (COO)</td>
                        <td>San Francisco</td>
                        <td>48</td>
                        <td>2010/03/11</td>
                        <td>0,000</td>
                    </tr>
                    <tr>
                        <td>Shou Itou</td>
                        <td>Regional Marketing</td>
                        <td>Tokyo</td>
                        <td>20</td>
                        <td>2011/08/14</td>
                        <td>3,000</td>
                    </tr>
                    <tr>
                        <td>Michelle House</td>
                        <td>Integration Specialist</td>
                        <td>Sidney</td>
                        <td>37</td>
                        <td>2011/06/02</td>
                        <td>,400</td>
                    </tr>
                    <tr>
                        <td>Suki Burks</td>
                        <td>Developer</td>
                        <td>London</td>
                        <td>53</td>
                        <td>2009/10/22</td>
                        <td>4,500</td>
                    </tr>
                    <tr>
                        <td>Prescott Bartlett</td>
                        <td>Technical Author</td>
                        <td>London</td>
                        <td>27</td>
                        <td>2011/05/07</td>
                        <td>5,000</td>
                    </tr>
                    <tr>
                        <td>Gavin Cortez</td>
                        <td>Team Leader</td>
                        <td>San Francisco</td>
                        <td>22</td>
                        <td>2008/10/26</td>
                        <td>5,500</td>
                    </tr>
                    <tr>
                        <td>Martena Mccray</td>
                        <td>Post-Sales support</td>
                        <td>Edinburgh</td>
                        <td>46</td>
                        <td>2011/03/09</td>
                        <td>4,050</td>
                    </tr>
                    <tr>
                        <td>Unity Butler</td>
                        <td>Marketing Designer</td>
                        <td>San Francisco</td>
                        <td>47</td>
                        <td>2009/12/09</td>
                        <td>,675</td>
                    </tr>
                    <tr>
                        <td>Howard Hatfield</td>
                        <td>Office Manager</td>
                        <td>San Francisco</td>
                        <td>51</td>
                        <td>2008/12/16</td>
                        <td>4,500</td>
                    </tr>
                    <tr>
                        <td>Hope Fuentes</td>
                        <td>Secretary</td>
                        <td>San Francisco</td>
                        <td>41</td>
                        <td>2010/02/12</td>
                        <td>9,850</td>
                    </tr>
                    <tr>
                        <td>Vivian Harrell</td>
                        <td>Financial Controller</td>
                        <td>San Francisco</td>
                        <td>62</td>
                        <td>2009/02/14</td>
                        <td>2,500</td>
                    </tr>
                    <tr>
                        <td>Timothy Mooney</td>
                        <td>Office Manager</td>
                        <td>London</td>
                        <td>37</td>
                        <td>2008/12/11</td>
                        <td>6,200</td>
                    </tr>
                    <tr>
                        <td>Jackson Bradshaw</td>
                        <td>Director</td>
                        <td>New York</td>
                        <td>65</td>
                        <td>2008/09/26</td>
                        <td>5,750</td>
                    </tr>
                    <tr>
                        <td>Olivia Liang</td>
                        <td>Support Engineer</td>
                        <td>Singapore</td>
                        <td>64</td>
                        <td>2011/02/03</td>
                        <td>4,500</td>
                    </tr>
                    <tr>
                        <td>Bruno Nash</td>
                        <td>Software Engineer</td>
                        <td>London</td>
                        <td>38</td>
                        <td>2011/05/03</td>
                        <td>3,500</td>
                    </tr>
                    <tr>
                        <td>Sakura Yamamoto</td>
                        <td>Support Engineer</td>
                        <td>Tokyo</td>
                        <td>37</td>
                        <td>2009/08/19</td>
                        <td>9,575</td>
                    </tr>
                    <tr>
                        <td>Thor Walton</td>
                        <td>Developer</td>
                        <td>New York</td>
                        <td>61</td>
                        <td>2013/08/11</td>
                        <td>,540</td>
                    </tr>
                    <tr>
                        <td>Finn Camacho</td>
                        <td>Support Engineer</td>
                        <td>San Francisco</td>
                        <td>47</td>
                        <td>2009/07/07</td>
                        <td>,500</td>
                    </tr>
                    <tr>
                        <td>Serge Baldwin</td>
                        <td>Data Coordinator</td>
                        <td>Singapore</td>
                        <td>64</td>
                        <td>2012/04/09</td>
                        <td>8,575</td>
                    </tr>
                    <tr>
                        <td>Zenaida Frank</td>
                        <td>Software Engineer</td>
                        <td>New York</td>
                        <td>63</td>
                        <td>2010/01/04</td>
                        <td>5,250</td>
                    </tr>
                    <tr>
                        <td>Zorita Serrano</td>
                        <td>Software Engineer</td>
                        <td>San Francisco</td>
                        <td>56</td>
                        <td>2012/06/01</td>
                        <td>5,000</td>
                    </tr>
                    <tr>
                        <td>Jennifer Acosta</td>
                        <td>Junior Javascript Developer</td>
                        <td>Edinburgh</td>
                        <td>43</td>
                        <td>2013/02/01</td>
                        <td>,650</td>
                    </tr>
                    <tr>
                        <td>Cara Stevens</td>
                        <td>Sales Assistant</td>
                        <td>New York</td>
                        <td>46</td>
                        <td>2011/12/06</td>
                        <td>5,600</td>
                    </tr>
                    <tr>
                        <td>Hermione Butler</td>
                        <td>Regional Director</td>
                        <td>London</td>
                        <td>47</td>
                        <td>2011/03/21</td>
                        <td>6,250</td>
                    </tr>
                    <tr>
                        <td>Lael Greer</td>
                        <td>Systems Administrator</td>
                        <td>London</td>
                        <td>21</td>
                        <td>2009/02/27</td>
                        <td>3,500</td>
                    </tr>
                    <tr>
                        <td>Jonas Alexander</td>
                        <td>Developer</td>
                        <td>San Francisco</td>
                        <td>30</td>
                        <td>2010/07/14</td>
                        <td>,500</td>
                    </tr>
                    <tr>
                        <td>Shad Decker</td>
                        <td>Regional Director</td>
                        <td>Edinburgh</td>
                        <td>51</td>
                        <td>2008/11/13</td>
                        <td>3,000</td>
                    </tr>
                    <tr>
                        <td>Michael Bruce</td>
                        <td>Javascript Developer</td>
                        <td>Singapore</td>
                        <td>29</td>
                        <td>2011/06/27</td>
                        <td>3,000</td>
                    </tr>
                    <tr>
                        <td>Donna Snider</td>
                        <td>Customer Support</td>
                        <td>New York</td>
                        <td>27</td>
                        <td>2011/01/25</td>
                        <td>2,000</td>
                    </tr>
                    </tbody>
                    <tfoot>
                    <tr>
                        <th>Name</th>
                        <th>Position</th>
                        <th>Office</th>
                        <th>Age</th>
                        <th>Start date</th>
                        <th>Salary</th>
                    </tr>
                    </tfoot>
                </table>

            </div>
        </div>
    </div>
@endsection

This is how currently my table looks like:

![alt text]https://imgur.com/a/UNEvTqp "Error")

As you can see I get the error:

Uncaught TypeError: $(...).DataTable is not a function

Any suggestions what I am doing wrong?

14 Jan
1 year ago

GregorSams started a new conversation Add Validation To Repeater Field

I am using Laravel 5.5 and I am using the jquery repeater field.

Find below my frontend:

    @extends('layouts.app') @section('content')
    <div class="panel-body">
        {{-- display success message --}} @if (Session::has('success'))
        <div class="alert alert-success">
            <strong>Success:</strong> {{ Session::get('success') }}
        </div>
        @endif {{-- display error message --}} @if (count($errors) > 0)
        <div class="alert alert-danger">
            <strong>Error:</strong>
            <ul>
                @foreach($errors->all() as $error)
                <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
        @endif
    </div>
    
    <!-- Form -->
    <form action="{{ route('instrument.updateDetails', [$instrumentUnderEdit->id]) }}" method='POST' class="repeater" enctype="multipart/form-data">
        {{ csrf_field() }}
        <label>Firstname</label>
        <label>Lastname</label>
        <label>Twitter</label>
        <div data-repeater-list="team">
            <div data-repeater-item>
    
                <input type="text" name="firstName" value='{{ $instrumentUnderEdit->firstName }}' />
    
                <input type="text" name="lastName" value='{{ $instrumentUnderEdit->lastName }}' />
    
                <input type="text" name="twitter" value='{{ $instrumentUnderEdit->twitter }}' />
    
                <input data-repeater-delete type="button" value="Delete" />
            </div>
        </div>
        <input data-repeater-create type="button" value="Add" />
        </br>
        </br>
        <div class="row">
            <div class="form-group col-xs-5 col-lg-1">
                <label>User Name*</label>
                <input type="text" name="userName" class="form-control" placeholder="Insert your contributor name" style="width: 250px;"> </div>
        </div>
        <input type="hidden" name='_method' value='POST'>
        <input type="submit" class='btn btn-success btn-sm' value='Update'>
    </form>
    @endsection

I am using the following in my backend for validation:

        $this->validate($request, [
            'firstName' => 'nullable|min:2|max:190',
            'lastName' => 'nullable|min:3|max:190',
            'twitter' => 'nullable|min:3|max:190',
            'userName' => 'required|min:1|max:190',
        ]);

Currently, the repeater field does not valide correctly. I am guessing that the reason for this is that in the request the name attribute is rendered as the following f.ex.: "team[1][firstName]", "team[2][firstName]" whereas the number indicates the row of the field.

Any suggestions how to add validation to each repeater field?

Thx in advance for your replies!

01 Jan
1 year ago

GregorSams started a new conversation Load Db Data Into Javascript File

I am using Laravel 5.5 and I am trying to work with ag-grid and want to load my data that is coming from my db directly into the Javascript file.

My Migration looks like the following:

    public function up()
    {
        Schema::create('tasks', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->timestamps();
        });
    }

My Frontend looks like the following:

example.js

    // specify the columns
    var columnDefs = [
        {headerName: "Name", field: "name"},
        {headerName: "Created_At", field: "created_at"},
        {headerName: "Updated_At", field: "updated_at"}
    ];
    
    // specify the data
    var rowData = [
        {name: "TODO 1", created_at: "01.01.2018", updated_at: "05.11.2016"},
        {name: "TODO 1", created_at: "01.01.2018", updated_at: "05.11.2016"} // HERE I would like to replace this dummy data with my db data
    ];
    
    // let the grid know which columns and what data to use
    var gridOptions = {
        columnDefs: columnDefs,
        rowData: rowData,
        onGridReady: function () {
            gridOptions.api.sizeColumnsToFit();
        }
    };
    
    // used in our jasmine test
    function selectAllRows() {
        gridOptions.api.selectAll();
    }
    
    // wait for the document to be loaded, otherwise ag-Grid will not find the div in the document.
    document.addEventListener("DOMContentLoaded", function () {
        // lookup the container we want the Grid to use
        var eGridDiv = document.querySelector('#myGrid');
    
        // create the grid passing in the div to use together with the columns & data we want to use
        new agGrid.Grid(eGridDiv, gridOptions);
    });

home.blade.php

    <html>
    
    <head>
        <script src="https://www.ag-grid.com/dist/ag-grid/ag-grid.js"></script>
        <script src="example.js"></script>
    </head>
    
    <body>
        <h1>Ag-Grid Example</h1>
        <div id="myGrid" style="height: 115px;width:500px" class="ag-fresh"></div>
    
        <!-- Own Scripts -->
        <script src="{{ asset('js/example.js') }}"></script>
    </body>
    
    </html>

Any suggestions how to insert my data that I load from the database into the the variable rowData in my example.js file?

I appreciate your replies!

31 Dec
1 year ago

GregorSams started a new conversation Ag-Grid - Passing Data To Javascript File From Controller

Hello guys,

I am trying out Ag-Grid however, I do not know how to pass my data from my model Task to my js-script file.

Below is my backend:

Task migration:

    public function up()
    {
        Schema::create('tasks', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->timestamps();
        });
    }

Frontend - view

<html>

<head>
    <script src="https://www.ag-grid.com/dist/ag-grid/ag-grid.js"></script>
    <script src="example.js"></script>
</head>

<body>
    <h1>Ag-Grid Example</h1>
    <div id="myGrid" style="height: 115px;width:500px" class="ag-fresh"></div>

    <!-- Own Scripts -->
    <script src="{{ asset('js/example.js') }}"></script>
</body>

</html>

Frontend - Jsfile

// specify the columns
var columnDefs = [
    {headerName: "Make", field: "make"}, 
    {headerName: "Model", field: "model"},
    {headerName: "Price", field: "price"}
];

// specify the data
var rowData = [
    {make: "Toyota", model: "Celica", price: 35000},// data has to loaded here
    {make: "Ford", model: "Mondeo", price: 32000},
    {make: "Porsche", model: "Boxter", price: 72000}
];

// let the grid know which columns and what data to use
var gridOptions = {
    columnDefs: columnDefs,
    rowData: rowData,
    onGridReady: function () {
        gridOptions.api.sizeColumnsToFit();
    }
};

// used in our jasmine test
function selectAllRows() {
    gridOptions.api.selectAll();
}

// wait for the document to be loaded, otherwise ag-Grid will not find the div in the document.
document.addEventListener("DOMContentLoaded", function () {
    // lookup the container we want the Grid to use
    var eGridDiv = document.querySelector('#myGrid');

    // create the grid passing in the div to use together with the columns & data we want to use
    new agGrid.Grid(eGridDiv, gridOptions);
});

Any suggestions how to load my data into the var rowData?

Thanks in advance for your replies!

23 Dec
1 year ago

GregorSams started a new conversation Error - Argument 1 Passed To Illuminate\Database\Grammar::parameterize() Must Be Of The Type Array

Hello guys,

the following query works perfectly well on my mysql db:

SELECT *
            FROM instruments
            LEFT join financials on instruments.id=financials.instruments_id
            WHERE financials.id IN
            ( SELECT MAX(financials.id)
            FROM financials
            GROUP BY financials.instruments_id )
            ORDER BY instruments.id ASC

I tried to translate the query into eloquent, which looks the following:

$overviewArray = DB::table('instruments')
    ->leftJoin('financials', 'instruments.id', '=', 'financials.instruments_id')
    ->whereIn('financials.id', DB::raw('SELECT MAX(financials.id)
    FROM financials
    GROUP BY financials.instruments_id '))
    ->orderBy('instruments.id')
    ->get()//I get the error here
->toArray(); 

However, I get the following error:

[2017-12-23 15:01:45] local.ERROR: Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, object given, called in C:\Users\admin\Desktop\Coding Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 250 {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, object given, called in C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 250 at C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Grammar.php:135)
[stacktrace]
#0 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php(250): Illuminate\Database\Grammar->parameterize(Object(Illuminate\Database\Query\Expression))
#1 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php(196): Illuminate\Database\Query\Grammars\Grammar->whereIn(Object(Illuminate\Database\Query\Builder), Array)
#2 [internal function]: Illuminate\Database\Query\Grammars\Grammar->Illuminate\Database\Query\Grammars\{closure}(Array, 0)
#3 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Support\Collection.php(847): array_map(Object(Closure), Array, Array)
#4 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php(197): Illuminate\Support\Collection->map(Object(Closure))
#5 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php(180): Illuminate\Database\Query\Grammars\Grammar->compileWheresToArray(Object(Illuminate\Database\Query\Builder))
#6 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php(85): Illuminate\Database\Query\Grammars\Grammar->compileWheres(Object(Illuminate\Database\Query\Builder), Array)
#7 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php(60): Illuminate\Database\Query\Grammars\Grammar->compileComponents(Object(Illuminate\Database\Query\Builder))
#8 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\MySqlGrammar.php(39): Illuminate\Database\Query\Grammars\Grammar->compileSelect(Object(Illuminate\Database\Query\Builder))
#9 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1650): Illuminate\Database\Query\Grammars\MySqlGrammar->compileSelect(Object(Illuminate\Database\Query\Builder))
#10 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1707): Illuminate\Database\Query\Builder->toSql()
#11 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1692): Illuminate\Database\Query\Builder->runSelect()
#12 C:\Users\admin\Desktop\Projects\demo_project\app\Console\Commands\OverviewCommand.php(58): Illuminate\Database\Query\Builder->get()
#13 [internal function]: App\Console\Commands\OverviewCommand->handle()
#14 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Array, Array)
#15 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#16 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#17 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Container\Container.php(549): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#18 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Console\Command.php(183): Illuminate\Container\Container->call(Array)
#19 C:\Users\admin\Desktop\Projects\demo_project\vendor\symfony\console\Command\Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#20 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Console\Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#21 C:\Users\admin\Desktop\Projects\demo_project\vendor\symfony\console\Application.php(936): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 C:\Users\admin\Desktop\Projects\demo_project\vendor\symfony\console\Application.php(240): Symfony\Component\Console\Application->doRunCommand(Object(App\Console\Commands\OverviewCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 C:\Users\admin\Desktop\Projects\demo_project\vendor\symfony\console\Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Console\Application.php(88): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 C:\Users\admin\Desktop\Projects\demo_project\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(121): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 C:\Users\admin\Desktop\Projects\demo_project\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 {main}
"} 

The error occurs at the ->get() method of my query.

Any suggestions what I am doing wrong?

I appreciate your replies!

22 Dec
1 year ago

GregorSams started a new conversation Laravel 5.5 - UpdateOrCreate() Does Not Add Any Record To Db

I am having the following setup:

SETUP

I am using Laravel 5.5 I have the following db migration:

        Schema::create('prices', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('exchanges_id');
            $table->string('symbol');
            $table->dateTime('exch_datetime');
            $table->decimal('high', 40, 9);
            $table->decimal('low', 40, 9);
            $table->decimal('bid', 40, 9);
            $table->decimal('ask', 40, 9);
            $table->decimal('vwap', 40, 9);
            $table->decimal('open', 40, 9);
            $table->decimal('first', 40, 9);
            $table->decimal('last', 40, 9);
            $table->decimal('change', 40, 9);
            $table->decimal('average', 40, 9);
            $table->decimal('baseVolume', 40, 9);
            $table->decimal('quoteVolume', 40, 9);
            $table->timestamps();
        });

My Model looks like the following:

    class Price extends Model
    {
        protected $fillable = ['exchanges_id', 'symbol', 'exch_datetime', 'high', 'low', 'bid' , 'ask',  'vwap', 'open', 'first', 'last', 'change', 'average', 'baseVolume', 'quoteVolume',];
    }

I am using the cctx library to get price data, see below my minimum viable example command:

    <?php

    namespace App\Console\Commands;

    use App\Price;
    use ccxt\ccxt;
    use Illuminate\Console\Command;
    use Log;

    class TestCommand extends Command
    {

        protected $signature = 'Test:test';

        protected $description = 'Command description';

        public function __construct()
        {
            parent::__construct();
        }

        public function handle()
        {
            $poloniex = new \ccxt\poloniex();
            $this->updatePrices($poloniex, "poloniex");
        }
        public function updatePrices($exchangeObj, $exchangeName)
        {
            $tick = $exchangeObj->fetch_ticker('GAS/BTC');
            var_dump($tick);
            try {
                print_r("#######################" . "\n");
                print_r($tick['datetime'] . "\n");
                print_r($tick['ask'] . "\n");

                $prices = Price::updateOrCreate([
                //    'exchanges_id' => 10,
                    'exch_datetime' => $tick['datetime'],
                ], [
                    'ask' => $tick['ask'],
                ]);
                var_dump($prices->toSql());

            } catch (\Exception $e) {
                Log::info($e->getMessage());
            }
        }
    }       

When I run the command I get the following output:

    >php artisan test:test
    C:\Users\admin\Desktop\Projects\demo_laravel\app\Console\Commands\TestCommand.php:49:
    array(18) {
      'symbol' =>
      string(7) "GAS/BTC"
      'timestamp' =>
      string(13) "1513941757340"
      'datetime' =>
      string(29) "2017-12-22T11:22:37.647+00:00"
      'high' =>
      double(0.00218987)
      'low' =>
      double(0.00155806)
      'bid' =>
      double(0.00174699)
      'ask' =>
      double(0.00176426)
      'vwap' =>
      NULL
      'open' =>
      NULL
      'close' =>
      NULL
      'first' =>
      NULL
      'last' =>
      double(0.0017645)
      'change' =>
      double(-0.14186363)
      'percentage' =>
      NULL
      'average' =>
      NULL
      'baseVolume' =>
      double(52247.01599391)
      'quoteVolume' =>
      double(99.79979936)
      'info' =>
      array(10) {
        'id' =>
        int(198)
        'last' =>
        string(10) "0.00176450"
        'lowestAsk' =>
        string(10) "0.00176426"
        'highestBid' =>
        string(10) "0.00174699"
        'percentChange' =>
        string(11) "-0.14186363"
        'baseVolume' =>
        string(11) "99.79979936"
        'quoteVolume' =>
        string(14) "52247.01599391"
        'isFrozen' =>
        string(1) "0"
        'high24hr' =>
        string(10) "0.00218987"
        'low24hr' =>
        string(10) "0.00155806"
      }
    }
    #######################
    2017-12-22T11:22:37.647+00:00
    0.00176426

Problem

My problem is that nothing gets inserted into the database, when I run the command: enter image description here

Any suggestions why this is the case?

I appreciate your replies!

21 Dec
1 year ago

GregorSams started a new conversation UpdateOrCreate Does Not Insert Anything Within My Db

I am using Laravel 5.5 and would like to insert data in my table. However, laravel does not insert any data in the db:

My table looks like the following:

CREATE TABLE `prices` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `exchanges_id` int(11) NOT NULL,
 `symbol` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
 `ask` decimal(40,9) NOT NULL,
 `created_at` timestamp NULL DEFAULT NULL,
 `updated_at` timestamp NULL DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

My model has the following fillables:

protected $fillable = ['exchanges_id', 'symbol', 'ask', 'exch_datetime']

My laravel command looks like the following. I am using the cctx lib to get prices:

 <?php

namespace App\Console\Commands;

use App\Prices;
use ccxt\ccxt;
use Illuminate\Console\Command;
use Log;

class TestCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'Test:test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $poloniex = new \ccxt\poloniex();
        $this->updatePrices($poloniex, "poloniex");
    }
    public function updatePrices($exchangeObj, $exchangeName)
    {
        $tick = $exchangeObj->fetch_ticker('GAS/BTC');
        var_dump($tick);
        try {
            print_r("#######################" . "\n");
            print_r($tick['datetime'] . "\n");
            print_r($tick['ask'] . "\n");

            $prices = Prices::updateOrCreate([
            //    'exchanges_id' => 10,
                'exch_datetime' => $tick['datetime'],
            ], [
                'ask' => $tick['ask'],
            ]);
            dd($prices->toSql());

        } catch (\Exception $e) {
            Log::info($e->getMessage());
        }
    }
}

My problem is that nothing gets inserted into the database.

I tried to use dd($prices->toSql()); with my query, but I do not get any sql output.

Any suggestions what might be wrong or how to debug this properly?

I appreciate your replies!

20 Dec
1 year ago

GregorSams left a reply on Wordpress On Subdomain With Laravel As Frontend

@RamjithAp Thx for your reply! I am currently on a development environment. Any suggestions how to setup the subdomain on my dev env. Please see my updated .htaccess file.

GregorSams started a new conversation Wordpress On Subdomain With Laravel As Frontend

I need to add wordpress to an existing laravel app. I am using Apache (XAMPP) to serve the application:

    https://premium.website.com/ -> Wordpress website
    https://website.com/ -> Laravel web application

My folder structure looks like the following, whereas in the \wordpress folder I have all my wordpress files:

enter image description here

Any suggestions how to setup the development environment to serve the wordpress site from a subdomain?

I also have to say that I currently do not have a specific idea how to approach this problem and appreciate your help !

Thx in advance!

02 Feb
1 year ago

GregorSams started a new conversation Monitor A Website With Laravel

Hey guys,

I am in the process of creating a comment monitoring tool to scan reddit comments for certain keywords.

Under the following url I can display all comments:

https://amp.reddit.com/r/all/comments.json

However I am not sure how to implement the monitoring aspect in laravel. Is php the right language for such requests intensive tasks? Any well designed examples within laravel?

Appreciate your replies!

03 Dec
2 years ago

GregorSams started a new conversation Set Up Database Connection On Cloud9

I am using the following database credentials on my cloud9 terminal(taken from this tutorial):

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=c9
DB_USERNAME=pisco
DB_PASSWORD=

I did the following to select the db:

mysql-ctl cli
use c9;
exit;

Furthermore, I updated my config file in config/database.php:

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', 'localhost'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'c9'),
    'username' => env('DB_USERNAME', 'pisco'),
    'password' => env('DB_PASSWORD', ''),
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix' => '',
    'strict' => false,
    'engine' => null,
],

Still I get the following error when I run migrate:

pisco:~/workspace $ php artisan migrate

                                                                                                                                                 
  [Illuminate\Database\QueryException]                                                                                                           
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'c9.users' doesn't exist (SQL: alter table `users` add `deleted_at` timestamp null)  
                                                                                                                                                 

                                                                                      
  [PDOException]                                                                      
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'c9.users' doesn't exist  
                                                                                  

Any suggestions what I am doing wrong?