我想跟踪用户在我的Web应用程序上的下载,所以我决定创建一个名为下载的表。我已经在我的模型中分配了关系。
Download.php
<?php
use Illuminate'Auth'UserTrait;
use Illuminate'Auth'UserInterface;
use Illuminate'Auth'Reminders'RemindableTrait;
use Illuminate'Auth'Reminders'RemindableInterface;
class Download extends Eloquent {
protected $table = 'downloads';
// Relations
public function user(){return $this->belongsTo('User','user_id');}
public function catalog_downloads(){return $this->hasMany('CatalogDownload'); }
public function marketing_materials(){return $this->hasMany('Download'); }
}
这是我在其中一个controller
中的download
函数
public function file_download($id)
{
$catalog_download = CatalogDownload::findOrFail($id);
$distributor = Auth::user()->distributor()->first();
$export_type = $distributor->export_type()->first();
$product_export = $catalog_download->product_exports()->first();
$destinationPath = base_path().'/app/files/product_export/'. $catalog_download->id.'/'. $export_type->id.'/';
$file_name = $product_export->file_path;
$pathToFile = $destinationPath .$file_name;
if(Response::download()){
$download = new Download;
$download->title = $catalog_download->title;
$download->count = $download->count + 1;
$download->user_id = Auth::user()->id ;
$download->save();
}
return Response::download($pathToFile);
}
我已经downloads
桌子了。
由于某些原因,尚未将任何数据保存到数据库中。 :(
有人可以帮我看看这个吗?
我刚刚添加了这个代码块。
if(Response::download()){
$download = new Download;
$download->title = $catalog_download->title;
$download->count = $download->count + 1;
$download->user_id = Auth::user()->id ;
$download->save();
}
其余的都是正确的。
你的
代码前有一个return
语句,它是无法访问的,返回后你什么都不能做......