PHPackages                             geekyants/share-dialog - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. geekyants/share-dialog

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

geekyants/share-dialog
======================

Share Popup in Laravel Apps

v1.0.2(5y ago)151033[1 PRs](https://github.com/GeekyAnts/laravel-inertia-sharedo/pulls)MITVuePHP &gt;=5.3.0

Since Feb 9Pushed 5y ago5 watchersCompare

[ Source](https://github.com/GeekyAnts/laravel-inertia-sharedo)[ Packagist](https://packagist.org/packages/geekyants/share-dialog)[ Docs](https://github.com/geekyants/share-dialog)[ RSS](/packages/geekyants-share-dialog/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (35)Used By (0)

**Sharedo**
===========

[](#sharedo)

[![Latest Version on Packagist](https://camo.githubusercontent.com/77bc35cb8a8b8be3aa6aa69eafa6ec53ad53664b9a00b6e08548b622561a12dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6765656b79616e74732f7368617265646f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/geekyants/sharedo)[![License](https://camo.githubusercontent.com/f2d2902981d110f0dd575475fec357f82050b5a6bc87c29b9da71426ce7c7236/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6765656b79616e74732f7368617265646f)](https://github.com/GeekyAnts/laravel-inertia-sharedo/blob/master/LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/7153bd330d8738e3c5520db1efaf3d52bbbe8366b1ca35740640fcf3acf14546/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6765656b79616e74732f7368617265646f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/geekyants/sharedo)

Share Popup for Laravel Apps

[![Sharedo](./public/images/sharedo.gif)](./public/images/sharedo.gif)

1) Introduction
---------------

[](#1-introduction)

**Sharedo** provides you an interface to manage roles and permissions for Laravel apps. You can assign read or write permissions to a user and remove the permissions as required. It is powered by Inertia.js and Laravel Bouncer.

2) Motivation
-------------

[](#2-motivation)

We realised that it is very time consuming to add a share functionality to Laravel projects and this can hinder the development process.
This package aims to solve this problem by enabling you to share your project's entities with other users easily.

3) Dependencies
---------------

[](#3-dependencies)

If you have [Tailwind](https://tailwindcss.com/) and [Bouncer](https://github.com/JosephSilber/bouncer) pre-installed, you can move on to the [Installation](#4-installation) section.

### **Tailwind Installation**

[](#tailwind-installation)

Install Tailwind as shown below:

```
npm install -D tailwindcss@latest postcss@latest autoprefixer@latest
```

Next, generate your tailwind.config.js file:

```
npx tailwindcss init
```

In your **tailwind.config.js** file, configure the **purge** option with the paths to all of your Blade templates and JavaScript components so Tailwind can tree-shake unused styles in production builds:

```
module.exports = {
    purge: [
        "./resources/**/*.blade.php",
        "./resources/**/*.js",
        "./resources/**/*.vue",
    ],
    darkMode: false, // or 'media' or 'class'
    theme: {
        extend: {},
    },
    variants: {
        extend: {},
    },
    plugins: [],
};
```

In your webpack.mix.js, add **tailwindcss** as a PostCSS plugin:

```
mix.js("resources/js/app.js", "public/js").postCss(
    "resources/css/app.css",
    "public/css",
    [require("tailwindcss")]
);
```

Open the `./resources/css/app.css` file and add the following code, replacing the original file contents:

```
/* ./resources/css/app.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
```

Next, import your stylesheet in your main Blade layout (commonly `resources/views/layouts/app.blade.php` or similar) and add the responsive viewport meta tag if it's not already present:

```

```

### **Bouncer Installation**

[](#bouncer-installation)

Install Bouncer with composer:

```
composer require silber/bouncer v1.0.0-rc.10
```

Add Bouncer's trait to your user model:

```
use Silber\Bouncer\Database\HasRolesAndAbilities;

class User extends Model
{
    use HasRolesAndAbilities;
}
```

Publish Bouncer's migrations to your app's migrations directory by running the following command:

```
php artisan vendor:publish --tag="bouncer.migrations"
```

4) Installation
---------------

[](#4-installation)

1. Install the Sharedo package using composer as shown below:

    ```
    composer require  geekyants/sharedo
    ```
2. After installation, move the package's config file to your project's config folder:

    ```
    php artisan vendor:publish  --tag="config"
    ```
3. Moving forward, scaffold the view components present in the sharedo package as follows:

    ```
    php artisan ui sharedo
    ```

    A **Sharedo** folder containing Vue.js components will be created in your resources directory. You can now easily customise your Sharedo's Vuejs components 🚀
4. Now, run the migrations. After executing this command, Bouncer migrations and the **new\_users\_sharedo** table will be migrated:

    ```
    php artisan migrate
    ```

5. To compile and minify the CSS and JavaScript files generated by sharedo, add this to your webpack.mix.js file:

    ```
    .js("resources/js/sharedo.js", "public/js")
    .vue()
    ```

    > Note: If your css is not compiled in your app.css file, you can change it in the sharedo.blade.php file.
6. Install the dependencies:

    ```
    composer install
    npm install
    ```
7. Finally, build your assets as shown below:

    ```
    npm run dev
    ```

5) Usage
--------

[](#5-usage)

You must define a relation **user** on the entity model that you want to share. The relation should return the user of that entity.

To share your entity with other users, visit:

```
{APP_URL}/sharedo/{entity_name}/{entity_id}
```

For example, if you want to open Sharedo for a project model with id 123, then visit:

```
{APP_URL}/sharedo/projects/123

```

> Note: **The entity\_name should have the same name as that of the database migration corresponding to the model that you want to share.**

> Note: **Sharedo sends error messages back to your application in the error props.**

If you invite a user who is not present in your database, Sharedo automatically creates it in your users table. Also, a new entry is inserted into the **new\_users\_sharedo table** referencing the user's id as a foreign key and **has\_ever\_logged\_in** property is set to false.
This can help you differentiate between the users created by Sharedo and users created by the usual sign-up flow.

To restrict other users from accessing your entities, you have to explicitly use the Bouncer methods [here](https://github.com/JosephSilber/bouncer#cheat-sheet).

> Note: **Uses who are given write access to the entity can also share that entity with other users.**

6) Customisation
----------------

[](#6-customisation)

You can customise the functionality of Sharedo easily by making changes in the sharedo.php file present in your config folder.

You can customise the functionality of Sharedo easily by making changes to the **sharedo.php** file present in your config folder.

1. If your files are not present in the `App\Models\\`, then change the modelPath to that location instead of `App\Models\\`.

    ```
    "modelPath" => "App\Models\\"
    ```
2. To add your own custom middleware to Sharedo, append it to the middleware array.
    For example, if you want to add the **"admin"** middleware, then your middleware array will look like this:

    ```
    "middleware" => ['web', 'auth','admin']
    ```
3. If you want only certain entities to be shareable, you can add them to the **restrict-entities** array.
    For instance, if you want only the files entity to be shareable, your array will look like this:

    ```
    'restrict-entities' => ['files'],
    ```
4. You can also send email notifications to the users when they are given access to an entity.
    Sharedo fires an **UserAbilityChanged** event when a user's access is changed and attaches the **SendUserAbilityChangedNotification** listener to it. If you want to send an email notification, make the following changes in EventServiceProvider:

    ```
    use Geekyants\Sharedo\Events\UserAbilityChanged;
    use Geekyants\Sharedo\Listeners\SendUserAbilityChangedNotification;
    protected $listen = [
     ...
          UserAbilityChanged::class => [
            SendUserAbilityChangedNotification::class,
        ]

    ];
    ```

    You can also modify the email template by publishing the Sharedo mail resources:

    ```
    php artisan vendor:publish  --tag="mail"
    ```

    > After running this command, the mail notification template will be located in the `resources/vendor/sharedo/mail` directory:

    You can attach your own listeners to the event. For example, if you want to attach a **SendSlackNotification** listener to the **UserAbilityChanged** event, execute the following:

    ```
    use Geekyants\Sharedo\Events\UserAbilityChanged;

    ...

    protected $listen = [
            UserAbilityChanged::class => [
                SendSlackNotification::class,
            ]
        ];
    ```
5. To provide an option that allows searching for users, you can create a class that implements **UserContactsInterface**.php from the package and define the **getUserContacts** function.

    The return type of the **getUserContacts** function should be a string containing a JSON representation of an array of objects. Each object denoting a user must have an **"email"** attribute as shown below:

    ```
    "[
      { email: '', ... },
      { email: '', ... },
      { email: '', ... }
    ]"
    ```

    For example, you can create a class called **SendUserContacts** which implements **UserContactsInterface** and performs an operation to get users in the **getUserContacts** function:

    ```
