michapietsch

michapietsch

Member Since 5 Months Ago

Greifswald

Experience Points 23,400
Experience Level 5

1,600 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 191
Lessons
Completed
Best Reply Awards 6
Best Reply
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.

01 Mar
2 weeks 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
3 weeks 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
3 weeks 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
3 weeks 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
3 weeks 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
3 weeks 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
1 month ago
20 Feb
1 month 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
1 month 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
3 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
3 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
3 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
3 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
3 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?

michapietsch left a reply on ({response})

Seems the response is not an object and by adding the curly braces you create an object from an array.

Please check the response in DevTools to see what you get from the server.

michapietsch left a reply on 405 Method Not Allowed Laravel Ajax

Where do you pass the ID in the Ajax request? I can only see you add the CSRF token.

06 Nov
4 months ago

michapietsch left a reply on PHP Fatal Error: Uncaught Error: Class 'Monolog\Handler\StreamHandler' Not Found

So according to your composer.lock you have version 1.12 installed. I just checked the Github repo for Monolog, chose the 1.12 tag and there the Class exists: https://github.com/Seldaek/monolog/blob/1.12.0/src/Monolog/Handler/StreamHandler.php

Can you confirm, that in the vendor directory, amongst the monolog files you can see this class?

To doubt the mere existence of this class file might seem weird, but who knows what weird things could happen? :)

michapietsch left a reply on Validation Radio-Button

I got curious, because I'm from Germany. :)

Can you show us more code? The above snippet does not handle the inline styles, of course .

michapietsch started a new conversation Delete From Pivot Table Only One Of Multiple Associations

Hi,

I wasn't able to find an existing thread. Please point me to it if you know of one!

Imagine you have multiple associations in a many-to-many relationship. Like when for some reason there are multiple identic products in a cart.

Why aren't they merged to one entry? Well, maybe some will get a gift box, the others won't.

Whatever the reason, there are multiple entries and we COULD to remove a specific one with newPivotStatement... -- BUT we'd need to know exactly what distinguishes this entry to formulate the where clauses. Maybe it's the gift box, maybe something else. Don't know, shouldn't need to care.

I came across the suggestion to include the id in withPivot and use an extra model to delete the entry.

What do think about this? What alternatives are there to consider?

Micha

20 Oct
5 months ago

michapietsch left a reply on A General (long) Question On TDD And Test Organization

Came here looking for advice on test organization. It can be tough in complex applications! You're right, on unit level it's quite straightforward but if you're testing integration or E2E then the number of combinations can be overwhelming!

Let's pick out validation as an example:

First, I think testing on unit level can ensure that request does not get processed further if it's not valid. But I'd go as far as to test on browser level. Because user experience matters. E.g. does the user get appropriate feedback? I'm a huge fan of browser testing and I'm glad there are great tools to make it easy. It's just my preferred way.

I'd write a test for every aspect you need to cover in development. Even if you're at first just writing down the test definitions it's good documentation for stakeholders. :) Because a lot of work happens in the shadows. The customer will mostly only test the usual path without all the side roads you need to consider and cover and of course you test all of them manually during development. So writing more tests and covering all potential edge cases is a great way of forcing yourself to think about and cover all of them and to make the development process comprehensible to others.

Every single validation rule is a piece of work that needs to be done, tested and continue to work correctly in the future.

michapietsch left a reply on Validation Radio-Button

Hi,

is it just not displayed or could you verify that the error message exists in $errors?

PS: I see you're working on a project in German language. Where you from?

michapietsch left a reply on How To Set Mannual Url (href) In Pagination

Do you use Ajax to get the data and then insert it into the page and now you also want to update the URL in the address bar?

michapietsch left a reply on PHP Fatal Error: Uncaught Error: Class 'Monolog\Handler\StreamHandler' Not Found

composer dump-autoload will make the existing classes available. But does the Class 'Monolog\Handler\StreamHandler' exist? You could check that in the vendor directory.

Now what is the effect of the minimum-stability property? It affects dependency resolution, that means how composer determines which package versions to install. I guess in this case it's about a difference between versions of the Monolog package. The class is expected in it but the installed version somehow does not include it.

That's my guess where I'd look for the cause of the error.

If you want to try to set minimum-stability and your composer.json does not have it, you could add it.

If it doesn't help, could you please look into composer.lock and see which version of Monolog is installed?