JohnnyW2001

Member Since 4 Years Ago

Experience Points
19,380
Total
Experience

620 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
172
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.

  • Community Pillar

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

Level 4
19,380 XP
May
14
4 weeks ago
Activity icon

Replied to Testing That An Email Can Be Verified

Oops. I took a moment and zoomed out. I was really overcomplicating something that was actually very simple! :) I got it to do what I want now.

May
13
4 weeks ago
Activity icon

Replied to Testing That An Email Can Be Verified

I'm sure you're probably right. It may not even be possible to do what I was hoping to. It's late here and I'm tired :)

As to what updates the email, it's simply visiting the URL:

Route::get('/verify-email/{id}/{hash}', [VerifyEmailController::class, '__invoke']) ->middleware(['auth', 'signed', 'throttle:6,1']) ->name('verification.verify');

Activity icon

Replied to Testing That An Email Can Be Verified

Hey, thanks for trying to help. My app has the simple ability to allow the user to change their email address. They request the change, an email with a verification link is dispatched to the new address, and once it's clicked then the new email is inserted into the place of the old one.

Does that help explain the situation? I basically want to replicate the behaviour of a user clicking the link in the verification email to test that their new email is inserted correctly.

Thanks again!

Activity icon

Started a new Conversation Testing That An Email Can Be Verified

I wish to have a test that checks whether or not an email can be verified successfully.

The issue I have is getting my test to visit the link created by verificationUrl() in the VerifyEmail notification. Is there a way I can easily expose this for testing purposes?

This is one way of doing it: https://stackoverflow.com/a/57714619/199700

But I was wondering if anyone knows a better way?

Activity icon

Awarded Best Reply on Send Email Verification To A New Email Address

The answer is that you can simply use the routeNotificationForMail() method to redirect emails to wherever you want. If it's a "VerifyEmail" notification I send it to their proposed email address, otherwise the notification will go to their current one.

I also override the markEmailAsVerified() and getEmailForVerification() methods in my user model to add the functionality I needed. Everything else stays the same.

Activity icon

Replied to Send Email Verification To A New Email Address

The answer is that you can simply use the routeNotificationForMail() method to redirect emails to wherever you want. If it's a "VerifyEmail" notification I send it to their proposed email address, otherwise the notification will go to their current one.

I also override the markEmailAsVerified() and getEmailForVerification() methods in my user model to add the functionality I needed. Everything else stays the same.

May
12
1 month ago
Activity icon

Started a new Conversation Send Email Verification To A New Email Address

Hi all, I'm just adding the ability for a user to change their email address in my app, but I'd like to get them to verify the new address before accepting it on their account.

Laravel has the very helpful $user->sendEmailVerificationNotification(); method, but of course it only sends to $user's current email address (and not the new proposed one).

Laravel tends to think of things before I do, so I was wondering if there was any way to send this verification email to an email address selected by the user (instead of $user->email). Looking through the code, I can't find a way, but you never know. I thought I'd check before building my own.

Thanks!

Apr
13
1 month ago
Activity icon

Replied to Laravel Blade Components... Best Practice For Props?

@martinbean That was my fault. I missed off the $attributes bag. I see now that props allow you to easily place HTML attributes wherever you'd like around a more complex component. And also make things a bit more readable if you want to use default values.

I still don't understand why disabled gets special treatment in the Laravel Breeze component, though?

Activity icon

Started a new Conversation Laravel Blade Components... Best Practice For Props?

There's a great Livewire tutorial on Laracasts by Kevin McKee where he gives an example of using Laravel components for form elements. His example looks like this:

<x-text-input
    wire:model="name"
    type="text"
    label="name"
    :required="true"
    placeholder=""
    class="" />

And the actual component file:

@props([
    'text' => "text"
    'label' => ""
    'required' => false
    'placeholder' => ""
])

