fdusautoir

fdusautoir

Member Since 5 Years Ago

Experience Points
46,360
Total
Experience

3,640 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
373
Lessons
Completed
Best Reply Awards
2
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 10
46,360 XP
Aug
09
1 month ago
Activity icon

Started a new Conversation Laravel - Services Or Repositories Patterns

Hi everyone,

Since a couple of days I find myself thinking and trying a lot of things about Services or Repositories patterns with Laravel. Until now, I always put data logic into Models like accesors, mutators, scopes and custom methods like this :

    public function createTrip(Request $request)
    {
    	$quote = $this->create($this->syncDatas($request));
	$quote->syncRelations($request);
    	return $quote;
    }


    public function updateTrip(Request $request)
    {
    	$this->update($this->syncDatas($request));
    	$this->syncRelations($request);
    	return $this;
    }


    protected function syncDatas(Request $request)
    {
        $datas = (object) json_decode($request->datas);

        return [
            'name' => $datas->name,
            'type' => $datas->type,
            'schedule' => [
                'start' => $datas->date_start,
                'end' => $datas->date_end
            ],
            'members' => collect($datas->client->members)->pluck('id'),
            'price' => $datas->price
        ];
    }


    protected function syncRelations(Request $request)
    {
        $datas = (object) json_decode($request->datas);

        $this->syncClient($datas);
        $this->syncOption($datas);
        $this->syncDestinations($datas);
        $this->syncSteps($request);
        $this->syncCars($request);
        $this->syncFlights($datas);
        $this->syncHotels($request);
        $this->syncUsers($datas);
    }

As you see, I inject the request object and format data before store it with the syncDatas() method and do to the same for the relations.

This is mainly the reason why I think about Services/Repositories pattern because I don’t know if that is a good way to use Model at this step. But i’m not really convinced about using those patterns into Laravel and as many, want to keep my Controllers very clean and easy to read.

So, I want to know, what is your approach on this case ? Do you use Services/Repositories pattern in your projects ?

Aug
06
1 month ago
Activity icon

Replied to Model Class Instance Question

@martinbean I have not a real example to give you, the aim here is just to understand the way it works. It is more about POO than Laravel.

This is why I took the example of Model with its first() method. It is returns a Model instance with public properties columns based on schema columns that it retrieves from database.

I tried to take a look in core’s model files but I didn’t find the full answer to this question :

How can I return an object with its public properties dynamically set as Laravel does ? I have answered to this question with my previous example which works but it still have a + sign behind each property and want to know why in comparison to Laravel Model which don’t.

Aug
02
1 month ago
Activity icon

Replied to Model Class Instance Question

Thanks all for your answers. I find the solution below :

class Test {

  
  public function __construct($datas)
  {
    foreach($datas as $key => $data)
    {
      $this->$key = $data;
    }
  }
  
  public function get()
  {
	return $this;
  }

}

$test = new Test(['id' => 1, 'name' => 'John']);

$test->get();

However, I still don't understand why Laravel Models don't have a plus sign in front of properties even though its properties are dynamically set.

Activity icon

Replied to Model Class Instance Question

@thibaultvanc Ok that is clear.thanks for this answer. Any idea about the first question ?

Activity icon

Replied to Model Class Instance Question

Hi @tykus ,

Thanks for your feedback. 2 questions about it :

  1. How can I dynamically set the public properties of the object from a given array for example :
class Test {
  
  protected $datas = [];
  
  public function __construct($datas)
  {
    $this->datas = $datas;
  }
  
  public function first()
  {
	return $this;
  }

}

$test = new Test(['id' => 1, 'name' => 'John']);

$test->first();

  1. Why does I get a plus sign in front of properties ? What is the difference ?
=> Test {#2050
     +id: 1,
     +name: "John",
   }

Thanks for your help

Activity icon

Started a new Conversation Model Class Instance Question

Hi,

I have a question about something.

Consider the following code : App\Models\User::first(). This returns an User class with its attributes like this :

App\Models\User {#2070
     id: 1,
     firstname: "François",
     lastname: "Dusautoir",
     email: "[email protected]",
     avatar: null,
     email_verified_at: "2020-07-23 16:45:19",
     settings: "{"lang":"fr","notifications":[]}",
     owner: 1,
     created_at: "2020-07-23 16:45:19",
     updated_at: "2020-07-23 16:45:19",
   }

How is it works to return an instance of the object ? I mean, if I create a simple class like this :


class Test {
  
  public function first()
  {
    return  [
      'id' => 1,
      'name' => 'John'
    ];
  }

}


(new Test)->first();

It's only returns me a single array, which is normal. But how can I reproduce something like this :

Test {#2069
     id: 1,
     name: "John",
   }

Thanks for your help about it.

May
08
4 months ago
Activity icon

Commented on Different Strategies For Different Clients

Really great. This is clearly that kind of lessons that I need today to level up refractoring in my apps. This serie is really cool Jeffrey 👌👍

Apr
21
5 months ago
Activity icon

Commented on Rapid Code Generation With Blueprint

That is a really awesome work Jason ! Thanks for that.

I didn’t see it in the readme documentation but is there an option to set a default $guarded = [‘id’] instead of the fillable property in model created ? I have the same question about the $casts property. I generally just use it to cast JSON datas.