ftiersch

ftiersch

Member Since 4 Years Ago

Experience Points
91,405
Total
Experience

3,595 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
101
Lessons
Completed
Best Reply Awards
130
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.

Level 19
91,405 XP
22 Sep
16 hours ago

ftiersch left a reply on Getting A Weird Result When Retrieving Data On Show Page

I think the "findOrFail" is unneccessary since you seem to implicitly bind the route to a configurator object by typehinting it.

Try changing your controller to this:

public function show(Configurator $configurator)
    {
        return view('configurator.show', compact('configurator'));
    }
21 Sep
1 day ago

ftiersch left a reply on How To Know If A Method Is Called From Blade Or Elsewhere

Gotta agree with @bobbybouwmann here. "Magical" usually means "annoying the next person working on it because he has to find out what the f is going on".

Your solution with the directive sounded great to me. Expressive and explicit and no unwanted complications.

20 Sep
2 days ago

ftiersch left a reply on Custom Directive In Slot Scope

You're right, that worked. I thought it should work inside a renderless component too for reusability but that fixed it. Thanks!

ftiersch left a reply on M:N Relationship

That depends a lot on the kind of thing you want to create. What I mean is that you shouldn't think too much in rigid structures.

The 1:n or m:n only describes the number of possible entities on each side. If they make sense without another totally depends on your application.

So a 1:n relationship is usually where one of your entities has the ID of the other one in it's database table. That's what creates the relationship between the two. So with the car / color example the "cars" table would have a "color_id" column.

Now when you make that "color_id" column NULLABLE there can be a car without a color. Think of a factory that creates cars but they only get painted at the end. So basically until the car is at the end it doesn't have a color and the "color_id" column would be NULL.

Can't really think of a real world example right now, sorry :D

ftiersch left a reply on OrWhere When Query Don't Give Results

In your blade:

@forelse($posts as $post)
    {{ $post->title }}
@empty
    No results found
@endforelse

ftiersch left a reply on Getting A Record Where There Is Only One

Like I said - I'm not sure about your setup. Like what the $type variable does and why you need that and where the hasManyThrough relationship is :) If you can give a little more context I'm sure there are some improvements possible.

ftiersch left a reply on FirstOrCreate Case Sensitive

Whoops. I just tried and you're right. :) Didn't even know that, I always used LIKE for case insensitivity.

Sorry @mstrauss , totally got that wrong.

ftiersch started a new conversation Custom Directive In Slot Scope

Hey,

I'm currently trying to use a custom directive (from https://github.com/simplesmiler/vue-clickaway) in a scoped slot but I get "Failed to resolve directive". Is there any workaround around this?

// this is the MainNav component

import { mixin as clickaway } from 'vue-clickaway';

    export default {
        mixins: [clickaway],
        data() {
            return {
                isOpen : false,
            }
        },
        methods: {
            hide() {
                this.isOpen = false;
            }
        },
        render() {
            return this.$scopedSlots.default({
                isOpen      : this.isOpen,
                hide : this.hide,
            });
        },
    }
// and here I'm using it

<main-nav>
        <div slot-scope="slotScope">
            <nav class="mainnav" v-on-clickaway="slotScope.hide">
            </nav>
        </div>
    </main-nav>

ftiersch left a reply on Print_r

It is not returning the information, it is only printing the information. But your variable will just be "true". When you pass "true" to the function you get the information from the function but it will not print it.

ftiersch left a reply on FirstOrCreate Case Sensitive

value='input'

should be case sensitive - meaning it is sensitive to casing and "input" is something else than "iNput" because the case is different.

value LIKE 'input'

This would be case insensitive

ftiersch left a reply on Date Format Shuffling

I would run the sanity checks with a validator.

So in a controller you could do this:

$this->validate(request(), [
    'datevalue' => 'required|date',
]);

ftiersch left a reply on Date Format Shuffling

Haha... god damnit... you're onto me! Should be a correct date of course :)

Otherwise:

Carbon::createFromFormat('d-m-Y', '31-12-2019')->toDateString();

ftiersch left a reply on Getting A Record Where There Is Only One

