| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 | <?php
namespace App\Http\Services\Backend\ZooManagement;
use App\Models\ZooManagement\TigerManagement;
class TigerManagementService
{
    
    // 相關私有 model 調用器宣告
    private $tigerManagementDb;
    
    public function __construct()
    {
        // 建構 model 調用器
        $this->tigerManagementDb = new TigerManagement();
    }
    
    /**
     * 取得老虎資訊的列表
     *   排序、分頁均未實現
     * @return array:     返回老虎列表的陣列
     */
    public function getTigers()
    {
        // 取得參數
        // 調用資料庫(或者其他業務邏輯)
        $tigers = $this->tigerManagementDb->select(['id', 'tigerName'])->get()->toArray();
        
        // 整理返回值並返回
        return $tigers;
    }
    
    /**
     * 取得單一老虎資訊
     *
     * @param  integer $id : 老虎的自增量
     *
     * @return array:       返回老虎資訊的陣列
     */
    public function getTigerById($id)
    {
        // 取得參數
        // 調用資料庫(或者其他業務邏輯)
        $tigers = $this->tigerManagementDb->select(['id', 'tigerName'])->where('id', $id)->first()->toArray();
        
        // 整理返回值並返回
        return $tigers;
    }
    
    /**
     * 新增老虎
     *
     * @param  string $tigerName : 老虎名字
     *
     * @return bool:               返回新增的操作結果
     */
    public function insertTiger($tigerName)
    {
        // 取得參數
        // 調用資料庫(或者其他業務邏輯)
        $res = $this->tigerManagementDb
            ->insert(['tigerName' => $tigerName]);
        
        // 整理返回值並返回
        return $res;
    }
    
    /**
     * 修改老虎
     *
     * @param  integer $id :        老虎的自增量
     * @param  string  $tigerName : 老虎名字
     *
     * @return bool:                返回修改的操作結果
     */
    public function modifyTiger($id, $tigerName)
    {
        // 取得參數
        // 調用資料庫(或者其他業務邏輯)
        $res = $this->tigerManagementDb
            ->where('id', $id)
            ->update(['tigerName' => $tigerName]);
        
        // 整理返回值並返回
        return $res;
    }
    
    /**
     * 刪除老虎
     *
     * @param  integer $id : 老虎的自增量
     *
     * @return bool:         返回刪除的操作結果
     */
    public function deleteTigerById($id)
    {
        // 取得參數
        // 調用資料庫(或者其他業務邏輯)
        $res = $this->tigerManagementDb
            ->where('id', $id)
            ->delete();
    
        // 整理返回值並返回
        return $res;
    }
    
}
 |