PHP code example of lingyun / think-repositories

1. Go to this page and download the library: Download lingyun/think-repositories library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lingyun / think-repositories example snippets



namespace app\repositories;

use think\Repository;

class FilmsRepository extends Repository {

    public function model() {
        return 'App\Film';
    }
}


namespace app\model;

use think\Model;

class Film extends Model {

    protected $primaryKey = 'film_id';

    protected $table = 'film';

    protected $casts = [
        "rental_rate"       => 'float'
    ];
}


namespace app\controller;

use app\repositories\FilmsRepository as Film;

class FilmsController extends Controller {

    private $film;

    public function __construct(Film $film) {

        $this->film = $film;
    }

    public function index() {
        return \Response::json($this->film->all());
    }
}