<?php

namespace App;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class PhotoGallery
 * @package App
 * @mixin Builder
 */
class PhotoGallery extends Model
{
    use SoftDeletes;

    protected $fillable = ['image', 'show_in_home'];

    public static function withDescription($skip = null)
    {
        $query = self::where('photo_galleries.show_in_home', '=', 1)
            ->orderByDesc('photo_galleries.id')
            ->join('photo_gallery_descriptions as sd', 'sd.photo_gallery_id', 'photo_galleries.id')
            ->where('sd.language_id', currentLanguage()->id)
            ->limit(6)->select(['photo_galleries.*', 'sd.title']);

        if ($skip){
            $query->skip($skip)->take(6);
        }

        return $query->cursor();
    }
}
