smnwk

smnwk

Member Since 5 Months Ago

Experience Points 200
Experience
Level
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

16 Dec
1 month ago

smnwk left a reply on Serialize Computed Property Carbon Instance

I've tried your workaround by overriding the php toArray() function and it works:

public function toArray()
{
        Carbon::serializeUsing(function ($carbon) {
            /** @var $carbon Carbon */
            return $carbon->toDateTimeString('d.m.Y H:i:s');
        });
        
        return parent::toArray();
 }

But php Carbon::serializeUsing can't be the sustainable solution.

I've reportet an issue in the GitHub repository:

https://github.com/laravel/framework/issues/26868

smnwk left a reply on Serialize Computed Property Carbon Instance

@VILFAGO - Yes, I did.

    /**
     * Append computed properties automatically.
     *
     * @var array
     */
     protected $appends = ['departureTime'];

Otherwise I wouldn't be added to the json object.

smnwk left a reply on Serialize Computed Property Carbon Instance

@TALINON - I'm using Laravel 5.7 but that doesn't work either. Casting with other fields that aren't computed properties works without problems. I'll report in the github repository.

15 Dec
1 month ago

smnwk started a new conversation Serialize Computed Property Carbon Instance

Hi,

my model offers a computed property called "departureTime"; if a departure time is available, it will be returned as a Carbon instance. By serializing I just want to get the date so I added a cast in my $date property (I also tried $casts) but nevertheless it does not work.

protected $dates = ['time', 'arrivalTime', 'departureTime'];

/** ... other stuff ... **/

public function getDepartureTimeAttribute() {
    if(!$this->isDriving) {
        return null;
    }

    $lastNullPosition = Track::where([
        ['speed', 0], ['created_at', '<=', $this->created_at]
    ])->orderBy('id', 'desc')->first();

    return $lastNullPosition->time;
}
"departureTime":{"date":"2018-12-15 16:33:51.000000","timezone_type":3,"timezone":"Europe\/Berlin"}

Maybe someone could help me.

13 Oct
3 months ago

smnwk left a reply on Laravel's Passport + Testing

What I meant is that if the axios request works in browser then $request->bearerToken()shouldn't be null in (the same) browser?

My intention was to get the bearer token (via the browser) to put it in Postman.

smnwk left a reply on Laravel's Passport + Testing

Hi, but the axios request works?

smnwk started a new conversation Laravel's Passport + Testing

Hi there,

I'm using Laravel's Passport to build an api backend. I implemented the CreateFreshApiToken class to consume the api with JavaScript; this works. But now I want to test my api in Postman - what's the best practice getting the Bearer attribute?

I've tried $request->bearerToken()but I only get null.

18 Aug
5 months ago

smnwk left a reply on Factory Each Closure With Belongs To Relation

Sorry for being vague. It doesn't throw an error, just the foreign key isn't set.

Code in the Employee model:

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

smnwk started a new conversation Factory Each Closure With Belongs To Relation

Hi there,

I am using a factory for creating employees. Each employee has one insurance and bank; moreover, each belongs to an address (yes, a belongs to relationship is needed).

My code looks like this

factory(Employee::class, 8)
    ->create()
    ->each(function ($e) {
        $e->insurance()
            ->save(factory(Insurance::class)
            ->make());

        $e->bank()
            ->save(factory(Bank::class)
            ->make([
                'acc_holder' => $e->firstname.' '.$e->lastname,
            ]));
        # doesn't work  
        $e->address()
            ->associate(factory(Contact::class)
            ->make());
});