michapietsch

michapietsch

Member Since 10 Months Ago

Greifswald

Experience Points 34,290
Experience Level 7

710 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 279
Lessons
Completed
Best Reply Awards 9
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 Aug
2 weeks ago

michapietsch left a reply on Eloquent Design

@fareedr You're belongsToMany relationship $user->categories() points to the pivot model UserCategory when it's really the Category model you need to relate.

You can see this in the errors message: You want to query from the table user_categories and join it with the table user_categories. This can't work.

Try this:

// User.php
public function categories()
{
    return $this->belongsToMany(Category::class, 'user_categories');
}
02 Aug
2 weeks ago

michapietsch left a reply on How To Set And Get Headers In Laravel ?

@mostafalaravel So you want to manipulate the incoming request in the middleware? Would it be possible to set the headers from the client that sends the request?

michapietsch left a reply on Including Node Modules Js/css Into Laravel

@0ussama Please take a look at the scaffold provided by Laravel. Maybe watch the lessons on Laravel Mix.

The files https://github.com/laravel/laravel/blob/master/resources/js/app.js and https://github.com/laravel/laravel/blob/master/resources/js/bootstrap.js demonstrate how to pull in dependencies.

michapietsch left a reply on Search Box In Multiple Select (array Of Select Box) Not Working

@abdulbazith So it loads only one time after page load and then stops working, not matter which of the selects?

michapietsch left a reply on Eloquent Design

@fareedr

$posts = Post::whereIn('category_id', \Auth::user()->categories->modelKeys())->get();   

michapietsch left a reply on How Make For Heavy Testing For Search System

@mstdmstd I was just stating why I wrote this in the first place.

I can't answer that, but maybe somebody else can state their experiences with stress testing tools.

01 Aug
3 weeks ago

michapietsch left a reply on Laravel Mix Dynamic Imports

@denorm Did you get it to work?

You can mark this thread as solved by selecting an answer.

michapietsch left a reply on Eloquent Model Custom Validation Before Save

@orb_77 Could you achieve what you tried to solve?

BTW You can mark this as solved by selecting an answer.

michapietsch left a reply on Eloquent Design

@snapey Does whereIn accept a collection? I think pluck returns a collection, but whereIn would expects an array.

michapietsch left a reply on How Make For Heavy Testing For Search System

@mstdmstd First you need the consent to run heavy tests. The other service needs to be prepared for the load. I mention this because in the case of an external service owned by someone else it may violate the terms of use or even be criminal, as you can potentially render a service unavailable.

What exactly do you want to test?

michapietsch left a reply on Eloquent Design

@fareedr

Try

Posts::whereIn('category_id', $user->categories->modelKeys())->get()

michapietsch left a reply on Password Confirmation Error When Using Vue With Laravel Auth

@grahammorbydev If you require a password confirmation, you should ask your user to provide. Otherwise you should remove this feature and along with it the validation.

michapietsch left a reply on How Make For Heavy Testing For Search System

@mstdmstd Do you want to test the performance/speed?

First, you should never run a load test against an external service that you do not own.

You are right: The request/response time to communicate with the external service is probably a bottleneck. But I see no option to optimize that other than to partner with the provider of this API and talk to them.

michapietsch left a reply on Display .md File With Javascript

@shaqaruden Is the file publicly available? Then you can use a library like axios to handle a request and fetch this file's contents and further process it directly in your JavaScript with the use of a parser.

michapietsch left a reply on Search Box In Multiple Select (array Of Select Box) Not Working

@abdulbazith I suspect the search option comes from the jQuery plugin? Then I suspect the plugin can not handle multiple selects like this. Please remove the first select, which works, and check if the second one works after removing the first.

michapietsch left a reply on Get Parent Of Parent In Laravel Eloquent

@engrlaravel You can simplify this. Since each division belongs to an organization, you don't need an organization_id on the department. The organization title would be $department->division->organization->title.

michapietsch left a reply on How Can I Create Categories For Specific Users Based On Categories They Posted In

@kingsleyo You need to restrict the whereHas or having to the user. You can pass a closure to whereHas. Please refer to the docs.

BTW: What refers $this to?

25 Jul
4 weeks ago

michapietsch commented on Smooth Scrolling

Will it really work in older browsers? We prevent the default action, and only in the scroll() method we would get an exception or just nothing happens.

19 Jul
1 month ago

michapietsch left a reply on Eloquent Model Custom Validation Before Save

A little late, but...

There is https://github.com/JeffreyWay/Laravel-Model-Validation

I use an approach similar to this.

04 Jul
1 month ago

michapietsch left a reply on Laravel Mix Dynamic Imports

@denorm I just read about it in the issues.

The workaround at the moment is to compile CSS outside of the Mix config in which you use extract().

For Tailwind I use a simple npm script. For CSS processing with Mix someone suggested to add another Mix config file, e.g. webpack.css.mix.js and add it to the npm scripts. etc.

01 Jul
1 month ago

