ExpDev07

ExpDev07

Member Since 3 Weeks Ago

Experience Points 410
Experience Level 1

4,590 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 2
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

06 Jul
1 week ago

ExpDev07 left a reply on Ideas Of To Create A Simple Chats

You probably want to use Laravel's Broadcasting to ensure that you can update the chat without needing a page refresh.

ExpDev07 left a reply on All Of My Vue Componenets No Longer Rendering.

But do you also wrap that around your html in for example in your layout template?

<head>
    <!-- head stuff -->
</head>

<body>
    <!-- Your Vue components must find themselves inside here -->
    <div id="app">
        <nav></nav>
        <div class="content">
            @yield('content')
        </div>
    </div>
</body>

In other blade templates, you can extend this layout and put all your Vue components inside

@section('content')
    <a-vue-component />
@endsection

Hope this helped!

03 Jul
1 week ago

ExpDev07 left a reply on Eloquent HasMany WhereIn

@BOBBYBOUWMANN - Youre right... I just cant get my head around how to apply it my case despite the examples that you so kindly provided.

02 Jul
2 weeks ago

ExpDev07 left a reply on Eloquent HasMany WhereIn

@BOBBYBOUWMANN - I sorted it like this. In my user model, I have the following function:

/**
 * Gets the bans if player is banned, otherwise null. In practise, one player will have more than
 * one identifier banned.
 *
 * @return mixed
 */
public function bans()
{
    // Due to how banning works, there might exist a ban record for each of the player's identifier (steam, ip address
    // rockstar license, etc), and it's important to get all.
    return Ban::whereIn('identifier', $this->identifiers);
}

And whenever I will ban a user, I just do it like this:

// Make an id which will represent this batch of bans.
$ban_id = self::makeBanId();

// Go through the player's identifiers and create a ban record for each of them.
foreach ($player->identifiers as $identifier) {
    // Make sure there's only one ban per identifier by updating if one already
    // exists.
    Ban::updateOrCreate(['identifier' => $identifier], [
        'identifier' => $identifier,
        'ban-id' => $ban_id,
        'banner-id' => Auth::user()->player->staff,
        'reason' => $request->get('reason')
    ]);
}

Is this a bad way of doing it or? Should I instead use has?

ExpDev07 left a reply on Eloquent HasMany WhereIn

@BOBBYBOUWMANN - Well, the bansWithIdentifiers relationship ship wont work.

What I want is if theres for example a ban record with the columns:

Ban:

  • id: 5
  • identifier: ip:123456789

and another one with the columns:

  • id: 10
  • identifier: steam:steam64

And a user the columns:

User:

  • id: 100
  • identifiers: [steam:steam64, ip:123456789]

Then the bans function in user should return a HasMany relationship which contains both of those bans as they both have an identifier which matches the users identifiers. This is what I want.

ExpDev07 left a reply on Eloquent HasMany WhereIn

@BOBBYBOUWMANN - That would work, but this wouldnt really be two relationships though, right?

It would be one for creating, and the other method would just be a getter? Right?

ExpDev07 left a reply on Eloquent HasMany WhereIn

@BOBBYBOUWMANN - Yes, youre right. But for convenience, I want to be able to for example call

$user->bans

and that will retrieve all the bans which has an identifier column which matches an identifier in the array. Then if I want to create one, I can do

$user->bans()->create(...).

01 Jul
2 weeks ago

ExpDev07 started a new conversation Eloquent HasMany WhereIn

Hey! I have a user model with an array of identifiers. An identifier can be either an IP address or something else. However, users can be banned. And this is done through their identifiers.

Therefore, I created a HasMany relationship like this thinking it would work:

public function bans()
{
    // Due to how banning works, there might exist a ban record for each of the player's identifier (steam, ip address
    // rockstar license, etc), and it's important to get all.
    return $this->hasMany(Ban::class)->whereIn('identifier', $this->identifiers);
}

And that did not work. I know why: because it will still look for the foreign key relationship, then apply the "whereIn" constraints. This is not what I want.

I want that, as long as there's a Ban model (entry) where the identifier matches one of the identifiers in the user's identifiers-array, then it should be added to that hasMany relationship. Any tips on how to achieve this?

And it is kind of important that it is done through relationships, as I want do do this later:

