https://twill.io logo
Join Discord
Powered by
# ❓questions
  • u

    user

    05/22/2021, 9:47 AM
    Any idea on this?
  • d

    Dmi3yy

    05/22/2021, 10:09 AM
    What best practice for get all settings in Blade ? if use
    Copy code
    app(SettingRepository::class)->byKey('site_title');
    we have 3 query per each setting value
  • d

    Dmi3yy

    05/22/2021, 10:24 AM
    better by model )
  • d

    Dmi3yy

    05/22/2021, 10:24 AM
    Copy code
    $settings =  Setting::with('translations')->get()->pluck('value', 'key')->toArray();
  • i

    ifox

    05/22/2021, 10:27 AM
    will look into it, thank for flagging!
  • d

    Dmi3yy

    05/22/2021, 12:23 PM
    How i can get all images with crops ? i see
    Copy code
    public function images($role, $crop = "default", $params = [])
    public function imageAsArray($role, $crop = "default", $params = [], $media = null)
    but i get with one crop (
  • d

    Dmi3yy

    05/22/2021, 12:24 PM
    I use slider and tag picture inside https://tppr.me/g6J3A
  • i

    ifox

    05/22/2021, 12:31 PM
    you can filter the medias relationship by pivot->role manually to get all of them at once and then call ->image on each to get the url
  • i

    ifox

    05/22/2021, 12:32 PM
    but with a picture tag the idea is that you'd render different crops in different sources
  • i

    ifox

    05/22/2021, 12:35 PM
    you can also use the ImageService facade manually for more complex use cases
  • d

    Dmi3yy

    05/22/2021, 12:36 PM
    yep but tag picture good for that and if we use one img all ok
  • d

    Dmi3yy

    05/22/2021, 12:37 PM
    yes now I will do it, I asked because if there is a ready-made solution, then why do it again
  • i

    ifox

    05/22/2021, 12:38 PM
    https://github.com/croustille-io/twill-image
  • i

    ifox

    05/22/2021, 12:38 PM
    check this out
  • d

    Dmi3yy

    05/22/2021, 12:40 PM
    thanks
  • i

    ifox

    05/22/2021, 12:40 PM
    doesn't solve your logic for a slider but for picture tag implementation this is perfect
  • i

    ifox

    05/22/2021, 12:42 PM
    you can loop over a single crop to create your slides but then inside the slides render multiple crops
  • i

    ifox

    05/22/2021, 12:42 PM
    makes sense?
  • i

    ifox

    05/22/2021, 12:43 PM
    ->images('role', 'crop') and then use the index to pull the right crops from those media
  • i

    ifox

    05/22/2021, 12:44 PM
    I'll think about putting together a demo codebase for this
  • d

    Dmi3yy

    05/22/2021, 12:44 PM
    Yep webp support need too
  • d

    Dmi3yy

    05/22/2021, 12:46 PM
    I think soon finish project and will ask about code review if its posible, after that write some video review and totorials
  • i

    ifox

    05/22/2021, 12:47 PM
    sounds good! happy to review
  • r

    Rayderxx

    05/22/2021, 1:08 PM
    block translation is not really scoutfriendly 😉
  • d

    Dmi3yy

    05/23/2021, 9:43 AM
    @User what you think about this solution: - get crops for all images and in params we can set for each crop
    Copy code
    public function imagesWithCrops($role, $params = [])
        {
            $medias = $this->medias->filter(function ($media) use ($role) {
                return $media->pivot->role === $role;
            });
    
            $urls = [];
    
            foreach ($medias as $media) {
                $paramsforcrop = $params[$media->pivot->crop] ?? [];
                $urls[$media->id][$media->pivot->crop] = $this->image($role, $media->pivot->crop, $paramsforcrop, false, false, $media);
            }
    
            return $urls;
        }
    https://tppr.me/XAvPt
  • d

    Dmi3yy

    05/23/2021, 9:53 AM
    And
    Copy code
    public function imagesAsArraysWithCrops($role, $params = [])
        {
            $medias = $this->medias->filter(function ($media) use ($role) {
                return $media->pivot->role === $role;
            });
    
            $arrays = [];
    
            foreach ($medias as $media) {
                $paramsforcrop = $params[$media->pivot->crop] ?? [];
                $arrays[$media->id][$media->pivot->crop] = $this->imageAsArray($role, $media->pivot->crop, $paramsforcrop, $media);
            }
    
            return $arrays;
        }
    https://tppr.me/L55xu
  • d

    Dmi3yy

    05/23/2021, 9:53 AM
    If all ok i send PR
  • d

    Dmi3yy

    05/23/2021, 9:58 AM
    And in Blade: https://tppr.me/ATDQS
  • i

    ifox

    05/23/2021, 11:23 AM
    that's great @Dmi3yy, i can see this being helpful for sure, you can PR
  • d

    Dmi3yy

    05/23/2021, 11:35 AM
    Ok will do that )
1...121314...484Latest