Repeating Eloquent Scopes into Reusable Traits

Поділитися
Вставка

КОМЕНТАРІ • 24

  • @ryiad2010
    @ryiad2010 5 днів тому

    very useful thank sir

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

    Thank you for videos, that is helpful. I begin my each work day with your video and know that i get some new and helpful information. Laravel is cool.

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

    Veo tus videos antes y después de ir a dormir, estoy como JR de Laravel y ver tus videos me ayuda mucho
    Saludos

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

    very useful, thank you

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

    As always very helpful.

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

    धन्यवाद श्रीमान

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

    It's very useful

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

    Isn't it also possible to create a baseModel. And make your models extend this new BaseModel with the repeated code ?

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

    Thank you for the great information, teacher. Can you show us how to dynamically translate the site from the database?

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

      There are packages like Laravel translatable, please search my channel, I had videos about it

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

      @@LaravelDaily Thank you very much😇

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

    thks master

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

    how about without using Traits?

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

    Thank you for this video this is really helpful for me. Can you please guide me how can I modify this code.
    $maxId = LongTermContracts::UserById()->whereYear("created_at", date('Y'))->count() + 1;
    $maxId = str_pad($maxId, 5, 0, STR_PAD_LEFT);
    $request->request->add(['contract_no' => "LT" . date('Y') . "-" . $maxId, 'user_id' => auth()->user()->id]);
    $contract = LongTermContracts::create($request->all());
    Thank you again.

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

      Modify for what? What is the actual problem or goal to solve?

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

      @@LaravelDaily the goal is to optimize this code to shorter way.

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

      @@LaravelDaily I just want to create a contract no when contract create and the number will be like LT20230001 so when I create a contract I need to create first this number and then create contract. So i need to do in a shorter way.

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

      Not sure if that can be much optimized, maybe just not using some temporary variables, bu tthen lines would get longer.
      Just a few things.
      1. Instead of auth()->user()->id you can use auth()->id()
      2. Don't use $request->all() it's considered unsafe: laraveldaily.com/post/laravel-request-all-security-issue

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

      ​@@LaravelDaily Thank you sir for your valuable time that you replied me. so Humble and Highly Appreciated.

  • @er.anilkumarthakur1493
    @er.anilkumarthakur1493 Рік тому

    //its better to make it work with the date range... if I am wrong correct me
    ///trait
    public function scopeRecent($query, $search, $column = 'created_at')
    {
    if (empty($search) || ! isset($search)) {
    return $query;
    }
    return $query->whereDate($this->getTable().'.'. $column, '>=', Carbon::parse(current(explode(' to ', $search)))->startOfDay()->toDateString())
    ->whereDate($this->getTable().'.'.$column, '

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

      That probably may be more accurate, yes, the date accuracy was not the point of this video

  • @maulvieyazid7652
    @maulvieyazid7652 Рік тому +5

    Instead of concatenating $this->getTable . '.created_at'
    You can use $this->qualifyColumn('created_at')
    Its cleaner in my opinion
    Its not in laravel documentation, but this method exist in Model class