I'm a little confused about your setup :)

But if you have a hasManyThrough relationship you can change it to hasOneThrough which basically gives you the object right away so you don't have to call first() on it.

ftiersch left a reply on FirstOrCreate Case Sensitive

Do you mean case insensitive? Because the default way should be case sensitive.

ftiersch left a reply on Date Format Shuffling

I like to use Carbon for that but you can also use strtotime from PHP itself.

(new Carbon('32-12-2019'))->format('Y-m-d');

// or

(new Carbon('32-12-2019'))->toDateString();

ftiersch left a reply on M:N Relationship

Almost.

Yes, m:n (usually) means m can exist without n but they have a relationship with each other - in that case one entity of n can have multiple relationships with multiple entities of m and the other way around too.

Example: One Product in an online store can be bought by multiple customers. But of course every customer can also buy multiple products.

For your second one:

Depends on the relationship. There can still be an entity one without the entity two but a lot of times it's the way you said, that one entity only makes sense with the other one.

So for example lets say you have a table "colors" and a table "cars". A car without a color doesn't make sense. A color without a car makes sense. So if every car can have only one color here would be a 1:m relationship. If every car could have multiple colors it would be m:n.

ftiersch left a reply on Fetch A Collection From Multiple Ids And Create A Record

Brand::find([$ids])->each(function ($brand) {
    $brand->toys()->create();
});

You have to work through the collection because a collection is not a "Brand" model so it doesn't know the toys() relationship :)

ftiersch left a reply on Getting A Record Where There Is Only One

You could simply do this (if I understand your code correctly):

IndividualProfile::first();

ftiersch left a reply on Print_r

Read the documentation you've posted and you will know ;-)

You give it "false" as a return parameter so it will return "true" after printing your information (instead of returning it). And when you echo "true" you get 1 because it's the same thing.

19 Sep
3 days ago

ftiersch left a reply on How To Print A Category Parents Recursively?

Probably you need a recursive blade partial that you can include. So you can do this:

// this would be the partials/category.blade.php

@foreach ($categories as $category)
    <div>
        <p>{{ $category->name }}</p>

        @include('partials.category', ['categories' => $category->child_categories])
    </div>
@endforeach
// in your Category model
public function child_categories() {
    return $this->hasMany(self::class, 'parentId');
}

And depending on your number of nested levels you could also eager load some levels to avoid looooaaads of queries to get all the layers:

$categories = Category::with(['child_categories.child_categories.child_categories.child_categories'])->get();
18 Sep
4 days ago

ftiersch left a reply on How To Validate Slug On Update

https://laravel.com/docs/5.8/validation#rule-unique

There is an option to ignore a certain row for this rule :)

ftiersch left a reply on How To Add User Profile Whenever A New User Registered/created

My example creates a new Profile object every time a user is created. But that probably won't work that easy because your Profile has a lot of columns that need values. So either you make all those columns nullable() or you have to create the profile "manually" when you create a user during registration and fill it with the necessary values :)

ftiersch left a reply on Page Viewing Permissions Based On Role

That is exactly what middlewares are for ;-)

Add a middleware that has exactly the "if role = employee -> redirect" code in it and it shouldn't bring any issues for every user. And the added benefit is you don't have to execute all your code before checking that inside a blade file at the end (where it shouldn't sit anyway because templates are for presentation, not for logic).

ftiersch left a reply on How To Add User Profile Whenever A New User Registered/created

You can use Eloquent events or Observers for this.

In your User model for example:

public static function boot() {
    parent::boot();

    self::created(function ($model) {
        $profile = new Profile();
        $model->profile()->save($profile);
    });
}
17 Sep
5 days ago

ftiersch left a reply on Send Email With Different Data

Sure you can but you should definitely rework your variable names ;-)

ftiersch left a reply on How To Find For Specific Data In A Many To Many Relationship?

$toy = Toy::create($request);
$toy->brands()->attach($brand_id);

Try this

ftiersch left a reply on The Environment File Is Invalid! Failed To Parse Dotenv File Due To An Invalid Name.

Looks like there is an invisible symbol before your APP_NAME

