Package Data | |
---|---|
Maintainer Username: | tonglil |
Package Create Date: | 2015-01-17 |
Package Last Update: | 2015-06-19 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-04-18 15:19:02 |
Package Statistics | |
---|---|
Total Downloads: | 70 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 11 |
Total Forks: | 1 |
Total Open Issues: | 3 |
A library for implementing repositories with magic finders and caching for the Eloquent ORM.
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';
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']);
}
}