Projectslaravel-shortifyOwnership

Laravel Shortify

Package

URL shortening with visit tracking for Laravel.

Upgrade Guide

Ownership

Short URLs can belong to an authenticated user via user_id.

Automatic attachment

When shortening while authenticated, Shortify sets user_id from Auth::user() unless you pass user_id in $attributes.

$this->actingAs($user);

$short = Shortify::url('https://example.com');
$short->user_id; // $user->id
$short->owner;   // $user

Explicit ownership

Shortify::make()->shorten($longUrl, attributes: [
    'user_id' => $owner->id,
]);

// Or clear ownership while authenticated:
Shortify::make()->shorten($longUrl, attributes: [
    'user_id' => null,
]);

Querying

use BradieTilley\Shortify\Models\ShortifyUrl;

ShortifyUrl::query()->ownedBy($user)->get();
ShortifyUrl::query()->ownedBy($user->id)->get();

Configure the user model with models.user in Configuration.