1. Go to this page and download the library: Download tatter/relations 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/ */
$user->addGroup(3);
if ($user->hasGroups([1, 3]))
{
echo 'allowed!';
}
$user->setGroups([]);
// User hasMany Widgets
$user = $userModel->with('widgets')->find($userId);
echo "User {$user->name} has " . count($user->widgets) . " widgets.";
// ... but a Widget belongsTo one User
$widget = $widgetModel->with('users')->find($widgetId);
echo $widget->name . " belongs to " . $widget->user->name;
/* Define your models */
class UserModel
{
use \Tatter\Relations\Traits\ModelTrait;
protected $table = 'users';
protected $with = 'widgets';
...
/* Then in your controller */
$groups = $groupModel->whereIn('id', $groupIds)->with('users')->findAll();
foreach ($groups as $group)
{
echo "<h1>{$group->name}</h1>";
foreach ($group->users as $user)
{
echo "{$user->name} is a {$user->role} with " . count($user->widgets) . " widgets.";
}
}
shell
php spark schemas
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.