1. Go to this page and download the library: Download pushoperations/magician 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/ */
pushoperations / magician example snippets
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' => '[email protected]']);
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']);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.