查看和下载计数 - 使用灯箱更新查看数据库并下载
Views and downloads count - Update database on view with lightbox and download
我用 laravel 创建了一个网站,并且有一个页面,其中有可以通过 fancybox 以高分辨率查看或下载的图片。在数据库中,我有每个动作的计数器。我已经为计数设置了 GET 路由,因为它们也用于其他情况。
例如:www.mysiste.com/somecode/someothercode/image/viewed
每个图像的简化结构是这样的。这在每个循环中调用。我删除了所有样式和 类 为了更好地阅读...
<div >
<div class="card" style="background-color: lightgray">
<div >
<a data-fancybox="gallery" href="/images/......../{{$photo->filename}}">
<img class="card-img" src="/images/......../thumb/thumb_{{$photo->filename}}">
</a>
</div>
<div class="card-footer">
<div>
<div>
<a download="{{$photo->filename}}" href="/images/......../{{$photo->filename}}">
<span>Download (Hi-Res)</span>
</a>
</div>
<div>
<a download="social_{{$photo->filename}}" href="/images/......../social_{{$photo->filename}}">
<span>Download (Social-Res)</span>
</a>
</div>
</div>
</div>
</div>
</div>
我需要这样,当他们点击下载按钮时,它会在后台调用某个 URL 以进行计数..(最重要)
如果可能的话,我想在通过 fancybox 全屏查看图像时点击另一个 URL。
如何做到这一点?
您可以按照以下方式进行操作:
<a data-fancybox="gallery" href="{{ route('photo.fancybox', ['photo' => $photo])}}">
<img class="card-img" src="/images/......../thumb/thumb_{{$photo->filename}}">
</a>
...
<a href="{{ route('photo.download', ['photo' => $photo])}}">
<span>Download (Hi-Res)</span>
</a>
PhotoController
public function download(Photo $photo){
$photo->downloadCount->increment();
return redirect('/images/......../'. $photo->filename);
}
public function fancybox(Photo $photo){
$photo->fancyboxCount->increment();
return redirect('/images/......../social_'. $photo->filename);
}
并确保相应地注册您的新路线:
Route::get('photo/download', 'PhotoController@download')->name('photo.download');
Route::get('photo/fancybox', 'PhotoController@fancybox')->name('photo.fancybox');
我用 laravel 创建了一个网站,并且有一个页面,其中有可以通过 fancybox 以高分辨率查看或下载的图片。在数据库中,我有每个动作的计数器。我已经为计数设置了 GET 路由,因为它们也用于其他情况。
例如:www.mysiste.com/somecode/someothercode/image/viewed
每个图像的简化结构是这样的。这在每个循环中调用。我删除了所有样式和 类 为了更好地阅读...
<div >
<div class="card" style="background-color: lightgray">
<div >
<a data-fancybox="gallery" href="/images/......../{{$photo->filename}}">
<img class="card-img" src="/images/......../thumb/thumb_{{$photo->filename}}">
</a>
</div>
<div class="card-footer">
<div>
<div>
<a download="{{$photo->filename}}" href="/images/......../{{$photo->filename}}">
<span>Download (Hi-Res)</span>
</a>
</div>
<div>
<a download="social_{{$photo->filename}}" href="/images/......../social_{{$photo->filename}}">
<span>Download (Social-Res)</span>
</a>
</div>
</div>
</div>
</div>
</div>
我需要这样,当他们点击下载按钮时,它会在后台调用某个 URL 以进行计数..(最重要)
如果可能的话,我想在通过 fancybox 全屏查看图像时点击另一个 URL。
如何做到这一点?
您可以按照以下方式进行操作:
<a data-fancybox="gallery" href="{{ route('photo.fancybox', ['photo' => $photo])}}">
<img class="card-img" src="/images/......../thumb/thumb_{{$photo->filename}}">
</a>
...
<a href="{{ route('photo.download', ['photo' => $photo])}}">
<span>Download (Hi-Res)</span>
</a>
PhotoController
public function download(Photo $photo){
$photo->downloadCount->increment();
return redirect('/images/......../'. $photo->filename);
}
public function fancybox(Photo $photo){
$photo->fancyboxCount->increment();
return redirect('/images/......../social_'. $photo->filename);
}
并确保相应地注册您的新路线:
Route::get('photo/download', 'PhotoController@download')->name('photo.download');
Route::get('photo/fancybox', 'PhotoController@fancybox')->name('photo.fancybox');