sirhxalot

sirhxalot

Member Since 4 Years Ago

Zurich

Experience Points
42,230
Total
Experience

2,770 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
360
Lessons
Completed
Best Reply Awards
7
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
42,230 XP
Mar
19
2 months ago
Activity icon

Replied to Logging ID While Storing New Record To Database

Hi @mleontenko

Since you store the post using the save() method you can receive the id using $post->id.

Mar
06
2 months ago
Activity icon

Replied to Stripe Notice Undefined Property (MetaData) In Unit Tests

By the way my first attemp was to try the following:

$user->createOrGetStripeCustomer(['metadata' => ['billing_title' => null, 'billing_name' => null]);

But it didn't solved the issue?

Mar
05
2 months ago
Activity icon

Replied to How To Disable Casting During Testing

This is where the error will be thrown:

$user = new User(['status' => 'example']);

Since you are casting you must convert the value to App\Enums\UserStatus you can not assign a string.

Activity icon

Replied to How To Disable Casting During Testing

@xtremer360

Which Laravel version are you using?

What is the error message than?

Activity icon

Replied to How To Disable Casting During Testing

In Laravel 7 you should use: getRawOriginal(). Before you can use getOrginal()

Activity icon

Replied to How To Disable Casting During Testing

Hi @xtremer360!

I didn't test this answer but could you please try:

$model->getOriginal('foo')

It depends on your Laravel version: https://laravel.com/docs/7.x/upgrade

Activity icon

Started a new Conversation Stripe Notice Undefined Property (MetaData) In Unit Tests

Hi Folks!

I have created a unit test in order to proof if the metadata of a Stipe customer can be updated. When I filter the test everything runs successfully hoewever if I run the test suit I recieve notices: Stripe Notice: Undefined property of Stripe\StripeObject instance: billing_title. The billing_title is a metadata for a stripe user. Here is how I test it right now:

$user = factory(User::class)->create();
$user->createOrGetStripeCustomer();

        $billingData = [
            'name' => $user->name,
            'metadata' => [
                'billing_title'  => 'Dr. Prof. B',
                'billing_name'   => 'Kill Bill',
            ],
            'phone' => '111111 B',
            'address' => [
                'line1' => 'Slaughter Road 6B',
                'postal_code' => '1111 B',
                'city' => 'Tinker Bell B',
            ]
        ];

        $user->updateStripeCustomer($billingData);

        $billingDataAssertion = [
            'title' => 'Dr. Prof. B',
            'name' => 'Kill Bill',
            'company_name' => 'Slaughter Road 6B',
            'location' => '1111 B Tinker Bell B'
        ];

        $this->assertEquals($user->billing_address, $billingDataAssertion);

The test does not fail. However I have these notices:

PHPUnit 8.5.2 by Sebastian Bergmann and contributors.

................................................................. 65 / 94 ( 69%)
.........Stripe Notice: Undefined property of Stripe\StripeObject instance: billing_title
.Stripe Notice: Undefined property of Stripe\StripeObject instance: billing_title
Stripe Notice: Undefined property of Stripe\StripeObject instance: billing_title
Stripe Notice: Undefined property of Stripe\StripeObject instance: billing_title
...................                                     94 / 94 (100%)

Time: 22.32 seconds, Memory: 46.50 MB

OK (94 tests, 178 assertions)

It seems that everything is working. In production the metadata will be set and I receive the correct billing address. Do I have to worry about these notices? Can I disable them?

Best regards Alexander

Feb
21
3 months ago
Activity icon

Awarded Best Reply on Changing Font To Google Font In Email Template

<link href="https://fonts.googleapis.com/css?family=Heebo&display=swap" rel="stylesheet"> 
<p style="font-family: Heebo">Should be formated</p>

Does this work?

Feb
20
3 months ago
Activity icon

Replied to Stripe InvoiceFor Billing Details

@bobbybouwmann sorry for the wording but you are fucking awesome!

For real I appriciate your help so much - you are superman, or Jeffrey Way - Keep on going!

Here is a quick hint:

        $user->createOrGetStripeCustomer([
            'address' => [
                'line1' => 'Evergreen Terrace 5'
            ]
        ]);

Which result in:

Activity icon

Replied to Changing Font To Google Font In Email Template

It worked at least for me:

Activity icon

Replied to Changing Font To Google Font In Email Template

<link href="https://fonts.googleapis.com/css?family=Heebo&display=swap" rel="stylesheet"> 
<p style="font-family: Heebo">Should be formated</p>

Does this work?

Activity icon

Replied to Changing Font To Google Font In Email Template

By the way: body *:not(html):not(style):not(br):not(tr):not(code) is not valid you may tried: *:not(html):not(style):not(br):not(tr):not(code) which can not be used within email clients: https://www.campaignmonitor.com/css/selectors/universal/

Activity icon

Replied to Changing Font To Google Font In Email Template

@eddieace Please give it at least a try.

<p style="font-family: Avenir">Should be formated</p>

I am sure that your CSS rule will not be supported by email clients.

Activity icon

Replied to Stripe InvoiceFor Billing Details

@bobbybouwmann Thank you (again ;)

Do you know how I can found out what array keys are expected for $options? Is there a list or can I jump to any source code to get a list?

Thank you in advance.

Activity icon

Replied to Changing Font To Google Font In Email Template

In your case you must add the font-family to the elements you cannot use the body for global font assignement. Working with emails can sometimes be a pain - If you are interested I am using Inky: https://get.foundation/emails/docs/

It helps alot.

Activity icon

Replied to Changing Font To Google Font In Email Template

@eddieace Hi!

Please checkout: https://litmus.com/blog/the-ultimate-guide-to-web-fonts

Web fonts are available for most email clients.

Activity icon

Awarded Best Reply on How To Pass Parameter To Redirect

Hi @noblemfd!

You can use the route() helper method therefore. Like:

$this->redirect(route('route.name', ['param1' => 'first']));

https://laravel.com/docs/5.8/helpers#method-route

Activity icon

Replied to How To Pass Parameter To Redirect

Hi @noblemfd!

You can use the route() helper method therefore. Like:

$this->redirect(route('route.name', ['param1' => 'first']));

https://laravel.com/docs/5.8/helpers#method-route

Activity icon

Started a new Conversation Stripe InvoiceFor Billing Details

Hi Folks!

I am using Larvel Cashier in order to make a single charge for a credit card. But instead of using the ~~charge~~ method I am using the invoiceFor method of cashier:

 $user->invoiceFor(__('events.1.title'), $user->participation->plan_price, [], []);

Now I want to update the billing details from the payment method. Does somebody know how to achieve this?

When I dd the payment method I receive something like:

Laravel\Cashier\PaymentMethod {#392 ▼
  #owner: App\Models\User {#351 ▶}
  #paymentMethod: Stripe\PaymentMethod {#374 ▼
    +saveWithParent: false
    #_opts: Stripe\Util\RequestOptions {#363 ▶}
    #_originalValues: array:9 [▶]
    #_values: array:9 [▶]
    #_unsavedValues: Stripe\Util\Set {#376 ▶}
    #_transientValues: Stripe\Util\Set {#377 ▶}
    #_retrieveOptions: []
    #_lastResponse: null
    id: "NoNo"
    object: "payment_method"
    billing_details: Stripe\StripeObject {#378 ▼
      #_opts: Stripe\Util\RequestOptions {#363 ▶}
      #_originalValues: array:4 [▶]
      #_values: array:4 [▶]
      #_unsavedValues: Stripe\Util\Set {#380 ▶}
      #_transientValues: Stripe\Util\Set {#381 ▶}
      #_retrieveOptions: []
      #_lastResponse: null
      address: Stripe\StripeObject {#382 ▼
        #_opts: Stripe\Util\RequestOptions {#363 ▶}
        #_originalValues: array:6 [▶]
        #_values: array:6 [▶]
        #_unsavedValues: Stripe\Util\Set {#384 ▶}
        #_transientValues: Stripe\Util\Set {#385 ▶}
        #_retrieveOptions: []
        #_lastResponse: null
        city: null
        country: null
        line1: null
        line2: null
        postal_code: "44444"
        state: null
      }
      email: null
      name: "MICKEY MOUSE"
      phone: null
    }
    card: Stripe\StripeObject {#379 ▶}
    created: 1582205683
    customer: "NoNo"
    livemode: false
    metadata: Stripe\StripeObject {#383 ▶}
    type: "card"
  }
}

This is why I thought I can update the data like the following:

$paymentMethod = auth()->user()->paymentMethods()->first();
$paymentMethod->billing_details->email = auth()->user()->email;
$paymentMethod->save();

Unfortunally that does not work - so how to update the data?

Thank you in advance and best regards Alexander

Activity icon

Replied to Laravel Pivot Multiple Table Condition

@karolgil I am pretty sure that you are firing multiple queries you are passing the query object within the closure. If you want to check how many queries where fired checkout: https://github.com/laravel/telescope

And please don't missunderstand me. If you are happy with your implementation than that's okay. I just try to help you improve your code ;)

Best regards Alexander

Feb
12
3 months ago
Activity icon

Replied to Laravel Pivot Multiple Table Condition

Hi @karolgil! You can do that however I reccomend to use joins:

  • They are more performant.
  • They are easier to read.

Your example fires multiple queries which is bad. When using join you can handle everything in one query and its easier to read - at least for artisans :)

