jbloomstrom

jbloomstrom

Programmer Analyst at Matanuska-Susitna Borough

Member Since 4 Years Ago

Palmer

Experience Points
135,115
Total
Experience

4,885 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
1175
Lessons
Completed
Best Reply Awards
35
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.

Level 28
135,115 XP
Feb
20
2 days ago
Activity icon

Replied to Modal Delete Confirmation With BootstrapVue

Have you considered a global event bus? Basically, a separate Vue instance that acts as a go-between to allow events to be emitted and listened by disparate components.

https://alligator.io/vuejs/global-event-bus/

Activity icon

Replied to Validation Rules For Field Allowable Null And String

Have you tried sometimes?

Something like this:

'started_at' => [
    'sometimes',
    'required',
    'string',
    'date_format:Y-m-d H:i:s',
    new EmploymentStartDateCanBeChanged($this->route('referee'))
]

To prevent it invalidating null values, you'll need to conditionally disable the started_at field. Check out this answer for more on how to do that. https://laracasts.com/discuss/channels/laravel/validation-sometimesrequired?page=1#reply=510966

Here's a codepen of a working example. https://codepen.io/anon/pen/eadXox

https://laravel.com/docs/5.8/validation#conditionally-adding-rules

Jan
30
3 weeks ago
Activity icon

Awarded Best Reply on How To Add Dynamically Post Slug To Facebook Like Button?

In attribute values, you need to use the v-bind: directive. Something like this:

v-bind:data-href="`https://test.com/post/${post.slug}`"

or you can use the shorthand :

:data-href="`https://test.com/post/${post.slug}`"

https://vuejs.org/v2/guide/syntax.html#Attributes

Activity icon

Replied to How To Add Dynamically Post Slug To Facebook Like Button?

In attribute values, you need to use the v-bind: directive. Something like this:

v-bind:data-href="`https://test.com/post/${post.slug}`"

or you can use the shorthand :

:data-href="`https://test.com/post/${post.slug}`"

https://vuejs.org/v2/guide/syntax.html#Attributes

Jan
23
4 weeks ago
Activity icon

Replied to How Do I Override The 404 For The Resource Controller?

Check out this tutorial. It explains how to use custom handling if the route can't find a model.

TLDR:

// RouteServiceProvider.php
$router->model('code', App\Code::class, function () {
    // throw new NotFoundHTTPException;
    // your custom logic here.
});

https://scotch.io/tutorials/cleaner-laravel-controllers-with-route-model-binding#toc-custom-exceptions-for-route-model-binding

Activity icon

Awarded Best Reply on Polymorphic View Assistance

I think you're on to a good approach, dynamically include a partial specific to the reviewable_type. You could even add a trait to each reviewable model to simplify getting the partial name.

// trait added to Post, Comment, Picture etc.
use Illuminate\Support\Str;

trait CanGetReviewableTypePartialName {
  
  function getPartialNameAttribute() {
    // insert your own naming convention
   
    return "partials._" . Str::snake( class_basename( $this->reviewable ) );
    // App\Post becomes partials._post
    // App\PostPicture becomes partials._post_picture
  }
}


// your blade template

@foreach($rows as $row)
@include($row->partial_name, ['reviewable' => $row->reviewable])
@endforeach

Activity icon

Replied to How Do I Sum Every N Rows In Laravel Using MySQL Queries?

Please format your code by placing three backticks ` before and after the code block like this:

```

code

