<?php

namespace App\Models;

use CodeIgniter\Model;

class BannersModel extends Model
{
    protected $table = 'banners';
    protected $primaryKey = 'id';

    protected $allowedFields = [ 'name', 'photo', 'description', 'url', 'status'];

    protected $returnType     = 'array';
    protected $useTimestamps  = true;
    protected $useSoftDeletes = true;

    protected $createdField = 'created_at';
    protected $updatedField = 'updated_at';
    protected $deletedField = 'deleted_at';

    
    public function getAll()
    {
        $builder = $this->db->table('banners');
        return $result = $builder->get()->getResult();
    }

    public function singleBanner($id)
    {
        $builder = $this->db->table('banners');
        $builder->where('id', $id);
        return $result = $builder->get()->getRow();
    }

    public function getBanner()
    {
        $builder = $this->db->table('banners');
        $builder->limit(2);
        $builder->orderBy('id', 'DESC');
        return $result = $builder->get()->getResult();
    }

}