michapietsch left a reply on FirstOrCreate() / Using Multiple Sets Of Data

@jaheller You asked for "short". :) Although I'd say this is quite readable. But of course it's up to you.

30 Jun
1 month ago

michapietsch left a reply on FirstOrCreate() / Using Multiple Sets Of Data

Maybe collect() the IDs and chain a closure with each()?

michapietsch left a reply on FirstOrCreate() / Using Multiple Sets Of Data

Hi @jaheller, why do you think this should be avoided?

25 Jun
1 month ago

michapietsch left a reply on Eagerly Loaded Relation Not Present In View

Ah, stupid mistake!

In the test I used first() on the flight, but of course it's no collection. Still, first() return the flight, but it strips the relation!

My bad, I copied the line and checked that I get the flight from the view, which I do. But this first() is problematic there, of course.

If you're interested in why I did this: assertViewHas does not allow the query nested data. And simply using $flight->passengers in the view does not tell me, if it has been eager loaded. I want to make sure to avoid n+1 problems in some cases. To check for included relations I use this in the tests: $this->assertTrue(array_key_exists('passengers', $response->original->getData()['flight']->getRelations()));

michapietsch left a reply on Eagerly Loaded Relation Not Present In View

@staudenmeir I don't actually use the view, but wrote a test.

michapietsch left a reply on Eagerly Loaded Relation Not Present In View

@aurawindsurfing Actually it is present. I set up a flight with passengers. The test hits the endpoint: $this->get('/'). If I dump the flight there in the route closure it has the passengers included. Just once it gets passed to the view it is not included anymore in the flight object.

I understand that this is tricky. Maybe it sounds like a stupid beginner mistake. If so, I can't figure it out. I'm confused, because there is no obvious explanation. If you spin up the demo you can test and observe this what I'm inclined to call a bug, if nobody can point to an error on my side.

I kindly ask to take a serious look at the demo.

michapietsch left a reply on Eagerly Loaded Relation Not Present In View

@aurawindsurfing Thanks for looking into it. Unfortunately the behavior doesn't change.

Please note that I do not use the view, since this is a minimal demo and for quick results I used https://github.com/michapietsch/laravel-eager-loading-missing-in-view-example/blob/master/tests/Feature/ExampleTest.php

I stumbled upon this in another project and this demo is a stripped-down reproduction.

It seems as if somehow the relation data gets thrown out once the flight is handled by the view.

It might not be a bug, maybe just unintuitive. I might just not be aware of a catch in the syntax I use. Maybe someone can explain this behavior or show how to make the test pass. I'd thought I'd ask around first, but later I'd open an issue for clarification.

michapietsch started a new conversation Eagerly Loaded Relation Not Present In View

Hi,

I load a model with with and first and in an immediate dump the related data is present, but in the data passed to the view it's missing.

I create a demo here: github.com/michapietsch/laravel-eager-loading-missing-in-view-example

See how in routes.web I use Flight::with('passengers')->first() and uncomment the dump to verify that the passengers are present there. In the ExampleTest I check for the data to be present and it's missing.

Am I missing something here?

01 Mar
5 months ago

michapietsch left a reply on Button To Open Menu

@baeckerman83 Ah, great! I didn't know that!

Please mark as solved. :)

michapietsch left a reply on Maximum Function Nesting Level Of '256' Reached, Aborting! (Checking Relationship Type)

@bgweb Honestly not right from the top of my head, without digging in deeper.

But in your situation I'd try and see if it can be simplified and maybe not have this level of complexity.

michapietsch left a reply on Sending PHP Variables From Controller To Model As PHP Variables

If you want to use PHP, you need to render the template on the server.

I mentioned two ways to do this. What do you think about it?

michapietsch left a reply on Uncaught TypeError: Cannot Read Property 'querySelectorAll' Of Null

@ibe The second line is ok.

The map element cannot be queried. So my guess is it's not even there. Maybe it loads just a bit after your JS executes.

How do you get the #map element into your HTML? Is it a map service like Google Maps or Leaflet?

27 Feb
5 months ago

michapietsch left a reply on Button To Open Menu

My complete working example:

<template>
  <div>
    <button
      type="button"
      class="btn btn-outline-dark btn-block"
      @click="cityShow['dk'] = !cityShow['dk']"
    >
      <span class="flag-icon flag-icon-dk"></span>Denmark
    </button>
    <button type="button" class="btn btn-link btn-block" v-show="cityShow['dk']">Billund</button>
    <button type="button" class="btn btn-link btn-block" v-show="cityShow['dk']">Kopenhagen</button>
  </div>
</template>

<script type="text/babel">
export default {
  data() {
    return {
      cityShow: {
        dk: false
      }
    };
  }
};
</script>

Now tested.

michapietsch left a reply on Button To Open Menu

Of course, you're right!

And it's not tested, just scribbled.

I noticed another bug: please use @click="cityShow['dk'] = !cityShow['dk']" because we need to toggle it, not just activate it.

