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; } } ``
請正確格式化您的代碼。我無法理解這一點。 –