vkronlein

vkronlein

Owner / Lead Developer at Periapt, LLC.

Member Since 4 Years Ago

Queen Creek, AZ

Experience Points
43,660
Total
Experience

1,340 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
466
Lessons
Completed
Best Reply Awards
1
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 9
43,660 XP
Mar
17
2 months ago
Activity icon

Started a new Conversation Caching And Session On Wrong Servers

I have my cache set to memcached and my sessions set to redis.

Cache prefix is laravel_cache and session cookie is set to laravel_session

When I log into the redis-cli and look at my keys ... I see a key for laravel_cache and nothing for sessions at all.

But when I flush all and then try and load a page I am logged out so it seems that the session is in there somewhere. Perhaps I'm misunderstanding, I don't get why I have a laravel_cache key in redis.

Furthermore, I need to be able to determine if a given user is logged in from an external API call, where would I be able to configure the session to use namespacing to check if a given user is logged in?

Feb
18
3 months ago
Activity icon

Replied to Events Inside EventListener Not Updated On Page

Here's the whole block just in case it's needed.

const stripe = Stripe('{{ env("STRIPE_KEY") }}');
const elements = stripe.elements();
const cardButton = document.getElementById('card-submit');
const errorBlock = document.getElementById('card-errors');
const style = {
    base: {
        fontSize: '20px',
        textTransform: 'lowercase',
        color: '#636b6f',
        lineHeight: '24px',
        fontFamily: 'Montserrat, sans-serif',
        fontSmoothing: 'antialiased',
        '::placeholder': {
          color: '#747d8a',
        }
    },
    invalid: {
        color: '#e57373',
        ':focus': {
            color: '#747d8a',
        },
    }
};

const cardElement = elements.create('card', {style: style});

cardElement.mount('#card-element');

cardButton.classList.add('disabled');
cardButton.setAttribute('disabled', true);

cardElement.addEventListener('change', function(e) {
    if (e.error) {
        errorBlock.textContent = e.error.message;
    } else {
        errorBlock.textContent = '';
    }

    if (e.complete) {
        alert('yep it completed');
        cardButton.classList.remove('disabled');
        cardButton.setAttribute('disabled', false);
    }
});

const cardHolderName = document.getElementById('card-holder-name');
const clientSecret = cardButton.dataset.secret;

cardButton.addEventListener('click', async (e) => {
    e.preventDefault();

    cardButton.classList.add('disabled');
    cardButton.setAttribute('disabled', true);
    cardButton.textContent = 'Processing ... ';

    const { setupIntent, error } = await stripe.confirmCardSetup(
        clientSecret, {
            payment_method: {
                card: cardElement,
                billing_details: {
                    name: cardHolderName.value
                }
            }
        }
    );

    const form = document.getElementById('payment-form');
    const method = document.getElementById('payment-method');

    if (error) {
        errorBlock.textContent = error.message;
    } else {
        method.value = setupIntent.payment_method;
        form.submit();
    }
});
Activity icon

Started a new Conversation Events Inside EventListener Not Updated On Page

I'm trying to implement stripe as per the Cashier instructions.

I've implemented an event listener to spot card errors then update the card-errors element.

cardElement.addEventListener('change', function(e) {
    if (e.error) {
        errorBlock.textContent = e.error.message;
    } else {
        errorBlock.textContent = '';
    }
    
    if (e.complete) {
        cardButton.classList.remove('disabled');
        cardButton.setAttribute('disabled', false);
    }
});

When I trigger an error and console.log the errorBlock it shows that the element has been updated:

<div id="card-errors" role="alert" class="text-danger mt-3 pl-2">
    Your card number is incomplete.
</div>

But it doesn't update the element on the page, very weird.

Same thing happens inside my cardElement listener .... I get a message that the element isn't mounted.

Any help would be appreciated.

Feb
03
3 months ago
Activity icon

Replied to Validating Remote API Data

I built a simply validation piece to check that the items in a "required" array are set in the array being passed in.

Thanks for the suggestion, kinda seems like overkill, but it's a nice abstraction to pull those big arrays out of my code.

Activity icon

Replied to Validating Remote API Data

@bugsysha

So we have our local app, and we have a remote app that we pull data from via api.

Our local user makes a request to a member of another company, which creates an account and a request object on the remote app. A member of the other company fills in information about their requested product on the remote app and submits it.

Our original user on the local app then previews the data submitted and we need to check that all the data required for our local app has been sent. If not they can then send a reply to the remote user saying, hey, please fill in these items and resubmit.

Yes, having the field required on the remote app would resolve this issue, I know. But that option is not readily available so I have to find a way to validate what's sent, and show some sort of warning for the local user.

In any event, I've been reading about DTO's per your suggestion and pulled in the Spatie package.

This does nothing really for me other than standardize the data types, and strip away any data we don't need. It doesn't do ay sort of checking or validating whether given fields have been sent, which is really what I'm after.

If for instance I have this as my fromRequest method:

