Level 104
Use the getPath() method on the Media object (which also takes a conversion argument if needed), e.g.
$asset->getFirstMedia()->getPath()
$asset->getFirstMedia()->getPath('thumbnail')
1 like
I am uploading a file using the Spatie media library package but somehow having hard time getting the storage path. If anyone know this or could direct me to some resources would be a great help. Thank you in advance.
Vue.js:
let formData = new FormData();
formData.append("file", this.file);
formData.append("asset_id", this.asset_id);
axios
.post("/assets/media", formData, {
headers: {
"Content-Type": "multipart/form-data"
}
})
Laravel controller:
Asset::findOrFail(request("asset_id"))
->addMedia(storage_path($request->file("name"))) // How to get this storage_path ?
->toMediaCollection();
Please or to participate in this conversation.