Best regards

Feb
11
3 months ago
Activity icon

Awarded Best Reply on Laravel 5.8.35 Auth.failed Message Instead Of The Default One

And in your case it seems that you have changed the default locale?

Activity icon

Replied to Laravel 5.8.35 Auth.failed Message Instead Of The Default One

And in your case it seems that you have changed the default locale?

Activity icon

Replied to Laravel 5.8.35 Auth.failed Message Instead Of The Default One

Hi @allenek your translation file is missing.

Please chekck if the file resources/lang/en/auth.php exists if not you can download it from here: https://github.com/laravel/laravel/blob/master/resources/lang/en/auth.php

Activity icon

Awarded Best Reply on How To Test If A Verification Email Was Queued?

@sti3bas Thank you for your help! I have found out what the problem was:

The assertion sent to used a user that doesn't exists. I had to fetch the genereated user and than do the assertion - so the assertion end up like this:

    public function it_queues_a_verification_notification_email()
    {
        $user = factory(User::class)
            ->make()
            ->makeVisible(['password']);

        Notification::fake();

        Notification::assertNothingSent();

        $this->put(
            route('auth.register.store'),
            $user->toArray()
        );

        $user = User::firstWhere('email', $user->email);

        Notification::assertSentTo($user, VerificationEMail::class);

        Notification::assertTimesSent(1, VerificationEMail::class);
    }

