2017-03-27 48 views
0

我有兩個表「用戶」和「公告」,其中公告表有3個下載文件,所以我想添加一個功能,當用戶下載文件時添加用戶ID到下載文件?如何將用戶標識添加到每個文件中以便在laravel 5.2中下載?

通知式表

<?php 

use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreateAnnoucementsTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('announcements', function (Blueprint $table) { 
      $table->increments('project_id')->unsigned();; 
      $table->integer('types_id')->unsigned(); 
      $table->foreign('types_id')->references('id')->on('types')->onDelete('CASCADE')->onUpdate('CASCADE'); 
      $table->string('project_name'); 
      $table->string('extension'); 
      $table->date('deadline'); 
      $table->string('biddingdocuments'); 
      $table->string('amendmentdocuments'); 
      $table->string('noticestenders'); 
      $table->timestamps(); 
     }); 

    } 
/** 
* Reverse the migrations. 
* 
* @return void 
*/ 
public function down() 
{ 
    Schema::drop('announcements'); 
} 
} 


Users Table 
<?php 

use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreateUsersTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('users', function (Blueprint $table) { 
      $table->increments('id'); 
      $table->string('username')->unique(); 
      $table->string('email')->unique(); 
      $table->string('securityq'); 
      $table->string('securitya'); 
      $table->string('name'); 
      $table->string('fname'); 
      $table->string('lname'); 
      $table->string('gender'); 

      $table->string('cname'); 
      $table->integer('lnumber')->unique(); 
      $table->string('province'); 
      $table->string('city'); 
      $table->string('pnumber'); 

      $table->text('address'); 
      $table->string('password'); 
      $table->rememberToken(); 
      $table->timestamps(); 
     }); 
    } 

    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
     Schema::drop('users'); 
    } 
} 
userAnnoucement controller 

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 
use Illuminate\Http\Response; 

use App\Http\Requests; 
use App\Announcements; 



class UserAnnoucment extends Controller 
{ 
    public function index(Request $request) 
    { 

     $announcements = Announcements::orderBy('project_id','DESC')->paginate(5); 
     return view('userAnnoucements.index',compact('announcements'))->with('i', 

($請求 - >輸入( '頁',1) - 1)* 5); }

 /** 
    * Display the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 

    public function count(){ 
     $announcements = new Announcements; 
      $announcements->extension = Auth::user()->id; 
      $announcements->save(); 
     return $announcements; 

    } 



} 
`` 
+0

請正確格式化您的代碼。我無法理解這一點。 –

回答

0

,如果該網站是不是過於繁忙沒問題。否則,如果同時下載,您可能會發生衝突。

如果幾乎沒有流量,以編程方式將下載文件複製到臨時文件夾,請將用戶標識添加到文件名中,然後從那裏下載,即:1024_file.pdf。如果用戶中斷下載或返回,則文件已存在,但您可能要在每次下載後清除文件以節省磁盤空間,並且每次都使用相同的下載代碼。

在繁忙的服務上,爲每個用戶創建一個文件夾(如果其中一個尚不可用),並在這些文件夾中完成業務。

相關問題