<div class="{!! $attributes !!}">
  <label for="email">{{ $label }}</label>
  <input id="email"
    type="{{ $type }}"
    required="{{ $type }}"
    placeholder="{{ $placeholder }}">

etc.

Whereas Laravel Breeze follows the same pattern, but implements it far more simply:

<x-input 
    id="email" 
    class="block mt-1 w-full" 
    type="email" 
    name="email" 
    :value="old('email')" 
    required 
    autofocus />

And the actual component file:

@props(['disabled' => false])

<input {{ $disabled ? 'disabled' : '' }} {!! $attributes->merge(['class' => 'rounded-md shadow-sm border-gray-300']) !!}>

What's the reason for Kevin McKee's approach, when you could simply ignore @props and they would pass through to the rendered HTML anyway (as with Laravel Breeze's approach)?

Edit: Ignore the above question. It totally makes sense now. Still don't understand the following, though:

And why does Laravel Breeze use disabled as a @prop when it could easily be passed through in the same way required and autofocus are?

Mar
24
2 months ago
Activity icon

Replied to PHPStorm + Blade Components

This does not solve the question. At the moment PHPStorm's Laravel support doesn't extend to BladeX components yet.

This does, though: https://plugins.jetbrains.com/plugin/13441-laravel-idea/

Activity icon

Replied to PHPStorm + Blade Components

Yes! Just installed it. Does everything I wanted. Perfect!

Mar
15
2 months ago
Activity icon

Started a new Conversation Laravel Cashier: AsStripeSubscription() Not Working On Staging Server

I have a simple method on my User (actually "Customer") model to return a user's subscription renewal date:

public function subscriptionRenewalDate() : string
{
    $subscription = $this->subscriptions()->active()->first()->asStripeSubscription();

    return Carbon::createFromTimeStamp($subscription->current_period_end)->format('F jS, Y');
}

I call this method on the authenticated user from a blade template ({{ auth()->user()->subscriptionRenewalDate() }}) and it works locally, but as soon as I upload it to the remote staging server it fails with the error:

Cannot declare class App\Models\Customer, because the name is already in use

It points to this line in the Customer model:

class Customer extends Authenticatable
{

What's weird is that my unit tests all pass locally, but the ones relating to this blade template fail when Travis CI runs them. It's not database related because the tests use RefreshDatabase.

All I know is that the error is caused by asStripeSubscription(). If I remove that from the method, the blade template loads fine.

What's going on?

Mar
05
3 months ago
Activity icon

Replied to Tests Are Suddenly Failing

I could kiss you! I forgot there was another STRIPE_KEY in the PHPUNIT.XML. Everything is working fine again. Thank you!

Activity icon

Started a new Conversation Tests Are Suddenly Failing

I've been developing project for a few weeks and my 28 tests have been passing consistently. Today I added some things in preparation for deployment to staging, and now suddenly my tests are no longer working. Even really basic ones started to fail.

I forced a clearing of my cache through the artisan command (cache:clear, view:clear, config:clear, route:clear) and some of the previously not working tests started to work again.

What's incredibly strange is if I manually enter the stages from within the tests in Tinker... they work fine. They work absolutely as expected. What's more, when I use the app everything is working as expected. The only place things aren't working is in the tests... and I haven't changed the tests at all.

I feel all I've has been very innocuous. Add the following package to composer: vemcogroup/laravel-sparkpost-driver, update my Stripe keys to different account's, and add an .ebextensions folder for deployment to AWS.

Why would my tests suddenly become temperamental? I'm pulling my hair out!

Activity icon

Commented on A Unit Test Is Not Locked To A Single Class

Great stuff. It's so hard to consider going back to not doing TDD now. It feels so incredibly risky. I love having more confidence in my ability to refactor.

Feb
27
3 months ago
Activity icon

Replied to Secure Against Laravel 8.4.2 Debug Mode - Remote Code Execution

Using Laravel 6 isn't the issue per se, as it has security fixes until September 6th, 2022, but you will need to update Laravel to the latest version (use composer update). I believe this will get patches (6.x.x).

That said I can't see a list of the Laravel 6 minor versions anywhere, so it's difficult to know what the latest 6.x you should be using is.

https://laravel.com/docs/6.x/releases

Activity icon

Replied to Where To Learn? ... Tried Laracasts!

Laracasts is a phenomenal resource. It's my go to, and I don't really understand what you mean about it being "out of date"? The differences between 6 and 7/8 are largely minor (the whole Jetstream debacle aside), and you can quickly watch the "What's New?" series to see what's changed.

The reason they haven't done a whole new Laravel from Scratch series is simply because it's largely not needed. I'm currently building a Laravel 8 app (I jumped from 5 to 8 -- that was painful at first), and the tutorials are still very much working exactly as expected. In fact I've yet to encounter anything out of date (aside from the namespace changes which are listed underneath every video as a reminder to everyone).

I guess everyone likes different teaching styles, but for my money (and I'm a subscriber, so I mean that literally) Jeffrey Way is a superb teacher. The difference between a good teacher and a great teacher is the student leaves with the confidence to solve problems by themselves. Way is quite simply one of the best teachers I've ever had in my life. Possibly the best.

But again, each to their own.

Activity icon

Replied to Extending CRUD Methods

Ha, I've never seen someone use a Request like that before. Interesting :) I guess it shows the flexibility to solve problems in ways that make sense to you.

For my question, it's less about multiple model writes, and just doing a bunch of heavy lifting before I can persist something to the database. Things that will happen every time. It feels like it must be a common situation and I was wondering if a) there were any best practices, or b) how people approached situations like this.

Of course, it's very possible I'm over-engineering this, but it's a problem I've encountered before and never really felt I'd found a good solution to. Be interesting to see what others say.

Activity icon

Started a new Conversation Extending CRUD Methods

I often find myself in projects where I have additional business logic that I'd like to execute before persisting a model to the database. In the past I've approached this in a number of ways, but the one that seems to make the most sense isn't available to me... overwriting the create(), update(), etc. methods.

Things I've tried include:

  • Putting the business logic in the controller (nasty).
  • Breaking the steps I need to accomplish into smaller methods and calling them from the controller in order (better, readable at least, but still more involved than I'd like).
  • Creating a competing method in the model class (eg. createPost() - so long polymorphism!).

I've done research into Events. Is this the best place to put logic like this? They seem better suited to "side effects" (eg. send the user an email upon registering, etc) than putting heavier logic in place.

My ideal solution would be just to be able to call $model->create() and the model takes care of all the steps, and I don't have to know how. But there's no mention of the best practices for where to put this sort of logic.

Real world example

I wish to generate a unique access code for a third party service, which is then saved on the user's account for them to use.

Ideally I'd just want $user->accessCode->create($attributes).

However there a number of steps I need to accomplish first:

  1. Generate a cryptographically secure unique access code.
  2. Generate an OAuth2 access token for the third party service.
  3. Use the access token to send the unique access code I've generated to the third party service.
  4. THEN persist the new access code to the user's account.

There's actually several other steps, too (like checking to see that they're entitled to have an access code, etc).

I've love to break many of these steps into single responsibility private methods within the model and just call $user->accessCode->create($attributes). Then it can go about calling the methods (eg. generateAccessCode(), getAccessToken(), registerAccessCode(), etc.) and taking responsibility for itself.

After all I don't need to know the steps involved, it can just go ahead and do the steps required and report back when it's done.

What is the "best practice" way to approach these situations? Is using something like Event Closures the best way to go?

Thanks.

Feb
21
3 months ago
Activity icon

Commented on Limit Access To Authorized Users

Just one additional thing, which has thrown me in the past, you can also establish authorisation rules in Requests. I presume the Policy method is the one that's recommended (it's more flexible and can be used elsewhere in your project), but I always feel uneasy adding:

public function authorize()
{
    return true;
}
Activity icon

Commented on Limit Access To Authorized Users

JW is the greatest Laravel instructor out there. Just have to say that once in a while. He makes everything so simple to understand and is the reason I subscribe to Laracasts. Thanks @jeffreyway

Feb
10
4 months ago
Activity icon

Commented on Handle Incoming Webhooks

Found it: https://beyondco.de/docs/expose/introduction

It can be installed globally using composer:

composer global require beyondcode/expose
Activity icon

Commented on Handle Incoming Webhooks

Where do you get "expose"? Can you get it over brew? It's a difficult thing to Google! It doesn't seem to appear anywhere: https://www.softwaretestinghelp.com/ngrok-alternatives/

Feb
05
4 months ago
Activity icon

Replied to Running Cashier's Unit Tests

Yep, I understand that now. What I don't understand is why I have all these files in my vendor/laravel/cashier/ folder that really shouldn't be there, though. So weird!

I have laravel/cashier v12.6.3. I wonder why the .gitattributes was ignored. I guess it's harmless. Just odd.

Activity icon

Replied to Running Cashier's Unit Tests

@tippin Ah. Weird. My /vendor/laravel/cashier/ folder has a tests/ folder, filled with a bevy of tests. And the Laravel documentation says:

When testing, remember that Cashier itself already has a great test suite

I think both of those things threw me into thinking I was supposed to be using the supplied tests.

Thanks for clarifying. I can write my own integration tests for my app. I just didn't want to double up with if I didn't have to.

Thanks!

Edit: In fact, looking at the folder now, it seems the .gitattributes have been completely ignored! I have a .github/ folder and everything else that was supposed to be blocked (eg. .gitignore). Weird!

Edit edit: I'm using the package mentioned in the Laravel documentation: composer require laravel/cashier. I assume this is why? But actually I'm not sure. Really bizarre.

Activity icon

Started a new Conversation Running Cashier's Unit Tests

I understand the Laravel Cashier comes with a comprehensive suite of tests. I feel very dumb, but how am I supposed to run them?

I've tried php artisan test vendor/laravel/cashier/tests/ but I got the error message:

Fatal error: Uncaught Error: Class 'Laravel\Cashier\Tests\Feature\FeatureTestCase' not found in /PROJECT/vendor/phpunit/phpunit/src/TextUI/Command.php on line 97

I tried moving the FeatureTestCase from the vendor directory to my projects Tests/Feature directory, but obviously I got a similar error due to the namespace being Laravel\Cashier\Tests\Feature (which makes me feel I shouldn't be moving it).

What am I missing?

Activity icon

Commented on Installation And Usage

"Ends at" is null in the database (22:09 in the video). Why?

Jan
29
4 months ago
Activity icon

Commented on Email Verification

It would be amazing to explain the differences/similarities between Breeze, Jetstream and Fortify. I started my app with Breeze because I thought that was the most likely to be similar to Laravel 5 (which I know the best), but now it seems that Fortify might have been the right solution. (I've spend hours picking out TailWind and useless blade components from the Breeze installation.)

However, what's really confusing is that I can't see any of this Fortify configuration with Breeze installed.

Honestly Laravel used to make my life EASIER. What happened to it?

Activity icon

Commented on Login And Registration

I don't understand why you're not putting the registration and login views inside the AuthenticationSessionController?

Jan
18
4 months ago
Activity icon

Commented on Customize Routes

It depresses me so much that Laravel, once the cleanest and most developer friendly PHP framework, has been reduced to manually copying routes from the vendor folder. It feels like Laravel cares more about the beginner than it does the experienced developer. Hiding away routes that any project of reasonable complexity would need exposed.

Same goes for actions. And controllers.

It's crazy. Now we're expected to manually get the project to a point where any normal developer would want it to be out of the box. Or at least through artisan commands.

Laravel, what happened to you? You're such a mess! :'(