JohnBraun

JohnBraun

Developer at Enrise

Member Since 3 Years Ago

Netherlands

Experience Points
150,690
Total
Experience

4,310 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
1037
Lessons
Completed
Best Reply Awards
72
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 31
150,690 XP
Sep
23
4 days ago
Activity icon

Replied to Cypress & Laravel - Persist User Login

@longestdrive What is your specific reason to be able to preserve the logged in user across multiple tests? In general, it is best practice to keep each test separated (no overlapping sessions).

My advice would be to group all tests that require a logged in user and use the beforeEach cypress method to write the logic to log in a user once.

Sep
12
2 weeks ago
Activity icon

Replied to Laravel Friendly Devops/sysadmin Managed AWS Infrastructure Services

I would go with Laravel Forge, they also provide support for Amazon servers.

Activity icon

Replied to Dispatch A Simple Function

@mohammedassafly It depends on what is returned by your "someFunction".

The code you showed does not provide the answer to why you're getting the error here, although $this->{$func}($request) would be syntactically preferred over $this->$func($request).

Sep
09
2 weeks ago
Activity icon

Replied to Cypress And Laravel - Testing Principles Questions

Hi @longestdrive

Jeffrey Way creates a special endpoint for this in the video I linked below. Do note that you need to protect these routes to only exist in your testing environment.

In your case, you could create a special endpoint which also accepts the role of a user and creates that user in the database.

The video gets into endpoints at around 19 minutes: https://laracasts.com/series/whatcha-working-on/episodes/39

In fact, this is how the laracasts/cypress helper commands work as well. Check out the vendor directory.

Jul
31
1 month ago
Activity icon

Replied to Vue Strange Behavior Of Data And Props

And if you only console.log(this.anything) ? Does that also give undefined?

Jul
21
2 months ago
Activity icon

Awarded Best Reply on 💡 Ideas How To Work With Pdf

@talelmishali

You could create an endpoint to generate the HTML you want to convert to PDF.

Then, you can use this pakage by Spatie to convert that HTML document to PDF: https://github.com/spatie/browsershot

Jul
20
2 months ago
Activity icon

Replied to Style Error

I think you have hard coded the path to the assets. It is advisable to use the asset() helper Laravel provides: https://laravel.com/docs/7.x/helpers#method-asset

Activity icon

Replied to Sitemap Generate All But I Just Want Route

You can use ->add() to specify which routes should be added.

public function handle()
{
    // modify this to your own needs
    SitemapGenerator::create(config('app.url'))
        ->configureCrawler(function (Crawler $crawler) {
            $crawler->ignoreRobots();
        })
        ->add(Url::create('/home')
            ->setLastModificationDate(Carbon::yesterday())
            ->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
            ->setPriority(0.1))
        ->writeToFile(public_path('sitemap.xml'));
}
Activity icon

Replied to Property [articles] Does Not Exist On This Collection Instance

$menu->getChild will yield a collection of Category models (hence the hasMany relationship). So, you'll need to loop over all these Category models first.

@foreach ($menu->getChild as $child)
  @foreach ($child->articles as $article)
    {{ $article->title }}
  @endforeach
@endforeach

Activity icon

Replied to 💡 Ideas How To Work With Pdf

@talelmishali

You could create an endpoint to generate the HTML you want to convert to PDF.

Then, you can use this pakage by Spatie to convert that HTML document to PDF: https://github.com/spatie/browsershot

Jul
17
2 months ago
Activity icon

Replied to How To Get Manager's Manager In Laravel Query

@noblemfd I understood that you have two models: a Employee model and a App\Models\Hr\HrEmployee model, correct?

Jul
16
2 months ago
Activity icon

Replied to HasOneTrough / HasManyTrough Relations

@charrua I have a way to approach this problem, which uses 3 relatively fast queries on the database and retrieves the courses without employing a relationship method.

Please let me know if this helps you out. If you use the code listed below, you should be able to fetch all courses for a user by calling $user->courses().

Models

class Course extends Model
{
    public function enrollments()
    {
        return $this->belongsToMany(Enrollment::class);
    }
}
class Enrollment extends Model
{
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function courses()
    {
        return $this->belongsToMany(Course::class);
    }
}
class User extends Authenticatable
{
    // default methods omitted for clarity... 

    public function enrollments()
    {
        return $this->hasMany(Enrollment::class)->with('courses');
    }

    public function courses()
    {
        return collect($this->enrollments)->flatMap(function ($enrollment) {
            return $enrollment->courses;
        });
    }
}

Migrations

The users table migration is default.

// For the 'enrollments' table
    public function up()
    {
        Schema::create('enrollments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id');
            $table->timestamps();
        });
    }
// For the 'courses' table
    public function up()
    {
        Schema::create('courses', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
        });
    }
// For the course_enrollment pivot table
    public function up()
    {
        Schema::create('course_enrollment', function (Blueprint $table) {
            $table->foreignId('course_id');
            $table->foreignId('enrollment_id');
            $table->unique(['course_id', 'enrollment_id']);
        });
    }
