twoarmtom

Member Since 3 Years Ago

Beamsville

Experience Points
12,950
Total
Experience

2,050 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
106
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.

  • Community Pillar

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

Level 3
12,950 XP
Mar
05
1 month ago
Activity icon

Replied to Sending Email During Import: No Query Results For Model [App\User]

Thank you, the delay seems to be working. I really appreciate your time.

Activity icon

Replied to Sending Email During Import: No Query Results For Model [App\User]

Yes, it is part of the import, I wondered if it was maybe because the sleep(2) function would prevent the user import from being complete before the Mail would be attempted, so the user wasn't added yet. When I removed the sleep(2) function it seemed to work, maybe because the test import is only 4 users and it quickly made it through the loop before the queue attempted to send the email. Might not be so lucky with a larger import so I like your idea of delay.

Would the best way to use a delay be to change the queue function to later like so?

$when = now()->addMinutes(5);

Mail::to($user)->later($when, new NewAccount($user, $token));

Thank you for your help and advice, much appreciated!

Mar
04
1 month ago
Activity icon

Replied to Sending Email During Import: No Query Results For Model [App\User]

I used the sleep(2) function because of limits with Mailtrap, and I wasn't using a queue worker in my local environment. I just realized that if I remove the sleep(2) function it works in production.

My worry is that there may be issues with the mail server if I import hundred of users and there's no pause between each user.

Is this worry I have avoided by using the redis queue? Sorry if this is a dumb question.

Activity icon

Replied to Sending Email During Import: No Query Results For Model [App\User]

Interestingly enough, I went in a tested it again (after deleting users) and it worked, but then I tried again (after deleted users again) and it failed with the same issue as before. Not sure why it is being so inconsistent.

Activity icon

Replied to Sending Email During Import: No Query Results For Model [App\User]

Just the first one goes through, then the same failed message. I'm testing it with 4 users.

Activity icon

Started a new Conversation Sending Email During Import: No Query Results For Model [App\User]

I have the following Import function:

public function collection(Collection $rows)
    {
        foreach($rows as $row)
        {
            if(User::where('email', $row['email'])->first() == null)
            {
                $user = User::create([
                    //
                'name'     => $row['name'],
                'email'    => Str::lower($row['email']), 
                'password' => Hash::make(Str::random(10)),
                ]);
                $role = $row['role'];
                $location = $row['location'];
            
                $user->roles()->attach($role);
                $user->hospital()->attach($location);
                $token = app('auth.password.broker')->createToken($user);

                Mail::to($user)->queue(new NewAccount($user, $token));
            }
            sleep(2);
        }

    }

In my local environment this works perfect. In production the email part of this loop is failing (and I know emails work, I've tested them with password resets etc.).

In Laravel Horizon it shows:

ID 111

Queue default

Tags App\User:207

Failed At 2021-03-04 15:18:16

And it gives this error:

Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\User]

The NewAccount Mail is:

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\User;

class NewAccount extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

        
    /**
     * Create a new message instance.
     *
     * @return void
     */
    
    public $user;
    public $token;
    public function __construct(User $user, $token)
    {
        //
        $this->user = $user;
        $this->token = $token;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->markdown('emails.setpassword');
    }
}

The only difference between local and production that I can think of is the use of Redis for queue. In my local environment I'm not using Redis.

Any ideas why this may be failing? I should add that this mail class is used for normal registration and works without issue.

Dec
04
4 months ago
Activity icon

Started a new Conversation Problem Adding Headers To Mail Message In Laravel 7.x

I'm trying to add a .env variable to a message header to help me identify my installations when new accounts are created but the user emails fail (I have the same Laravel application installed on different servers for different clients). I've tried the methods described in the documentation:

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    $this->view('emails.setpassword');

    $this->withSwiftMessage(function ($message) {
        $message->getHeaders()
                ->addTextHeader('X-Mailgun-Variables', env('APP_SCHOOL') . ' USER:' . Auth::id());
    });
}

And I've tried other combinations like this:

/**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {

        return $this->markdown('emails.setpassword')->withSwiftMessage(function ($message) {
            $message->getHeaders()
                    ->addTextHeader('X-Mailgun-Variables', env('APP_SCHOOL') . ' USER:' . Auth::id());
        });
    }

My Mailgun details show up like this (adjusted to hide data) without the extra headers:

	"message": {
		"headers": {
			"to": "User Name <[email protected]>",
			"message-id": "[email protected]",
			"from": "Application Support <[email protected]>",
			"subject": "New Account"
		},
		"size": 11451
	},

Can anyone see an issue why it wouldn't be sending the header?

Nov
18
4 months ago
Activity icon

Replied to Livewire And Bootstrap Datepicker

I was having a similar issue and this fixed it, thanks!

Oct
23
5 months ago
Activity icon

Replied to Highlight Inputs When There Are Duplicates In A V-for Loop With Computed Property

@silencebringer That was perfect, and much more elegant than I expected, thank you!!

Activity icon

Started a new Conversation Highlight Inputs When There Are Duplicates In A V-for Loop With Computed Property

I have a v-for loop that shows the order of quiz questions (the order is a pivot column) and I'd like the class is-invalid to be added to all inputs if the client accidentally sets a duplicate order value.

Could someone suggest a way to do this with a computed property?

<div v-for="(question, index) in questions" :key="index">
    <div class="pb-3">
        {{ question.stem_en }}
    </div>
    <div class="form-group row">
        <div class="col-md-1">
            <label>Order:</label>
        </div>
        <div class="col-md-2">
 	<!-- I want the inputs to have class 'is-invalid' if any these values appear more than once in the loop -->
            <input type="number" class="form-control" v-model="question.pivot.order">
        </div>
        <div class="col-9">
            <button @click.prevent="updateOrder(quiz.id, question.id, question.pivot.order)"
                class="btn btn-primary">Update Order</button>
            <button @click.prevent="deleteQuestion(quiz.id, question.id)" class="btn btn-danger">Remove from
                Quiz</button>
        </div>
    </div>
    <hr>
</div>