# Model

TIP

Model are actually behavior of app.

You will find model directory in App/Models/, All the models store here Suppose you want create database modal thats handel database stuff it will look like that

<?php

namespace App\Models;

use Config\Config;
use Zest\Database\Db as DB;

class Post extends DB
{
    /*
    * Store database name
    */
    protected static $db_name = Config::DB_NAME;
    /*
    * Store database table name
    */
    protected static $db_tbl = 'posts';

    public function name()
    {
        $db = new DB();
        $db->db()->method(); //example code
        //$db->db()->close() //close the connection
    }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

# Accessing models in Controllers

You can accesss models in following way \App\Models\modalname::method(param); So in our above example its look like \App\Models\Post::yourmethod

Last Updated: 3/22/2022, 4:20:26 PM