bsholdice

bsholdice

Member Since 3 Years Ago

Experience Points 7,240
Experience Level 2

2,760 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 70
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

18 Jun
4 weeks ago

bsholdice left a reply on Laravel-mix & Blade Syntax Needed To Use JS Package

the package author helped me:

app.js:

import sparkline from “@fnando/sparkline”;
window.sparkline = sparkline

blade.php:

<script>
    sparkline(document.querySelector(".sparkline"), [1, 5, 2, 4, 8, 3, 7]);
</script>

with no other entries in webpack.mix.js or bootstrap.js.

So now I need to understand exactly what window.sparkline = sparkline does.

bsholdice started a new conversation Laravel-mix & Blade Syntax Needed To Use JS Package

I want to use https://github.com/fnando/sparkline in a new 5.8 project. I kept getting a browser error:

Uncaught ReferenceError: sparkline is not defined.'

With the help of a SO question (https://stackoverflow.com/questions/56640085/issues-compiling-laravel-webpack-and-sparkline) it seems that one solution is to use mix.copy() to simply stage the .js file in /public/js/, which is then pulled down as a in my blade.

webpack.mix.js:

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .copy('node_modules/@fnando/sparkline/dist/sparkline.js', 'public/js');

blade.php:

<head>
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <script src="{{ mix('js/app.js') }}"></script>
    <script src="{{ mix('js/sparkline.js') }}"></script>
</head>

Is there a way to .mix() the .js into my app.js and import/invoke it somehow?

I have gaps in my knowledge about implementing JS packages in Laravel via laravel-mix and how the functions therein are made available to the browser. I'd like to learn more.

Any help appreciated.

11 Feb
1 year ago

bsholdice left a reply on Read Json From Redis

for anyone interested, I wrote a simple Console command, the crux of which is:

while ($redisdata = \Redis::lpop('iperf3')) 
{ 
    $json = json_decode($redisdata, true);
    ...
]

no threading or queuing, so successive scheduled commands could run concurrently. redis lpop should mean they dont interfere with each other. it doesn't handle failures very elegantly, as the lpop removes it from redis.

09 Feb
1 year ago

bsholdice left a reply on Read Json From Redis

to clarify: I'm wondering if I could get a command or job to subscribe to redis, then would I need to enqueue jobs to process the incoming json data. might a queue here be an overkill?

This data is performance test results from an external system that gets stored in a mysql database and my laravel app displays reports based on this data.

08 Feb
1 year ago

bsholdice started a new conversation Read Json From Redis

Looking for an elegant solution: I want to read in json formatted data from redis.

The data is loaded into redis sporadically, so there are periods of low activity and periods of high activity.

I'm wary of writing a scheduled Command to iteratively take data from redis until there is no more data to take for fear of colliding with the next scheduled command in periods of high activity (i.e. next iteration starts up but the previous iteration is already trying to drain the redis) etc.

any guidance?

01 Sep
1 year ago

bsholdice left a reply on HasMany/belongsTo Relationship Is One-way. BelongsTo Is Broken. Help!

Thank you Jackjones and NFarrington. I'm an idiot ;)

bsholdice started a new conversation HasMany/belongsTo Relationship Is One-way. BelongsTo Is Broken. Help!

I've been staring at this for too long. I predict its a simple stupid error. Can some kind soul spot my mistake and put me out of my misery?

in short, the below model configuration gives me an error when attempting to use the 'node' belongsTo relationship.

>>> $node
=> App\Node {#740
     name: "TEST6",
     updated_at: "2017-09-01 20:02:43",
     created_at: "2017-09-01 20:02:02",
     id: 85858,
     alias: "test6alias1",
   }
>>> $node->aliases
=> Illuminate\Database\Eloquent\Collection {#727
     all: [
       App\NodeAlias {#717
         id: 27,
         node_id: 85858,
         alias: "test6alias1",
         created_at: "2017-09-01 20:03:39",
         updated_at: "2017-09-01 20:03:39",
       },
     ],
   }
>>> $nodealias = \App\NodeAlias::find(27);
=> App\NodeAlias {#729
     id: 27,
     node_id: 85858,
     alias: "test6alias1",
     created_at: "2017-09-01 20:03:39",
     updated_at: "2017-09-01 20:03:39",
   }
>>> $nodealias->node()
=> null
>>> $nodealias->nodes()
BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::nodes()'

cat app/Node.php:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Node extends Model
{
    use SoftDeletes;
    protected $table = 'nodes';
    protected $dates = ['created_at','updated_at','deleted_at'];
    protected $fillable = array('name','type','site_id', 'old_name');


    public function aliases()
    {
        return $this->hasMany('App\NodeAlias');
    }
}

n.b. can't show the migration because there have been a handful of changes over the last few months so I'd need to paste the original create migration and all of the modifications.

nodes table schema:

CREATE TABLE `nodes` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `market_id` int(11) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `deleted_at` timestamp NULL DEFAULT NULL,
  `old_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `nodes_name_unique` (`name`),
  UNIQUE KEY `nodes_old_name_unique` (`old_name`),
  KEY `nodes_market_id_index` (`market_id`)
) ENGINE=InnoDB AUTO_INCREMENT=85859 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

cat app/NodeAlias.php:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class NodeAlias extends Model
{
    protected $fillable = array('alias');
    public function node()
    {
        $this->belongsTo('App\Node', 'node_id', 'id');
    }
}

node_aliases table schema:

CREATE TABLE `node_aliases` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `node_id` int(11) NOT NULL,
  `alias` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
18 May
3 years ago

bsholdice started a new conversation Iterate My Eagerloaded Collection Without Using A Method

in my controller I run a constrained eager load and pass the resulting collection to my view. I try to iterate through the collection and display the results but I realize I'm actually triggering my model's method needlessly, and retrieving results that were excluded by the constraint I used in my controller. How do I avoid this - I feel like I am missing something obivous...

class Domain extends Model
{
        public function Records() 
        {
            return $this->hasMany(Record::class);
        }
}

class Record extends Model
{
    public function Domain() 
    {
            return $this->belongsTo(Domain::class);
    }   
}

In my controller:

    public function index() 
    {
      $domains = Domain::with(['Records' => function ($query) {
      $query->where('title', 'like', '%first%');
      }])->get();
      return view('dns.tacsindex', compact('domains'));
    }

problem in my view is the $domain->records, which is also the name of my method...

    @foreach ($domains as $domain)
        <h3>{{$domain->name}}</h3>     
        <table class="table table-striped">
            <thead>
                <tr>
                    <th class="col-md-3">record Name</th>
                    <th class="col-md-1">record Type</th>
                </tr>
            </thead>
            <tbody>
            @foreach ($domain->records as $record)
            <tr>
                    <td>{{ $record->name }}</td>
                    <td>{{ $record->type }}</td>
            </tr>
            @endforeach
        </tbody>
    </table>
    @endforeach