mercredi 31 mai 2017

Laravel query writing

I am developing a project in Laravel 5.4. I want to write a select, insert and update query in my model that should work for any table in database. I used to do this is Codeigniter and work fine there, but I don't know how to use it in Laravel.

Following is the code from a model file in Codeigniter

class General_Model extends CI_Model {

        public function fetch_CoustomQuery($sql){
        $query = $this->db->query($sql);
        return $query->result(); 

        }


        public function create_record($data, $tbl) 
        {
        $this->db->set($data);
        $this->db->insert($tbl);
        return ($this->db->affected_rows() != 1) ? FALSE : TRUE;
        }



        public function update_record($data, $tbl, $wher) 
        {
        $this->db->where($wher);
        $this->db->set($data);
        $this->db->update($tbl);
        }


        public function delete_record($tbl, $wher) 
        {
        $this->db->where($wher);
        $this->db->delete($tbl);         
        } 
}

It was very easy in Codeigniter. I only need to pass the parameters and worked fine. I want to write same queries in my model in Laravel. Please help



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rcQUVp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire