pushoperations/magician 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pushoperations/magician

最新稳定版本:v2.0.0

Composer 安装命令:

composer require pushoperations/magician

包简介

A library for implementing repositories with magic finders for the Eloquent ORM.

README 文档

README

Build Status Coverage Status Scrutinizer Code Quality

Total Downloads Latest Stable Version Latest Unstable Version License

SensioLabsInsight

A library for implementing repositories with magic finders and caching for the Eloquent ORM.

Contents

Install

The recommended way to install is through Composer.

Update your project's composer.json file to include Magic Repository:

{
    "require": {
        "pushoperations/magician": "2.*"
    }
}

Then update the project dependencies to include this library:

composer update pushoperations/magician

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

Usage

A base implementation of the magic repository is already created for use out-of-the-box.

<?php namespace Controllers;

use Controller;
use Magician\Magician;

class ExampleController extends Controller
{
    public function __construct(Magician $magician)
    {
        // Tell this magician instance to be the repository manager for the 'User' model.
        $this->m = $magician->set('Models\User');
    }

    public function create()
    {
        $user = $this->m->firstOrMake(['email' => 'user@example.com']);

        if ($this->m->save($user)) {
            return $user;
        } else {
            return 'error: unable to save the user';
        }
    }

    public function read($id = null)
    {
        if ($id) {
            return $this->m->findById($id);
        } else {
            return $this->m->getById(['>', 0]);
        }
    }

    public function update($id)
    {
        $user = $this->m->findById($id);
        $user->fill([
            'trial' => true,
            'last_login' => new \DateTime,
            'subscription' => '2015',
        ]);

        $user->load('permissions');

        if ($this->rm->save($user)) {
            return $user;
        } else {
            return 'error: unable to save the user';
        }
    }

    public function inactive($date)
    {
        return $this->m->getByLastLogin(['<', $date]);
    }

    public function newTrials()
    {
        return $this->m->get10ByTrial(true, ['subscription' => 'asc'], ['email', 'subscription']);
    }
}

统计信息

  • 总下载量: 71
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 11
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-19