Using the $this->expectsEvents(\Illuminate\Auth\Events\Registered::class); was not a good idea since it fakes the events so after this line the event will never triggered.

Stupid mistake I am sorry for that.

Activity icon

Replied to How To Test If A Verification Email Was Queued?

@sti3bas Thank you for your help! I have found out what the problem was:

The assertion sent to used a user that doesn't exists. I had to fetch the genereated user and than do the assertion - so the assertion end up like this:

    public function it_queues_a_verification_notification_email()
    {
        $user = factory(User::class)
            ->make()
            ->makeVisible(['password']);

        Notification::fake();

        Notification::assertNothingSent();

        $this->put(
            route('auth.register.store'),
            $user->toArray()
        );

        $user = User::firstWhere('email', $user->email);

        Notification::assertSentTo($user, VerificationEMail::class);

        Notification::assertTimesSent(1, VerificationEMail::class);
    }

Using the $this->expectsEvents(\Illuminate\Auth\Events\Registered::class); was not a good idea since it fakes the events so after this line the event will never triggered.

Stupid mistake I am sorry for that.

Activity icon

Replied to How To Test If A Verification Email Was Queued?

Yes I did. And I am 99% sure that there is no error with the registration itself.

The following assertion works this is why I am confident that the registration itself works:

    public function its_stores_a_new_user()
    {
        $user = factory(User::class)
            ->make()
            ->makeVisible(['password'])
            ->toArray();

        $this->assertDatabaseMissing(
            'users', [
            'email' => $user['email']
            ]
        );

        $this->put(
            route('auth.register.store'),
            $user
        );

        $this->assertDatabaseHas(
            'users', [
            'email' => $user['email']
            ]
        );
    }

