项目作者: agungsugiarto

项目描述 :
The Illuminate Database package for CodeIgniter 4
高级语言: PHP
项目地址: git://github.com/agungsugiarto/codeigniter4-eloquent.git
创建时间: 2020-08-04T12:36:35Z
项目社区:https://github.com/agungsugiarto/codeigniter4-eloquent

开源协议:MIT License

下载


The Illuminate Database package for CodeIgniter 4

Latest Stable Version
Total Downloads
Latest Unstable Version
License

Update from v1.x to 2.x

just simple publish config eloquent with command

  1. php spark eloquent:publish

Instalation

Include this package via Composer:

  1. composer require agungsugiarto/codeigniter4-eloquent

Publish config

  1. php spark eloquent:publish

Costuming view pagination

The default view for pagination available with preset for bootstrap4 and basic html, if you want to costumize
just copy from \vendor\agungsugiarto\codeigniter4-eloquent\src\Views\Bootstrap4.php and modify with your style after that put on folder App\Views. Finnaly change your config in App\Config\Eloquent.php

Setup services eloquent

Open App\Controllers\BaseController.php

add service('eloquent'); on function initController

  1. //--------------------------------------------------------------------
  2. // Preload any models, libraries, etc, here.
  3. //--------------------------------------------------------------------
  4. // E.g.:
  5. // $this->session = \Config\Services::session();
  6. service('eloquent');

Usage

Example model

  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Authors extends Model
  5. {
  6. protected $table = 'authors';
  7. protected $primaryKey = 'id';
  8. }

How to use in controller

  1. <?php
  2. namespace App\Controllers;
  3. use App\Models\Authors;
  4. use Fluent\Models\DB;
  5. class Home extends BaseController
  6. {
  7. public function index()
  8. {
  9. return $this->response->setJSON([
  10. 'data' => Authors::all(),
  11. 'sample' => DB::table('authors')->skip(1)->take(100)->get(),
  12. ]);
  13. }
  14. }

License

This package is free software distributed under the terms of the MIT license.