GregorSams

Experience

450

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 0 Lessons Completed
  • 0 Favorites

14th January, 2018

GregorSams started a new conversation Add Validation To Repeater Field • 5 months ago

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!

1st January, 2018

GregorSams started a new conversation Load Db Data Into Javascript File • 5 months ago

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!

31st December, 2017

GregorSams started a new conversation Ag-Grid - Passing Data To Javascript File From Controller • 5 months ago

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!

23rd December, 2017

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

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!

22nd December, 2017

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

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!

21st December, 2017

GregorSams started a new conversation UpdateOrCreate Does Not Insert Anything Within My Db • 5 months ago

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!

20th December, 2017

GregorSams left a reply on Wordpress On Subdomain With Laravel As Frontend • 6 months ago

@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 • 6 months ago

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!

2nd February, 2017

GregorSams started a new conversation Monitor A Website With Laravel • 1 year ago

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!

3rd December, 2016

GregorSams started a new conversation Set Up Database Connection On Cloud9 • 1 year ago

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?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.