What If Two Or More Traits Have The Same Method

Поділитися
Вставка
  • Опубліковано 9 лис 2024

КОМЕНТАРІ • 12

  • @jameshello38
    @jameshello38 Рік тому +14

    For whatever reason if you want to use both traits at the same time then you can use the "as" keyword. For eg.
    class MyClass{
    use traitOne, traitTwo{
    traitOne::message insteadof traitTwo;
    traitTwo::message as traitTwoMessage;
    }
    }
    $c = new MyClass();
    $c->message(); //will output "one"
    $c->traitTwoMessage(); //will output "two"
    Traits can also be imported as private/protected. Traits have so many features than I had imagined. Its amazing

    • @MikdanJey
      @MikdanJey Рік тому +1

      Yes, This is regularly we followed.

    • @Laratips
      @Laratips  Рік тому +2

      Wow, that's awesome.

  • @llBestBoyll
    @llBestBoyll Рік тому

    helpful one
    ty 🙏🏼

  • @mayanksgajjar
    @mayanksgajjar Рік тому

    Thanks for sharing knowledge ☺

  • @MikdanJey
    @MikdanJey Рік тому

    Learned new thing here, Thanks :)

  • @codelaravel
    @codelaravel Рік тому

    You are doing great work brother. How we can pass User Object to trait boot method. when boot method auto call. Got my question brother. If not then let me know then i will share repo link with you.

    • @Laratips
      @Laratips  Рік тому +1

      I don't think you can pass any params to the boot method

  • @JenuelDevTutors
    @JenuelDevTutors Рік тому

    what editor are you using?