Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

Loots

Loots

Member Since 7 Months Ago

Experience Points
15,210
Total
Experience

4,790 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
144
Lessons
Completed
Best Reply Awards
0
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 4
15,210 XP
Nov
22
3 days ago
Activity icon

Replied to 419 Page Expired When Logging In Twice Using Laravel Jetstream

I'm sorry, I'm not sure which is the logical order according to you.

A: VerifyCsrfToken->RedirectIfAuthenticated

or B: RedirectIfAuthenticated-> VerifyCsrfToken

I think you mean A? Because you don't consider the request valid because of the wrong csrf token?

A friend of mine was testing the application, he was just clicking around, he wasn't trying to break it or anything. He got the 419 and thought it was a bug. I get why you say the request isn't valid, but if a non-malicious user gets the 419, the application just seems buggy... Thanks for your quick reply btw!

Activity icon

Replied to 419 Page Expired When Logging In Twice Using Laravel Jetstream

So it's because of the web middleware group, more specifically the implementation in this class: \App\Http\Middleware\VerifyCsrfToken::class?

Because if that's the case, wouldn't it make more sense to first use the guest middleware, so the user is redirected to the dashboard, and the user doesn't get the error? Or would that be a security risk?

--edit: I just tried this using middleware priority, it does solve my problem. But I'm still not sure if this would be a security risk. I would think not, because the request information is not actually used

Activity icon

Started a new Conversation 419 Page Expired When Logging In Twice Using Laravel Jetstream

Hi everyone,

I noticed something that might be a bug, but I'm not sure. So before I file a bug report I wanted to ask if you have an explanation.

I'm using a fresh laravel jetstream project to be sure that I didn't insert the bug myself. To replicate the 419 page:

-Register a new user -open 2 login windows in separate tabs -login with both tabs -> the second try will give a 419 page.

When I check the laravel fortify package, it seems like this is not the intended behaviour (and it would be strange). In the routes file the post request should go through the guest middleware, and the guest middleware should redirect to the dashboard if the user is already authenticated. Or am I missing something? Thanks for your help!

Nov
10
2 weeks ago
Activity icon

Replied to UpdateOrCreate For BelongsTo Relationship

Actually, your first code segment is perfect! There will be no select query because indeed, it wil use the default empty one when public_address_id is null. There is no extra query fired because of this, and it's concise.

I did update a little bit, because the save() method returns a bool. So you get this:

    public function publicAddress(): BelongsTo
    {
        return $this->belongsTo(Address::class)->withDefault();
    }

    public function updatePublicAddress(array $values): bool
    {
        $this->publicAddress->fill($values)->save();

        $this->publicAddress()->associate($this->publicAddress);
        return $this->save();
    }

I still have to add some validation, but other than that, it works perfectly! Thanks for your help! I would have looked way to long just to be sure such a method doesn't exist...

Activity icon

Started a new Conversation UpdateOrCreate For BelongsTo Relationship

Hi!

I want to create a package for adding addresses to models. But I don't want to use Polymorphic relationships because in my opinion, they should be avoided when not necessary. So on the Models that have an address. I want to use a belongTo relationship:

    public function billingAddress()
    {
        return $this->belongsTo(Address::class)->withDefault();

    }

billing_address_id is a nullable field and by default it will just return an empty Address Model so you don't need conditionals. My question is: how can I best update this nullable field? I created a updateBillingAddress method on the model:

    public function updateBillingAddress($array)
    {
        if (!$this->billing_address_id) {
            $this->billing_address_id = $this->billingAddress()->create($array)->id;
        }
        else {
            $this->billingAddress()->first()->fill($array)->save();
        }

        $this->save();
    }

But I have a feeling this should be easier. I looked through the documentation, updateOrCreate looks promising, but it's not perfect:

    public function updateBillingAddress($array)
    {
        $this->billing_address_id = $this->billingAddress()->updateOrCreate([], $array)->id;

        $this->save();
    }

I still have to assign the id to the billing_address_id, while it would make sense that this happens automatically... Also I still have to call the save() method afterwards, although this isn't a big deal because it will only be saved when the address didn't exist yet and the model is dirty. One more 'problem' is that it will run a query to search for the address even if the current billing_address_id is null, which makes no sense.

So I expect there to be an update method:

$aModel->billingAddress()->updateOrCreate2(['house_number' => 1]);

That also assigns the new id to the billing_address_id and only tries to find an existing address if the billing_address_id is not null... And also saves the current model if the address had to be created.

Oct
27
4 weeks ago
Activity icon

Replied to Feedback On My First Laravel Composer Package

Hi @sinnbeck

Thanks for your feedback! I did most of the things you suggested. Although I only have one automatic test and another manual test that can run via an artisan command (it's to test the configuration). And of course I still have to add the README.md. I learned a lot by making this package!

I just have one more question. Would you personally consider this package useful? And why/why not? The reason I like to make the templates in mailjet is because it's easily accessible by non technical people. And to me that's important because those people might know a lot more about email design/marketing strategies than I do. Of course it's also possible to import everything into the project after each change but that's a lot of work. And when sending a lot of emails it becomes an overhead to include those html/text messages in every request.

Oct
26
1 month ago
Activity icon

Replied to Where Are You All From?

Belgium

Activity icon

Started a new Conversation Feedback On My First Laravel Composer Package

Hi everyone!

I just created my first laravel composer package and uploaded it to packagist:

packagist: https://packagist.org/packages/loots-it/laravel-mail-template-channel github: https://github.com/Loots-it/laravel-mail-template-channel

The main reason I build this package is because I want to use Jetstream for my auth scaffolding, but I like to use mailjet templates for my transactional mails instead of the standard laravel mail templates/logic. That's why I created a new ExternalMailTemplateChannel, it's a variant on the standard MailChannel from Laravel. All you have to do to integrate it with the Jetstream scaffolding is change the Jetstream notifications to use the new ExternalMailTemplateChannel class by implementing the toExternalMailTemplate() method and adding the channel in the via() method. Which should be pretty easy. The other channel can then be deleted in the via() method.

To be honest, I still have some refactoring to do, I want to create a 'ExternalTemplateMailMessage' that has to be returned from the notifications to make the toExternalMailTemplate function easier to read and independent of the implemented driver. At the moment the function looks like this for the VerifyEmail notification.

    public function toExternalMailTemplate($notifiable) {

        $variables = [
            "confirmation_link" => $this->verificationUrl($notifiable)
        ];

        return [
            'Subject' => "Verify email address",
            'TemplateID' => 1, //example id
            'Variables' => $variables
        ];
    }

I would love to get some feedback on the package and composer packages in general, because it's my first ever. I know I still have to do some refactoring. But other than that, what is your recommended folder structure in packages? I've seen some packages with the structure contracts/, providers/, services/, facaded/ and it seems nice, but it didn't feel appropriate because this package was so small. What do you think is important for open source packages? And what are the most important things that are missing in mine? Could I have implemented the same functionality using the standard mail channel, in your opinion? I know tests would be a nice addition, but I currently don't know what's the best approach for that. Any suggestions would be appreciated :)

Update: one more thing I also want to refactor is the general from email address and name. At the moment these are stored in the ENV variables, it seems better to be able to config these in a separate config file, just like for the MailChannel.