<?php namespace App\Models;

use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Model;

class NewsModel extends Model
{
    protected $table = 'news';

    protected $allowedFields = ['newsID','title','body','slug','img','meta_desc','meta_keywords','status','dateCreated','createdBy','dateModified','modifiedBy'];

    


    public function updateNews($newsId,$data){

        $db= \Config\Database::connect();
       $builder = $db->table('news');

        $builder->where('newsID', $newsId);
        return  $builder->update($data);

    }


    public function getNews($slug = false)
{
    if ($slug === false)
    {
        return $this->findAll();
    }

    return $this->asArray()
                ->where(['slug' => $slug])
                ->first();
}

}
