Laravel Shareable Models

This package allows you to generate shareable links from your Eloquent Models. Think of it as dynamic routes that only exist for some models in your database.

It takes something like this:

class User extends Model {}

And turns it into this

Now all you have to do is define a route

Route::get('/shared/{shareable_link}', ['middleware' => 'shared', function (ShareableLink $link) {

// object(User)#1 (0) {}

The hash in the url gets resolved automatically by the provided shared middleware. You can then accessed the shared model via the shareable property of the link.

Here's a more complete example:


use Carbon\Carbon;
use Sassnowski\LaravelShareableModel\ShareableLink;

// Assume we have a user record for which we want to generate 
// a shareable link 
$user = User::create([
    'name' => 'Kai Sassnowski',
    'email' => '',
    'password' => bcrypt('super-secret'),

$link = ShareableLink::buildFor($user)
    // We can password protect the created link.

    // By default generated links are inactive.

    // You can prefix the created link to create unique routes
    // for different models.

    // We can configure the link to throw an event every time
    // it is visited by a user. That way you can attach arbitrary
    // event listeners to it. For example, you might want to
    // notify the user who shared the link via email that it has
    // been visited.

    // We can assign an expiration date to a link to ensure
    // it can only be visited until a certain date.


// string(57) "http://localhost/shared/users/egpZWPKbzmUB8aDz57ZXh58b8Jk"

results matching ""

    No results matching ""