```

With collections, you can break up results into groups of N rows each with the chunk method. https://laravel.com/docs/5.8/collections#method-chunk

You could then use reduce to process and derive a single value for each chunk. Or if you're wanting something other than a single value, you can use transform and apply whatever logic you want to each chunk.

https://laravel.com/docs/5.8/collections#method-reduce

https://laravel.com/docs/5.8/collections#method-transform

Activity icon

Replied to Polymorphic View Assistance

I think you're on to a good approach, dynamically include a partial specific to the reviewable_type. You could even add a trait to each reviewable model to simplify getting the partial name.

// trait added to Post, Comment, Picture etc.
use Illuminate\Support\Str;

trait CanGetReviewableTypePartialName {
  
  function getPartialNameAttribute() {
    // insert your own naming convention
   
    return "partials._" . Str::snake( class_basename( $this->reviewable ) );
    // App\Post becomes partials._post
    // App\PostPicture becomes partials._post_picture
  }
}


// your blade template

@foreach($rows as $row)
@include($row->partial_name, ['reviewable' => $row->reviewable])
@endforeach

Activity icon

Replied to 1 To M Query

@zaster Happy to help!

Activity icon

Replied to Re-Connect Old Forge Server To Laravel Forge

Is it not available from the Archived Servers page? If it's there, you can reconnect it with the current SSH key.

Activity icon

Awarded Best Reply on 1 To M Query

Something like this?

Job::whereHas('subjobs', function($query) use ($user_id, $company_id, $comp) {
  return $query->where('user_id', $user_id)
    ->where('user_company_id', $company_id)
    ->where('comp', $comp);
});

I'm making some assumptions about how your Job model is set up. If you post your full models, I can give a more accurate answer.

Activity icon

Replied to 1 To M Query

Something like this?

Job::whereHas('subjobs', function($query) use ($user_id, $company_id, $comp) {
  return $query->where('user_id', $user_id)
    ->where('user_company_id', $company_id)
    ->where('comp', $comp);
});

I'm making some assumptions about how your Job model is set up. If you post your full models, I can give a more accurate answer.

Jan
20
1 month ago
Activity icon

Replied to Querying On Relation Column Within A Relationship

hasMany returns a Builder instance, so you can chain a whereclause off it.

public function supplierThreads()
{
    return $this->hasMany(SupplierThread::class)
        ->where('status', '!==', 'closed');
}

public function supplierArchives()
{
    return $this->hasMany(SupplierThread::class)
        ->where('status', 'closed');
}
Jan
09
1 month ago
Activity icon

Replied to Can't Sync Many To Many Relation

Sounds like you may have missed some parentheses. There is a subtle but important difference between $Estado->requisitos and $Estado->requisitos(). The first one represents the Eloquent Collection, the second one returns the (BelongsToMany) relationship. The sync method is on the relationship, not the Eloquent Collection.

Activity icon

Replied to Can't Sync Many To Many Relation

You're trying to sync a collection to a collection, but you need to sync at the individual model level.

Search for the "syncing" example in the docs. You can see that it's meant to sync one model with many models.

$user->roles()->sync([1, 2, 3]);

For your example, try changing this:

$Estados->requisitos()->sync($requisitos);

to this:

$Estados->each->requisitos()->sync($requisitos);

It's a concept called higher order messaging

Another way of doing it would be:

$Estados->each(function($Estado) use ($requisitos) {
    $Estado->requisitos()->sync($requisitos);
});

Higher order messaging reads cleaner to me, so I use it whenever possible.

Dec
27
1 month ago
Activity icon

Replied to Message: Call To A Member Function Save() On Null

Try changing this:

 $ind->utili()->save($utili);

to this:

$utili->save();
Activity icon

Replied to Aws S3

You can pass the disk name as the second argument to the store method.

Like this:

$upload->store('images/task/medias', 's3');

From https://laravel.com/docs/5.8/filesystem#file-uploads

Activity icon

Replied to Eloquent Collection Heisenbug: Trying To Get Property Of Non-object!

I wonder if it's an issue of stale data.

What happens if you try getting a fresh instance of $otherOrgJob from the db? Like this?

$otherOrgJob->fresh()->jobParticipants->first()->id
Activity icon

Commented on Explain How To Limit Downloads Per User

Late to the party, but check out Firefox Developer Edition. https://www.mozilla.org/en-US/firefox/developer/

Nov
10
3 months ago
Activity icon

Awarded Best Reply on If Remote Img Src Exists?

You can use curl to check if the image exists.

function url_exists($url){
    $ch = curl_init($url);    
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

   return ($code == 200);
}

$url = url_exists("http://logo.clearbit.com/ryanm.com") ? 
    "http://logo.clearbit.com/ryanm.com" : 
    "<alternate_url>";
Oct
07
4 months ago
Activity icon

Commented on Explain How To Group Records By Relative Dates

More generally, if you want any number of groups you can just return id % X.

$i = 3; // change to number of groups you want

$collection->groupBy( function($item) use ($i)  {
    return $item->id % $i;
});
Sep
16
5 months ago
Activity icon

Commented on Explain PHP Generators

For large numbers, I usually write them in E-notation to avoid mistakes and make it easier to visually parse later. Works in PHP, JS, and many other languages.

1e3 === 1000;
1e6 === 1000000;
6.022e23 === 602200000000000000000000;