Download the PHP package ricasolucoes/tecnico without Composer

On this page you can find all versions of the php package ricasolucoes/tecnico. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package tecnico

Tecnico

This package supports Laravel 6 and above.

Latest Version Build Status codecov.io SensioLabsInsight Scrutinizer Code Quality

Tecnico is the fastest and easiest method to add a User / Group association with Invites to your Laravel 6+ project.

Installation

composer require ricasolucoes/tecnico

The Tecnico Facade will be auto discovered by Laravel automatically.

Configuration

To publish Tecnico's configuration and migration files, run the vendor:publish command.

This will create a tecnico.php in your config directory. The default configuration should work just fine for you, but you can take a look at it, if you want to customize the table / model names Tecnico will use.

User relation to groups

Run the migration command, to generate all tables needed for Tecnico. If your users are stored in a different table other than users be sure to modify the published migration.

After the migration, 3 new tables will be created:

You will also notice that a new column current_group_id has been added to your users table. This column will define the Group, the user is currently assigned to.

Models

Group

Create a Group model inside app/Group.php using the following example:

The Group model has two main attributes:

The owner_id is an optional attribute and is nullable in the database.

When extending TecnicoGroup, remember to change the group_model variable in config/tecnico.php to your new model. For instance: 'group_model' => App\Group::class

User

Add the UserHasGroups trait to your existing User model:

This will enable the relation with Group and add the following methods groups(), ownedGroups() currentGroup(), invites(), isGroupOwner(), isOwnerOfGroup($group), attachGroup($group, $pivotData = []), detachGroup($group), attachGroups($groups), detachGroups($groups), switchGroup($group) within your User model.

Don't forget to dump composer autoload

Middleware

If you would like to use the middleware to protect to current group owner then just add the middleware provider to your app\Http\Kernel.php file.

Afterwards you can use the groupowner middleware in your routes file like so.

Now only if the authenticated user is the owner of the current group can access that route.

This middleware is aimed to protect routes where only the owner of the group can edit/create/delete that model

And you are ready to go.

Usage

Scaffolding

The easiest way to give your new Laravel project Group abilities is by using the make:tecnico command.

This command will create all views, routes and controllers to make your new project group-ready.

Out of the box, the following parts will be created for you:

Imagine it as a the make:auth command for Tecnico.

To get started, take a look at the new installed /groups route in your project.

Basic concepts

Let's start by creating two different Groups.

Now thanks to the UserHasGroups trait, assigning the Groups to the user is uber easy:

By using the attachGroup method, if the User has no Groups assigned, the current_group_id column will automatically be set.

Get to know my group(s)

The currently assigned Group of a user can be accessed through the currentGroup relation like this:

The Group model has access to these methods:

Group owner

If you need to check if the User is a group owner (regardless of the current group) use the isGroupOwner() method on the User model.

Additionally if you need to check if the user is the owner of a specific group, use:

The isOwnerOfGroup method also allows an array or id as group parameter.

Switching the current group

If your Users are members of multiple groups you might want to give them access to a switch group mechanic in some way.

This means that the user has one "active" group, that is currently assigned to the user. All other groups still remain attached to the relation!

Glad we have the UserHasGroups trait.

Just like the isOwnerOfGroup method, switchGroup accepts a Group object, array, id or null as a parameter.

Inviting others

The best group is of no avail if you're the only group member.

To invite other users to your groups, use the Tecnico facade.

You can also send invites by providing an object with an email property like:

This method will create a GroupInvite model and return it in the callable third parameter.

This model has these attributes:

In addition to these attributes, the model has these relations:

Note: The inviteToGroup method will not check if the given email already has a pending invite. To check for pending invites use the hasPendingInvite method on the Tecnico facade.

Example usage:

Accepting invites

Once you invited other users to join your group, in order to accept the invitation use the Tecnico facade once again.

The acceptInvite method does two thing:

Denying invites

Just like accepting invites:

The denyInvite method is only responsible for deleting the invitation from the database.

Attaching/Detaching/Invite Events

If you need to run additional processes after attaching/detaching a group from a user or inviting a user, you can Listen for these events:

In your EventServiceProvider add your listener(s):

The UserJoinedGroup and UserLeftGroup event exposes the User and Group's ID. In your listener, you can access them like so:

The UserInvitedToGroup event contains an invite object which could be accessed like this:

Limit Models to current Group

If your models are somehow limited to the current group you will find yourself writing this query over and over again: Model::where('group_id', auth()->user()->currentGroup->id)->get();.

To automate this process, you can let your models use the UsedByGroups trait. This trait will automatically append the current group id of the authenticated user to all queries and will also add it to a field called group_id when saving the models.

Note:

This assumes that the model has a field called group_id

Usage

When using this trait, all queries will append WHERE group_id=CURRENT_TEAM_ID. If theres a place in your app, where you really want to retrieve all models, no matter what group they belong to, you can use the allGroups scope.

Example:

License

Tecnico is free software distributed under the terms of the MIT license.

'Marvel Avengers' image licensed under Creative Commons 2.0 - Photo from W_Minshull


All versions of tecnico with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2|^8.0
laravel/framework Version ^6.0|^7.0|^8.0
sierratecnologia/pedreiro Version ^0.4.0
sierratecnologia/muleta Version ^0.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ricasolucoes/tecnico contains the following files

Loading the files please wait ....