{"id":35110046,"url":"https://github.com/seancheung/assets","last_synced_at":"2026-04-20T21:32:43.999Z","repository":{"id":57035656,"uuid":"74381963","full_name":"seancheung/assets","owner":"seancheung","description":"Assets/Resource storage managment for Laravel","archived":false,"fork":false,"pushed_at":"2016-12-09T09:55:32.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-19T20:47:34.101Z","etag":null,"topics":["attachment","file","laravel","media","php","storage"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seancheung.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-21T16:18:41.000Z","updated_at":"2018-01-29T06:23:11.000Z","dependencies_parsed_at":"2022-08-23T20:51:04.026Z","dependency_job_id":null,"html_url":"https://github.com/seancheung/assets","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/seancheung/assets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seancheung%2Fassets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seancheung%2Fassets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seancheung%2Fassets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seancheung%2Fassets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seancheung","download_url":"https://codeload.github.com/seancheung/assets/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seancheung%2Fassets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32067391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T21:26:33.338Z","status":"ssl_error","status_checked_at":"2026-04-20T21:26:22.081Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attachment","file","laravel","media","php","storage"],"created_at":"2025-12-27T19:30:51.619Z","updated_at":"2026-04-20T21:32:43.993Z","avatar_url":"https://github.com/seancheung.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Assets\nAssets/Resource storage managment for Laravel\n\n## Installation\n\n### Composer\n\n```shell\ncomposer require panoscape/assets\n```\n\n### Service provider\n\n\u003e config/app.php\n\n```php\n'providers' =\u003e [\n    ...\n    Panoscape\\Assets\\AssetsServiceProvider::class,\n];\n```\n\n### Asset\n\n\u003e config/app.php\n\n```php\n'aliases' =\u003e [\n    ...\n    'App\\Asset' =\u003e Panoscape\\Assets\\Asset::class,\n];\n```\n\n### Migration\n\n```shell\nphp artisan vendor:publish --provider=\"Panoscape\\Assets\\AssetsServiceProvider\" --tag=migrations\n```\n\n## Usage\n\nAdd `OwnAssets` trait to user model.\n\n```php\n\u003c?php\n\nnamespace App;\n\nuse Illuminate\\Notifications\\Notifiable;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\nuse Illuminate\\Database\\Eloquent\\SoftDeletes;\nuse Panoscape\\Assets\\OwnAssets;\n\nclass User extends Authenticatable\n{\n    use Notifiable, SoftDeletes, OwnAssets;\n}\n```\n\nAdd `HasAssets` trait to the model that uses assets.\n\n```php\n\u003c?php\n\nnamespace App;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Panoscape\\Assets\\HasAssets;\n\nclass Article extends Model\n{\n    use HasAssets;\n}\n```\n\n### Get assets owned by a user\n\n```php\n$user-\u003eassets();\n//or dynamic property\n$user-\u003eassets;\n```\n\n### Get assets used by a model\n\n```php\n$model-\u003eassets();\n//or dynamic property\n$model-\u003eassets;\n```\n\n### Asset\n\n```php\n//get the owner\n$asset-\u003eowner();\n//check owner's existence\n$asset-\u003ehasOwner();\n\n//get items of a specific type which use this asset\n$asset-\u003eitemsOf(App\\Article::class);\n\n//get url\n$asset-\u003eurl();\n\n//check file existence\n$asset-\u003eexists();\n\n//check if this asset is attached to any items\n$asset-\u003eattached();\n\n//remove the asset's related file\n$asset-\u003eremove();\n\n//get all assets which are not attached\nAsset::getDetached();\n\n//get all assets which have no owner\nAsset::getAnonymous();\n\n//get MIME type of the given extension\nAsset::getMimeType('jpg');\n//get all MIME types of the given extension\nAsset::getAllMimeTypse('jpg');\n\n//create asset from request\n//the first argument is the key of the file in the request\n//the second argument is the folder path(relative to the disk) in which the file will be stored, which if optional\n//the third argument is the disk to store in, which by default is 'public'\nAsset::createFromRequest('avatar', 'avatars', 'public');\n\n//create asset from storage\n//the first argument is the file path relative to the disk\n//the second argument is the disk to store in, which by default is 'public'\nAsset::createFromStorage('avatars/avatar_927.png', 'public');\n\n```\n\n#### Attach/Detach/Sync\n\n```php\n//by id\n$article-\u003eattachAssets(1);\n//by model instance\n$article-\u003eattachAssets($asset);\n//with array\n$article-\u003eattachAssets([1, 2]);\n$article-\u003eattachAssets([$asset1, $asset2]);\n\n//detach\n$article-\u003edetachAssets(1);\n//detach all\n$article-\u003edetachAssets([]);\n\n//sync\n$article-\u003esyncAssets(1);\n//detach all\n$article-\u003esyncAssets([]);\n//sync without detaching\n$article-\u003esyncAssets([1, 2], false);\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseancheung%2Fassets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseancheung%2Fassets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseancheung%2Fassets/lists"}