1. Go to this page and download the library: Download ricasolucoes/tecnico 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/ */
ricasolucoes / tecnico example snippets
namespace App;
use Tecnico\TecnicoGroup;
class Group extends TecnicoGroup
{
}
namespace App;
use Tecnico\Traits\UserHasGroups;
class User extends Model {
use UserHasGroups; // Add this trait to your model
}
$user = User::where('username', '=', 'sebastian')->first();
// group attach alias
$user->attachGroup($group, $pivotData); // First parameter can be a Group object, array, or id
// or eloquent's original technique
$user->groups()->attach($group->id); // id only
echo "I'm currently in group: " . Auth::user()->currentGroup->name;
echo "The group owner is: " . Auth::user()->currentGroup->owner->username;
echo "I also have these groups: ";
print_r( Auth::user()->groups );
echo "I am the owner of these groups: ";
print_r( Auth::user()->ownedGroups );
echo "My group has " . Auth::user()->currentGroup->users->count() . " users.";
if( Auth::user()->isGroupOwner() )
{
echo "I'm a group owner. Please let me pay more.";
}
$group = Auth::user()->currentGroup;
if( Auth::user()->isOwnerOfGroup( $group ) )
{
echo "I'm a specific group owner. Please let me pay even more.";
}
try {
Auth::user()->switchGroup( $group_id );
// Or remove a group association at all
Auth::user()->switchGroup( null );
} catch( UserNotInGroupException $e )
{
// Given group is not allowed for the user
}
Tecnico::inviteToGroup( $email, $group, function( $invite )
{
// Send email to user / let them know that they got invited
});
$user = Auth::user();
Tecnico::inviteToGroup( $user , $group, function( $invite )
{
// Send email to user / let them know that they got invited
});
if( !Tecnico::hasPendingInvite( $request->email, $request->group) )
{
Tecnico::inviteToGroup( $request->email, $request->group, function( $invite )
{
// Send email to user
});
} else {
// Return error - user already invited
}
$invite = Tecnico::getInviteFromAcceptToken( $request->token ); // Returns a TecnicoInvite model or null
if( $invite ) // valid token found
{
Tecnico::acceptInvite( $invite );
}
$invite = Tecnico::getInviteFromDenyToken( $request->token ); // Returns a TecnicoInvite model or null
if( $invite ) // valid token found
{
Tecnico::denyInvite( $invite );
}
namespace App\Listeners;
use Tecnico\Events\UserJoinedGroup;
class YourJoinedGroupListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param UserJoinedGroup $event
* @return void
*/
public function handle(UserJoinedGroup $event)
{
// $user = $event->getUser();
// $groupId = $event->getGroupId();
// Do something with the user and group ID.
}
}
namespace App\Listeners;
use Tecnico\Events\UserInvitedToGroup;
class YourUserInvitedToGroupListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param UserInvitedToGroup $event
* @return void
*/
public function handle(UserInvitedToGroup $event)
{
// $user = $event->getInvite()->user;
// $groupId = $event->getGroupId();
// Do something with the user and group ID.
}
}
use Tecnico\Traits\UsedByGroups;
class Task extends Model
{
use UsedByGroups;
}
// gets all tasks for the currently active group of the authenticated user
Task::all();
// gets all tasks from all groups globally
Task::allGroups()->get();