I also use the route method so I can control permissions to files. Really worth doing. You can also hide your files above the public folder so it's not directly accessible.
@bashy Definitely not something you'd rely on, but good for analysing sources of downloads and other metrics which although not impossible to implement comes out of the box with GA - Although, going back to Barry's point wouldn't track direct downloads (or GA blocked by user).
Not sure I can actually do the way @Barryvdh stated, but working on it. Simply because I have a data table that as an ID and Document columns but there's not a way to get/find the ID as this is showing I'm wanting to show in the dashboard area of the cms I've built.
And the documents don't belong to a user or anything so it would be a case of Data::all() but need to get the amount of times each file has been downloaded and who by.
Hi @lstables, Wouldn't it be better to manage it via Ajax requests that control during the OnClick event of the link and updating by a controller method?
Using jQuery you can make any operation stopping the click default event as you need with:
$('#yourLinkId').on('click', function(e) {
e.preventDefault() //this stop the default click event
//Here you can put your ajax update operations including queries to your Laravel PHP code
}
If you are using several links with the same behaviour you can use a class name, not the id.
Looking at your initial post, would you not be better off having a lookup table, one which simply tracks a user ID and a document ID. The stats could then be aggregated for each download, plus you could drill into each download to see which users' have accessed the file.
Hi @lstables, try with this schema, I made it outside any dev-env and may have errors, but try to get the idea.
You could manage visited /downloaded times differently depends on your systems. And if you prefer to avoid the use of the LinkTypes table, you could use a specific column with a list of valid values.