This turns into green.

Activity icon

Replied to How To Test If A Verification Email Was Queued?

This is my testing environment:

APP_NAME="A cool Name"
APP_ENV=testing
APP_KEY=base64:w9ZOK0PIt4/xmNb5T7WRBtzG4hAVPrbUphhSnx9OlEo=
APP_URL=http://localhost

STRIPE_KEY=not_for_public
STRIPE_SECRET=not_for_public

DB_CONNECTION=sqlite_testing
DB_DATABASE=":memory:"

BCRYPT_ROUNDS=4

CACHE_DRIVER=array
MAIL_DRIVER=array
SESSION_DRIVER=array
BROADCAST_DRIVER=null

QUEUE_CONNECTION=sync
QUEUE_DRIVER=sync

CYON_LOG="log-file-name"

Any errors with that?

Activity icon

Replied to How To Test If A Verification Email Was Queued?

Unfortunally same failure.

I have dump and died: User::first() and $user both give me a App\User eloquent class.

Activity icon

Replied to How To Test If A Verification Email Was Queued?

@sti3bas you are right!

When I put the expectsevents to the top it turns greeen.

But when I uncomment the Notification assertion sent to it still fails:

1) Tests\Feature\SignUpTest::it_queues_a_verification_notification_email
The expected [App\Notifications\User\VerificationEMail] notification was not sent.
Failed asserting that false is true.

Current implementation:

    public function it_queues_a_verification_notification_email()
    {
        $this->expectsEvents(\Illuminate\Auth\Events\Registered::class);

        $user = factory(User::class)
            ->make()
            ->makeVisible(['password']);

        Notification::fake();

        Notification::assertNothingSent();

        $this->withoutExceptionHandling();

        $this->put(
            route('auth.register.store'),
            $user->toArray()
        );

        Notification::assertSentTo($user, VerificationEMail::class);
    }
Activity icon

Replied to How To Test If A Verification Email Was Queued?

And just to eliminate any missunderstandings this is the current implementation of the test:

    public function it_queues_a_verification_notification_email()
    {
        $user = factory(User::class)
            ->make()
            ->makeVisible(['password']);

        Notification::fake();

        Notification::assertNothingSent();

        $this->withoutExceptionHandling();

        $this->put(
            route('auth.register.store'),
            $user->toArray()
        );

        $this->expectsEvents(\Illuminate\Auth\Events\Registered::class);

        // Notification::assertSentTo($user, VerificationEMail::class);
    }
Activity icon

Replied to How To Test If A Verification Email Was Queued?

@sti3bas - Thank you!

Event Verified

When I make the assertion $this->expectsEvents('Illuminate\Auth\Events\Verified');

I will receive the following console output:

1) Tests\Feature\SignUpTest::it_queues_a_verification_notification_email
These expected events were not fired: [Illuminate\Auth\Events\Verified]
Failed asserting that an array is empty.

Event Registred

The assertion you shared: $this->expectsEvents(\Illuminate\Auth\Events\Registered::class); turns into the same error:

1) Tests\Feature\SignUpTest::it_queues_a_verification_notification_email
These expected events were not fired: [Illuminate\Auth\Events\Registered]
Failed asserting that an array is empty.

Conclusion

This brings me to the conclusion that the events will not be triggered during testing. But why?

