{"action":"created","issue":{"url":"https://api.github.com/repos/spatie/laravel-medialibrary/issues/398","repository_url":"https://api.github.com/repos/spatie/laravel-medialibrary","labels_url":"https://api.github.com/repos/spatie/laravel-medialibrary/issues/398/labels{/name}","comments_url":"https://api.github.com/repos/spatie/laravel-medialibrary/issues/398/comments","events_url":"https://api.github.com/repos/spatie/laravel-medialibrary/issues/398/events","html_url":"https://github.com/spatie/laravel-medialibrary/issues/398","id":188980264,"number":398,"title":"clearMediaCollection and getFirstMediaUrl id discrepancy","user":{"login":"kickthemooon","id":7913974,"avatar_url":"https://avatars.githubusercontent.com/u/7913974?v=3","gravatar_id":"","url":"https://api.github.com/users/kickthemooon","html_url":"https://github.com/kickthemooon","followers_url":"https://api.github.com/users/kickthemooon/followers","following_url":"https://api.github.com/users/kickthemooon/following{/other_user}","gists_url":"https://api.github.com/users/kickthemooon/gists{/gist_id}","starred_url":"https://api.github.com/users/kickthemooon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kickthemooon/subscriptions","organizations_url":"https://api.github.com/users/kickthemooon/orgs","repos_url":"https://api.github.com/users/kickthemooon/repos","events_url":"https://api.github.com/users/kickthemooon/events{/privacy}","received_events_url":"https://api.github.com/users/kickthemooon/received_events","type":"User","site_admin":false},"labels":[{"id":199396048,"url":"https://api.github.com/repos/spatie/laravel-medialibrary/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-11-13T16:47:37Z","updated_at":"2016-12-16T02:34:14Z","closed_at":null,"body":"so this is my controller method:\r\n```\r\n$file = $request->file('file');\r\n        $settings = Settings::first();\r\n        $settings->clearMediaCollection('main_header_logo');\r\n        $settings->addMedia($file)->toCollection('main_header_logo');\r\n        $image = $settings->getFirstMediaUrl('main_header_logo', 'main_header_logo');\r\n        return response([\r\n            'status' => 'success',\r\n            'imageurl'   => $image\r\n        ]);\r\n```\r\nSo the process is:\r\n1. Clear media collection\r\n2. Add media to collection\r\n3. Get first (and assuming only) media url\r\n\r\nThe problem:\r\ngetFirstMediaUrl or getFirstMedia gives me the id of the media that was there before i cleared the collection\r\nso for example, it gives me 99 when actually the new added media is 100."},"comment":{"url":"https://api.github.com/repos/spatie/laravel-medialibrary/issues/comments/267502746","html_url":"https://github.com/spatie/laravel-medialibrary/issues/398#issuecomment-267502746","issue_url":"https://api.github.com/repos/spatie/laravel-medialibrary/issues/398","id":267502746,"user":{"login":"emilioborraz","id":1085846,"avatar_url":"https://avatars.githubusercontent.com/u/1085846?v=3","gravatar_id":"","url":"https://api.github.com/users/emilioborraz","html_url":"https://github.com/emilioborraz","followers_url":"https://api.github.com/users/emilioborraz/followers","following_url":"https://api.github.com/users/emilioborraz/following{/other_user}","gists_url":"https://api.github.com/users/emilioborraz/gists{/gist_id}","starred_url":"https://api.github.com/users/emilioborraz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emilioborraz/subscriptions","organizations_url":"https://api.github.com/users/emilioborraz/orgs","repos_url":"https://api.github.com/users/emilioborraz/repos","events_url":"https://api.github.com/users/emilioborraz/events{/privacy}","received_events_url":"https://api.github.com/users/emilioborraz/received_events","type":"User","site_admin":false},"created_at":"2016-12-16T02:34:14Z","updated_at":"2016-12-16T02:34:14Z","body":"My solution to this so far is to unset the Media relationship, please see step 3.\r\n\r\n1. $emailNotification->clearMediaCollection();\r\n2. $emailNotification->addMediaFromRequest('attachment')->usingName('email_notification_'.$emailNotification->id)->toMediaLibrary();\r\n3. $emailNotification->media = null;\r\n4. return $emailNotification->getMedia()->first();"}}
{"actor":{"display_login":"emilioborraz"}}