// Go through the users's identifiers and create a ban record for each of them.
foreach ($user->identifiers as $identifier) {
    $user->bans()->updateOrCreate(['identifier' => $identifier], [
        'issuer_id' => Auth::user()->id,
        'reason' => 'a reason'
    ]);
}

Thanks in advance!

20 Jun
3 weeks ago

ExpDev07 left a reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'issuer' In 'field List'

@AURAWINDSURFING - Any way I could do it without using the factory method and just use the player model directly for relationship?

ExpDev07 left a reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'issuer' In 'field List'

@AURAWINDSURFING - Yes, they definitely are. It's unclean that I have to manually set the id. Is there no way in Eloquent to use the actual model object to set as reference when creating a model?

ExpDev07 left a reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'issuer' In 'field List'

@STAUDENMEIR - I did do that here, and it worked:

/**
 * Store a newly created resource in storage.
 *
 * @param Request $request
 * @param Player $player
 * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
 */
public function store(Request $request, Player $player)
{
    // Create the warning and persist it to the database.
    $warning = $player->warnings()->create([
        'issuer' => Auth::user()->player,
        'message' => $request->get('message')
    ]);

    // Redirect user to their created warning.
    return view('warnings.show', [ 'warning' => $warning ]);
}

ExpDev07 left a reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'issuer' In 'field List'

@AURAWINDSURFING - So I can't reference the player directly when creating a model such as:

// Get the player model
$player = Player::get('id');

// Create a warning for this player and set the issuer to themselves
$warning = $player->warnings()-create( [ 'issuer' => $player, 'message' => 'a test message.' ] );

// (in this example, should equal each other)
$warning->player; // player that recieved warning
$warning->issuer; // player that issued warning

ExpDev07 started a new conversation SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'issuer' In 'field List'

Hey, I am trying to create a model through seeding but is getting the following error:

Illuminate\Database\QueryException  : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'issuer' in 'field list' (SQL: insert into `warnings` (`message`, `issuer`, `player_id`, `updated_at`, `created_at`) values (Accusamus voluptas iure nobis eius ut. Recusandae possimus et ea dignissimos consequatur velit. Vel aliquam veritatis exercitationem quisquam aut. Fugit blanditiis dolores vel ut dolorem commodi est., {"id":1,"identifier":"steam:nonqui3491267","name":"Sabrina Sauer","identifiers":"[\"steam:nonqui3491267\", \"162.23.60.34\"]","playtime":1306,"seen":"2019-06-20 20:03:14","cid1":null,"cid2":null,"cid3":null,"cid4":null}, 1, 2019-06-20 20:03:14, 2019-06-20 20:03:14))

My seeder looks as following:

/**
 * Run the database seeds.
 *
 * @return void
 */
public function run()
{
    // Faker to create data.
    $faker = Factory::create();

    // And now, let's create a few users in our database:
    for ($i = 0; $i < 50; $i++) {
        // Create a user with some properties.
        $user = User::create([
            'identifier' => 'steam:' . $faker->word . $faker->word . $faker->numberBetween(0, 10000000),
            'username' => $faker->name,
            'avatar' => self::$AVATAR_URL
        ]);

        // An IP address.
        $ipAddress = $faker->ipv4;

        // Create a player for this user.
        $player = $user->player()->create([
            'name' => $user->username,
            'identifiers' => json_encode([ $user->identifier, $ipAddress ]),
            'playtime' => $faker->numberBetween(0, 10000),
            'seen' => Carbon::now()
        ]);

        // Give the player some warnings and self as issuer.
        $player->warnings()->create(
            [ 'message' => $faker->text, 'issuer' => $user->player ]
        );
    }
}

As you can see, I'm trying to create a new warning for the player, and just set the issuer as themselves. The player model has the following relationship:

/**
 * Gets the warnings that this person has received.
 *
 * @return \Illuminate\Database\Eloquent\Relations\HasMany
 */
public function warnings()
{
    return $this->hasMany(Warning::class);
}

And the Warning model has the following relationships:

/**
 * Gets the player that received this warning.
 *
 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
 */
public function player()
{
    return $this->belongsTo(Player::class);
}

/**
 * Gets the player that issued this warning.
 *
 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
 */
public function issuer()
{
    return $this->belongsTo(Player::class);
}

As you can clearly see, there is an "issuer" which I am trying to set in the seeder. In the seeder, "player" and "issuer" should be the same Player. In the migration, I do have an unsigned big integer for the "issuer_id".

Any help would be greatly appreciated, thanks!