public static function fromRequest(array $request): self
{
    return new self([
        'rid'           => $request['rid'],
        'name'          => $request['name'],
        'supplier_name' => $request['supplier_name'],
        'notes'         => $request['notes'],
        'mask'          => $request['mask'],
    ]);
}

If any of the $request info is not sent, I get a fatal error ... and that's exactly what Im trying to avoid.

Any other suggestions would be appreciated.

Jan
31
3 months ago
Activity icon

Replied to Validating Remote API Data

@bugsysha

Thanks for the response, but I have no experience with using those and this entire service is already built so I can't spend the time or resources to go back and replace the work already completed.

The service simply provides a user based preview of the data, so using Validator will be plenty since all I need to do is display the data, not persist it.

Thanks for the tip though, this gives me a new design pattern to learn.

Jan
30
4 months ago
Activity icon

Started a new Conversation Validating Remote API Data

Hey All.

I'm building a service that fetches an array from a user's remote account through a RESTful API.

The data comes in as a large nested array, and I'd like to use a Validator instance with rules and messages to show errors to the user, basically items that we require, that may not have been sent.

I have the basics started, but I'm wondering how to loop through nested items and create appropriate messages to pass back to Vuex.

The data is structured similar to this:

[
    'item' => [
        "name" => "Item name",
        "notes" => "Here are some notes.",
        "nested_1" => [
            0 => [
                "name" => "Item name",
                "notes" => "Here are some notes.",
                "nested_2" => [
                    0 => [
                        "name" => "Nested item name",
                        "notes" => "Here are notes.",
                        "nested_3" => [
                            0 => [
                                "name" => "Nested item",
                                "notes" => "Here are notes."
                            ]
                        ]
                    ]
                ]
            ],
            1 => [
                "name" => "Nested item name",
                "notes" => "No notes other than this.",
                "nested_2" => [
                    0 => [
                        "name" => "Nested item name",
                        "notes" => "Here are notes.",
                        "nested_3" => [
                            0 => [
                                "name" => "Nested item",
                                "notes" => "Here are notes."
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ]
]

There can be any number of arrays that are nested up to 3 levels deep, so is there an article or technique anyone can point me to that will explain how to validate all these items while still being able to keep all the errors coupled to their given item?

Yes I've Googled. I can't find anything except how to validate forms in your own Laravel API. And of course I also have the documentation open as I go so please don't point me there.

Thanks

Jan
21
4 months ago
Activity icon

Replied to Querying On Relation Column Within A Relationship

@bugsysha

Nope same result. Same error.

BUT I tried whereHas with the correct operators != and = and it seems to be working.

Thanks for the help.

Jan
20
4 months ago
Activity icon

Replied to Querying On Relation Column Within A Relationship

@jbloomstrom

Nope, you didn't read the question properly.

The status column is on the SupplierThreadStatus relationship on SupplierThread not on the SupplierThread model itself. This just throws an error since there is no status column to query.

Thanks though, I wish it was that simple, I would have been done eons ago.

Activity icon

Replied to Querying On Relation Column Within A Relationship

Well using whereHas seems to pull in the right model, but it's not hydrated with any attributes to query against. If I dump the model like below I get the SupplierThreadStatus model but an empty array for attributes.

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

The model dump looks like so:

App\Models\SupplierThreadStatus {#842 ▼
  +fillable: array:2 [▶]
  #with: array:1 [▶]
  #connection: null
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #withCount: []
  #perPage: 15
  +exists: false
  +wasRecentlyCreated: false
  #attributes: []
  #original: []
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▶]
}

I seem to be getting closer, but not quite yet.

Activity icon

Replied to Querying On Relation Column Within A Relationship

@bugsysha

No love. This throws

protected function invalidOperator($operator)
{
    return ! in_array(strtolower($operator), $this->operators, true) &&
           ! in_array(strtolower($operator), $this->grammar->getOperators(), true);
}

1. "strtolower() expects parameter 1 to be string, object given"

in the Builder class.

Any other ideas?

Activity icon

Replied to Querying On Relation Column Within A Relationship

Cool thanks @bugsysha I'll give that a go.

Activity icon

Started a new Conversation Querying On Relation Column Within A Relationship

I have a SupplierThread model that has a statuses relationship like so:

/**
 * Supplier threads have many statuses.
 *
 * @return \Illuminate\Database\Eloquent\Relations\HasMany
 */
public function statuses()
{
    return $this->hasMany(SupplierThreadStatus::class, 'supplier_thread_id', 'id');
}

I need now to have two relationships on my Company model to query live threads and archived threads. But I need those relationships to return from a given status from the thread's statuses relationship.

I saw on StackO an answer of passing an array with a closure value to with but this doesn't seem to work.

/**
 * Supplier live request threads relationship.
 *
 * @return \Illuminate\Database\Eloquent\Relations\HasMany
 */
public function supplierThreads()
{
    return $this->hasMany(SupplierThread::class)->with(['statuses' => function($query) {
        $query->where('status', '!==', 'closed');
    }]);
}

And then the supplierArchives relationships simply does the same except just the closed statuses.

But neither one is working, both queries return the same results which includes everything.

I'm sure this is probably simple, but I can't find an answer.

Thanks.