ftiersch left a reply on Send Email With Different Data

If it is a request object:

'data' => $request->only('repair_report_einkaufen', 'repair_report_einkaufen1'),

ftiersch left a reply on How To Find For Specific Data In A Many To Many Relationship?

Are your relationships (so the methods) called "toys()" and "brands()"? And does the brands() relationship work if you use it normally on a Toy model?

ftiersch left a reply on How To Find For Specific Data In A Many To Many Relationship?

If you add a new childs toy yes, that's all you need. But the toy needs to have all its brands already in the toy_brand relationship.

ftiersch left a reply on How To Find For Specific Data In A Many To Many Relationship?

Aah okay. That makes more sense. But why can a toy have many brands? Isn't a toy usually by a single brand?

Anyway. In that case you would have to add the relation between toy and brand and between toy and child. The rest should work as expected then.

ftiersch left a reply on How To Find For Specific Data In A Many To Many Relationship?

Wait, I think you have an error in your database planning there.

One child can have multiple toys, right? But one toy can only be owned by a single child right? Also one toy is of a single Model but every Model can have multiple toys?

ftiersch left a reply on How To Find For Specific Data In A Many To Many Relationship?

You don't have to, it works with your existing model_toy relationship. with() also gets the values dynamically.

ftiersch left a reply on How To Find For Specific Data In A Many To Many Relationship?

Yeah, that would work. You just put the name of the relationships in the with.

ftiersch left a reply on How To Find For Specific Data In A Many To Many Relationship?

With a subquery. Something like this:

SELECT * FROM child_toy WHERE EXISTS (SELECT * FROM model_toy WHERE model_id = ?)

Not sure about the exact syntax but something like that :)

ftiersch left a reply on How To Find For Specific Data In A Many To Many Relationship?

No, that query actually uses 2 subqueries (which could make it slow with a lot of data).

So basically it says "Check if this Child has a Toy that has at least one Model with the ID of the given model"

ftiersch left a reply on Class App\Http\Controllers\Techzadmin\Request Does Not Exist

The link doesn't help a lot if it's on your localhost ;-)

Add this at the top of your file after the namespace:

use Illuminate\Http\Request;

ftiersch left a reply on How To Find For Specific Data In A Many To Many Relationship?

You could do this on your Child model:

function hasToyWithModel($model) {
    return $this->toys()->whereHas('models', function ($query) use ($model) {
        $query->where('id', $model->id);
    })->exists();
}

I think that should work but I'm not sure if that's the most performant way.

ftiersch left a reply on How To Find For Specific Data In A Many To Many Relationship?

Do you have a pivot table with all three foreign keys in it or do you have multiple pivot tables?

16 Sep
6 days ago

ftiersch left a reply on Undefined Index

What does it say if you do

dd($data); 

after you got your data from the request?

ftiersch left a reply on User Model Namespace Not Importing

You cannot extend from multiple classes. Authenticatable already extends Model so you don't need to extend from it yourself.

ftiersch left a reply on Convert 'DD/MM/YYYY' Format To Timestamp

Of course it has... But things like Carbon and Collections just put an easier to use API wrapper around ootb things :)

ftiersch left a reply on How To Convert Date To Datetime ?

Maybe createFromFormat works better:

Carbon::createFromFormat('d/m/Y', $request->get('begin'))

ftiersch left a reply on How To Convert Date To Datetime ?

$date = '10/03/2019';

Carbon::parse($date)->toDatetimeString();

ftiersch left a reply on How Can I Check How Much Database Connection Dynamically

You get a normal php array back. So with @tykus method you get all the names as a new array. Or you go through them with foreach()

ftiersch left a reply on Limited Array Length And Key Size

You mean you send it TO your view? Can you show more code?

ftiersch left a reply on Upload Image Overwrite EXIF Metadata

http://image.intervention.io/api/exif

Have you seen the part about php being combiled with --enable-exif?

ftiersch left a reply on Limited Array Length And Key Size

Are all the keys unique?

array[test] = 10;
array[test] = 20;

This would only arrive as array[test] = 20 because the second value overwrites the first one.