我想在我的网络应用程序上跟踪用户下载,因此我决定创建一个名为downloads的表。我已经在模型中指定了关系。
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'); }
}
以下是download
controller
功能
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();
}
其余的都是正确的。
答案 0 :(得分:2)
你的代码前面有一个return
语句,它无法访问,返回后你无法做任何事情......