There are two other issues:

  • Once we use DK and then dk. Of course this needs to be identical.

  • I was wrong about the object keys. They have to initialized for it to work. Please use: cityShow: { 'dk': false } and also add all other countries.

michapietsch left a reply on Maximum Function Nesting Level Of '256' Reached, Aborting! (Checking Relationship Type)

I think I got it:

As I already wrote: $this->$name() return a relationship instance. Which automatically executes its constructor. In which, in some nested function, again $this->$name() gets called. Which return a relationship, which executes a constructor, which calls $this->$name() and so on.

michapietsch left a reply on Uncaught TypeError: Cannot Read Property 'querySelectorAll' Of Null

This confirms my suspicion. As the error reads: map is null at that time. So obviously line 1 which reads var map = document.querySelector('#map') is not correct. Please make sure to correctly query the map element.

michapietsch left a reply on Sending PHP Variables From Controller To Model As PHP Variables

PHP is rendered on the server. You modal template is also already rendered when it gets to the browser.

You could manipulate the model with JS. You use Bootstrap and likely want to use jQuery. But you need to fetch the data!

So it doesn't help you much to render and load the modal initially. You could as well leave empty placeholders in the modal.

Two options:

You can fetch only the data via Ajax. So it's processed on the server and you get what you need. Then you fill the empty placeholders elements in the modal before opening the modal.

Or you make an Ajax request to get fully rendered HTML from the server and replace the modal content before calling it.

michapietsch left a reply on Laravel Pluck An Array From Nested Relationship

Hi, sorry I didn't get back to you. Are you still on it?

michapietsch left a reply on Trying To Do A Join With A WhereIn Query

Well, I think there should be an "in case there are string keys". But hey, there's and "if" in the docs. :)

I haven't tried it, but I'd trust that non-identical instances should not be tried to be merged.

michapietsch started a new conversation "My Participation" Seems To Be Cached And Not Invalidated When I Reply

Hi,

I recently added a reply and in "My Participation" it still shows the last reply from someone else some hours ago.

michapietsch left a reply on Maximum Function Nesting Level Of '256' Reached, Aborting! (Checking Relationship Type)

I'm not sure if $this->$name() causes the problem. $name stands for the relation method name, right? For example, if a flight has passengers then $this->$name() would be $this->passengers(), right?

Well, this should return a relationship instance. I'd dig in there to see if it's really an issue with recursion.

What array is referenced in the line $this->{$type}[$name]?

26 Feb
5 months ago

michapietsch left a reply on Button To Open Menu

Try this:

<template>
  <div>
    <button type="button" class="btn btn-outline-dark btn-block" @click="cityShow['dk'] = true">
      <span class="flag-icon flag-icon-dk"></span>Denmark
    </button>
    <button type="button" class="btn btn-link btn-block" v-show="cityShow('DK')">Billund</button>
    <button type="button" class="btn btn-link btn-block" v-show="cityShow('DK')">Kopenhagen</button>
  </div>
</template>

<script type="text/babel">
export default {
  data() {
    return {
      cityShow: new Object()
    };
  }
};
</script>

For just drafting it I put it in a single file component.

But what's important:

  • cityShow('DK') evaluates to false, when the key doesn't exist, because undefined is falsy.
  • cityShow['dk'] = true is enough, because it automatically adds the key, if it's missing

michapietsch left a reply on Button To Open Menu

Hi,

v-show=getCountry("DK") calls getCountry()? Shouldn't it be v-show="getCountry('DK')" with quotes?

But where do you handle the click on Denmark?

michapietsch left a reply on How To "Implements" Vendor File

Hi,

you have implements Contract and interface Hostname. Shouldn't it be implements Hostname?

michapietsch left a reply on Trying To Do A Join With A WhereIn Query

The Eloquent collections contain model instances. It's not like an associative array. There should be no clash.

Of course if you work the merged collection and want to pluck IDs or so then you would need to be aware of it.

25 Feb
5 months ago

michapietsch left a reply on Turbolinks / Vue Front End Authentication

Hi Roni,

I found this article interesting, as well as the Full Stack Radio episode where he talks to Adam Wathan about it.

I haven't yet completely wrapped my head around it.

Turbolinks speeds up the page load experience but it's not a requirement if you need to redirect to any page using your JS. A simple use of window.location could do that.

Of course you would need to provide error codes with each XHR response and evaluate them in the client. If you don't then you risk data loss in the sense that the user may not notice that his action did not take effect.

I have questions about this approach. We writes it's still using reloads. But where's the desired interactivity then? If you make Ajax requests you need to update your state in the client or you need to refresh the state with an additional request. He uses his approach to provide the data as a prop without an additional request. But if you still need a refresh request you need to make sure you really fetch exactly the same data as a prop AND via Ajax.

michapietsch left a reply on Maximum Function Nesting Level Of '256' Reached, Aborting! (Checking Relationship Type)

Hi, can you show where you call the getRelationType() method?