Activity icon

Replied to How To Test If A Verification Email Was Queued?

I have now tried out the following:

$this->expectsEvents('Illuminate\Auth\Events\Verified');

Even this assertion fails? How can I trigger the event correctly?

Feb
10
3 months ago
Activity icon

Replied to Can Elm Be Used Effectively With Laravel? Can I Just Replace Vue With Elm?

Hi @olimejj! First of all changing the frontend to your prefered way is a good idea - every developer should be confident with the tools he/she's using.

Laravel does not dictate any frontend libraries at all - even vie.js is optional - take a peak to: https://laravel.com/docs/6.x/frontend

I am not aware of elm but i didnt see any problems with the integration?

Maybe the following will help to getting started: https://github.com/tightenco/laravel-elm

Activity icon

Replied to How To Test If A Verification Email Was Queued?

Thank you. I have done this aswell and also Queue.

Fact is my custom verification email is a notification that implement shoulqueue. Its not a mail but as I said i have tried out all possible mockings.

Activity icon

Replied to How To Test If A Verification Email Was Queued?

@sti3bas Thank you for the reply - i have done that same error.

Activity icon

Replied to How To Test If A Verification Email Was Queued?

Besides now I am testing if the original verification email was sent. I have also tested if my custom Notification was sent:

Mail::assertQueued(VerificationEMail::class);

I have also tried out Queue::assertPushed and Notification::assertSentTo.

Activity icon

Replied to How To Test If A Verification Email Was Queued?

No. I only have the failed assertion and no errors so far:

The expected [Illuminate\Auth\Notifications\VerifyEmail] mailable was not queued.
Failed asserting that false is true.
Activity icon

Replied to How To Test If A Verification Email Was Queued?

I know that the put action works from other tests where I check if a new user has been created. This is why i am sure that there is no validation error.

Activity icon

Replied to How To Test If A Verification Email Was Queued?

Besides I have added the following Queue Connection for testing purposes:

QUEUE_CONNECTION=sync
QUEUE_DRIVER=sync
Activity icon

Started a new Conversation How To Test If A Verification Email Was Queued?

Hi Folks!

I would like to write a PHPUnit test where I would like to proof if the verification email was send after register.

My goal is to override the email template used to send for the verification email therefore I have made the following changes:

App\User

    public function sendEmailVerificationNotification()
    {
        $this->notify((new VerificationEMail));
    }

App\Notifications\User\VerificationEMail

<?php

namespace App\Notifications\User;

use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class VerificationEMail extends VerifyEmail implements ShouldQueue
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        $verificationUrl = $this->verificationUrl($notifiable);

        return (new MailMessage)
            ->subject(__('verify.mail.subject'))
            ->from(__('verify.mail.from'))
            ->markdown(
                'mail.user.verification', compact(
                    'verificationUrl'
                )
            );
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

My test case looks like this:

    /** @test */
    public function it_queues_a_verification_notification_email()
    {
        $user = factory(User::class)
            ->make()
            ->makeVisible(['password']);

        Mail::fake();

        Mail::assertNothingSent();

        $this->put(
            route('auth.register.store'),
            $user->toArray()
        );

        Mail::assertQueued(VerifyEmail::class);
    }

I begin to make a user in order to have a valid user data. Than I send (put) the user to the register route which is the default register action from Laravel:

    public function register(SignupRequest $request)
    {
        event(new Registered($user = $this->create($request->all())));
        $request->flash('flash_success', __('register.success'));

        $this->guard()->login($user);

        if ($request->wantsJson()) {
            return response()
                ->json([
                    'message' => 'success',
                    'success' => true,
                ]);
        }

        return $this->registered($request, $user)
            ?: redirect()->back()->with([
                'message', 'success',
                'success' => true,
            ]);
    }

It works in produciton but not in testing. Why does my test not work? What should I do in order to test if the verification email was send to the queue and finally to the user?

Thank you in advance and best regards Alexander (sirthxalot)