michapietsch

michapietsch

Member Since 9 Months Ago

Greifswald

Experience Points 32,390
Experience Level 7

2,610 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 274
Lessons
Completed
Best Reply Awards 7
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.

19 Jul
2 days 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
2 weeks 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
2 weeks 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
3 weeks 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
3 weeks 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 the 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
4 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
4 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
4 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
4 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?

michapietsch left a reply on Laravel Snappy PDF - The Exit Status Code '127' Says Something Went Wrong

Hi Zaster, take a look at https://github.com/barryvdh/laravel-snappy/blob/master/readme.md#snappy-config-file

In Ubuntu you won't find the EXE and and will need to have wkhtmltopdf installed and configure its location

24 Feb
4 months ago

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

Hi Ibe,

I assume this happens on line 3, possibly because on line 1 var map = document.querySelector('#map') could not assign map correctly.

Please first make sure that the element id="map" exists.

Maybe try another syntax like var map = document.getElementById('map') although what you've written should be correct as well.

If you can't make progress try debugging it so far, that you can say which line exactly causes the error and maybe you can check the execution step by step.

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

Hi Ibzy,

$like_activity as well as $comment_activity = Comment::whereIn('comments.user_id', $friends)->get(); should be a collection.

You could merge them both: https://laravel.com/docs/5.7/collections#method-merge

I assume you want to sort the activity feed by date. You can use https://laravel.com/docs/5.7/collections#method-sortby and if needed you can provide custom sorting logic as a closure.

For future projects you could consider a polymorphic relationship like I think was used in https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/25 and https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/26.

23 Feb
4 months ago

michapietsch started a new conversation Local Query Scopes Vs. Collection Macros --- Shaping Complex Data

Hi,

I already defined scopes like scopePublished, scopeActive and so on.

Then I needed to return some complex statistics and I decided to first fetch all the data and then shape it with collection methods to determine e.g. "How many published per group and period", "How many not" and so on.

So I already had filter logic defined in scopes. But query scopes need queries, of course. And I don't want recursion and n+1 queries.

Now this made me wonder: Why not use collection macros to define the filters in the first place, so that they are available independent from Eloquent queries?

Although at the moment I don't know of a way to make collection macros model-specific, but indeed these filters are specific to the given model.

What approach would you take in this scenario?

21 Feb
5 months ago
20 Feb
5 months ago

michapietsch left a reply on Extending AuthorizeResource To Custom Method

If it's just documents it seems not to complex at first. But maybe documents have all CRUD operations. And maybe later there's not just documents.

I took this idea from "Cruddy by Design" by Adam Wathan: https://www.youtube.com/watch?v=MF0jFKvS4SI

18 Feb
5 months ago

michapietsch left a reply on Extending AuthorizeResource To Custom Method

Hi Oliver,

I think there is a mapping you maybe could override. Need to research this.

Another solution would be to check $user->can('view', $stream) inside the documents() method.

Or yet another suggestion: Create it as a separate subresource with a StreamDocumentsController. This may be cleaner if you add more functionality.

03 Dec
7 months ago

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

You're right, @divpro, now this needs to be put into context.

You want to access the path tags inside a closure which retrieves the related tasks. I'm not sure how you can access it there.

But you're actually looking for only one specific path, right? Maybe there's a better way, but why not use an array with the path tags and then start your query for the tasks and pass that variable to the closure?

02 Dec
7 months ago

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

Hi @divpro, thanks for the clarification. Now I understand the core of your question.

You get a collection, when you retrieve the tags for a path a pluck the 'name' column. You can now transform the collection into an array with the toArray() method.

For example you can get the tags for a path as an array:

$path->tags()->pluck('name')->toArray();

// Or as I see you called the relationship method pathtags() instead of tags():
$path->pathtags()->pluck('name')->toArray();
30 Nov
7 months ago

michapietsch left a reply on CSS Modules In Blade

@thaden Ah, interesting, thanks for the clarification! So many ways to do things these days! :) I haven't had the pleasure with PostCSS, yet.

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

@divpro Ah ok, so XML, PHP and CSS3 are the tags of the path and if a task has one, two or all three of them, then it's a match, but if a task has any other tag, which is not in these path tags, then this means this tasks is reaching beyond the path scope and that task should not be included?

michapietsch left a reply on Passing Value To Edit Form, Update() Returns Null Instead, Why?

Hi, are the sales displayed correctly when you load the form? Does the answer from the server with all the sales have the correct format, that means an array with sales and each sale has a itemID property?

michapietsch left a reply on CSS Modules In Blade

Hi, can you please give more information on your current workflow outside of Laravel blade files? Are you using CSS-in-JS with e.g. React or Vue?

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

Hi, please confirm that I get the basic idea right: Paths have tags, tasks have tags. Both are many-to-many relationships. Basically you want to retrieve a collection of paths, each with a collection of its tags, and each tag with a collection of its tasks. But now you want to filter that down and exclude certain tags, so that tasks with these tags are excluded, and from the paths you want to exclude tags associated with any of these excluded tasks?

24 Nov
7 months ago

michapietsch left a reply on Package:autodiscover

Did you upgrade? I think the postAutoloadDump is an old command. I believe I ran in the same error... If you upgraded, please compare your composer.json to the one you find at Github for the version you are now running.

23 Nov
7 months ago

michapietsch left a reply on Write Each Part Html

I don't completely understand the part where you add the myname HTML.

But I think you could first simplify your code and not use the switch because inside it always uses the module name. So instead of switch and also instead of name!=footer etc. you could check if the module name exists in an array of allowed modules and then just generate the view include. You are already looping through all of them.

michapietsch left a reply on Submitting An Ajax Get Request Returns Undefined

Could you try and use response as an argument for the success fallback? Maybe data clashes with the existing var.

michapietsch left a reply on Package:autodiscover

Could you please be more specific? Do you get error messages?