Activity icon

Replied to My Composer Is Very Slow . It Just No Doing Anything.

Which version of composer do you use?

Activity icon

Replied to How To Get Manager's Manager In Laravel Query

Does your App\Models\Hr\HrEmployee class have a circular reference to itself? This model needs to have a line_manager_id as well if this employee has a manager.

If it also has this linemanager() relationship (hasOne), you should be able to access that relationship in your blade view:

{{ optional($data->linemanager->linemanager)->fullName ?? 'None' }}
May
26
4 months ago
Activity icon

Replied to Jeroen-G/laravel-packager ProcessTimedOutException When Creating A New Package

@getupkid203 @jeroen I can confirm that using a different vendor / package name (which does not exist on Packagist) works as it should using Laravel 7.13 and Laravel valet on Mac OS 10.15.3.

I was under the impression that composer would check the locally defined repositories first, however it turns out it first checks packagist and when it doesn't find a package there it falls back to a local package.

May
22
4 months ago
Activity icon

Replied to Single Sign-On Authentication (SSO)

In the definition of SSO, you have an identity provider and multiple resources that uses this central identity provider to authenticate users so they only ever need to have an account at the central identity provider instead of separate accounts for the underlying resources.

Socialite provides a solution for your users to authenticate themselves to your website using a third party website (integration). In that sense, Socialite provides SSO for your Laravel application, as users can use their central identity provider of choice (for example Google, Github, Twitter, etc.).

Additionally, socialite also provides an integration with Laravel passport if you want to use your own website as a central identity provider (instead of Google, Twitter, etc.). If you're interested in setting that up, I wrote a blog post on that topic a little while ago: https://johnbraun.blog/posts/oauth2-authentication-across-laravel-projects

Activity icon

Replied to Is There Any Support For Laravel Forge At All?

In Laravel Forge, there is a green chat button in the bottom right of your screen that allows you to contact the team. I raise your question there.

Activity icon

Replied to Generate .ics Calendar File In Php Laravel

I see that Spatie has a package for that, have you tried that one yet? https://github.com/spatie/calendar-links

// Generate a data uri for an ics file (for iCal & Outlook)
echo $link->ics();
May
17
4 months ago
Activity icon

Awarded Best Reply on Mock Notification Gives Get_class() Expects Parameter 1 To Be Object, String Given

The assertSentTo() method on Notification expects a User object (or any other "Notifiable" object in your application), but you are only passing the $email string.

If you pass in the User object that should fix your test.

May
16
4 months ago
Activity icon

Awarded Best Reply on Array To String Conversion

https://www.php.net/manual/en/language.variables.variable.php

It is because when calling $this->sponserTree->$array[i], the $array[i] variable is not evaluated. We can force evaluation of $array[$i] first by wrapping the variable in curly braces {}.

Activity icon

Replied to Array To String Conversion

https://www.php.net/manual/en/language.variables.variable.php

It is because when calling $this->sponserTree->$array[i], the $array[i] variable is not evaluated. We can force evaluation of $array[$i] first by wrapping the variable in curly braces {}.

Activity icon

Replied to Mock Notification Gives Get_class() Expects Parameter 1 To Be Object, String Given

The assertSentTo() method on Notification expects a User object (or any other "Notifiable" object in your application), but you are only passing the $email string.

If you pass in the User object that should fix your test.

Activity icon

Replied to 3 Table Relation

It looks to me like you need a Many to Many relationship which relates a certificate to a hotel instead of a hasManyThrough relationship.

https://laravel.com/docs/7.x/eloquent-relationships#many-to-many

The role_user pivot table in the example would be the certificate_list table in your case, having a hotel_id and certificate_id.

Activity icon

Replied to Array To String Conversion

Right, you'll want to use:

if (is_null($this->sponserTree->{$columns[$i]}))

Wrapping the stringified column in {}.

Activity icon

Replied to Array To String Conversion

Could you provide some more details about the problem you're trying to solve? The code seems quite confusing at first glance.

By the way, in your first example you're also returning a $col variable, but you never define it.

Activity icon

Awarded Best Reply on Php Artisan Queue:work Error

Have you tried the solution as suggested in this Stack Overflow post yet? https://stackoverflow.com/questions/29695450/pdoexception-sqlstatehy000-2002-no-such-file-or-directory

Which database driver are you using?

Activity icon

Replied to Select Specific Fields By Polymorphic Type While Using 'with'?

The functionality to select columns for polymorphic relations was added in this PR https://github.com/laravel/framework/pull/25662

I guess all columns have to be available in all the related tables if you want to eager load them.

Activity icon

Replied to Php Artisan Queue:work Error

Have you tried the solution as suggested in this Stack Overflow post yet? https://stackoverflow.com/questions/29695450/pdoexception-sqlstatehy000-2002-no-such-file-or-directory

Which database driver are you using?