내 응용 프로그램에서이 시나리오를 사용할 수있는 사용자는 각 에디션마다 하나의 저널을 업로드 할 수 있지만 에디션에는 여러 사용자의 저널이 많이 포함되어 있지만 사용자는 필요한 경우 다른 사용자에게 저널 작성자 중 한 사람으로 자격을 부여합니다 (태그가 추가 된 사용자는 저널을 업로드 할 수 없으며 사용자가 저널을 업로드하지 않은 경우 작성자로 태그가 지정된 저널을 사용하여 동일한 버전으로 저널을 업로드 할 수 있음). 아직). 지금까지 필자는 각 에디션에 업로드 할 수있는 파일의 수를 제한하는 것을 제외하고는이 작업을 수행했습니다. 다음은 내 마이그레이션은 다음과 같습니다사용자가 업로드 할 수있는 파일 수 제한 (Laravel 5.3)
판 테이블 :
class CreateTableEdition extends Migration {
public function up() {
Schema::create('edition', function (Blueprint $table) {
$table->increments('id');
$table->integer('volume');
$table->text('cover')->nullable();
$table->integer('number');
$table->timestamps();
});
Schema::table('journal', function(Blueprint $table) {
$table->foreign('id_edition')->references('id')->on('edition')->onDelete('cascade')->onUpdate('cascade');
});
}
public function down() {
Schema::table('journal', function(Blueprint $table) {
$table->dropForeign('journal_id_edition_foreign');
});
Schema::drop('edition');
}
}
저널 테이블 :
class CreateTableJournal extends Migration {
public function up() {
Schema::create('journal', function (Blueprint $table) {
$table->increments('id');
$table->string('title', 255);
$table->text('abstract');
$table->text('file');
$table->integer('id_edition')->unsigned();
$table->integer('user_id')->unsigned();
$table->string('journalslug');
$table->timestamps();
});
Schema::table('journal', function(Blueprint $table) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
});
}
public function down() {
Schema::table('journal', function(Blueprint $table) {
$table->dropForeign('journal_user_id_foreign');
});
Schema::drop('journal');
}
}
사용자 테이블 : 사용자 테이블과 저널을 연결하는
class CreateUsersTable extends Migration
{
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('username')->unique();
$table->string('userslug');
$table->string('nameslug');
$table->string('email')->unique();
$table->string('phone')->nullable();
$table->string('address')->nullable();
$table->string('password');
$table->rememberToken();
$table->enum('level', ['admin', 'author']);
$table->timestamps();
});
}
public function down()
{
Schema::drop('users');
}
}
Penulis 테이블 (피벗 테이블 테이블)
,210public function up()
{
Schema::create('penulis', function (Blueprint $table) {
// Create tabel penulis
$table->integer('id_user')->unsigned()->index();
$table->integer('id_journal')->unsigned()->index();
$table->timestamps();
$table->primary(['id_user', 'id_journal']);
$table->foreign('id_user')
->references('id')
->on('users')
->onDelete('cascade')
->onUpdate('cascade');
$table->foreign('id_journal')
->references('id')
->on('journal')
->onDelete('cascade')
->onUpdate('cascade');
});
}
public function down()
{
Schema::drop('penulis');
}
}
-Edition 테이블 저널 테이블은 일대 다 관계 (한 판 여러 저널을 가질 수있다)를 갖는다
-users 테이블 저널 테이블, 첫 번째 여러 관계있다 대다 관계 사용자가 업로드하려는 저널의 저자 중 한 사람으로 다른 사용자를 태그 할 수 있습니다. 이 관계는 피봇 테이블 (penulis table)을 사용하여 연결되었습니다. 두 번째 것은 저널을 업로드 한 사용자 만 저널을 수정하거나 삭제할 수있는 일원이 될 수 있도록 일대 다 관계 (한 명의 사용자가 많은 저널을 가짐)입니다 (태그가 지정된 사용자는 할 수 없습니다).
이제이 문제를 어떻게 해결할 수 있습니까? 사용자가 각 판에서 하나의 저널 만 업로드 할 수 있도록 업로드 할 수있는 파일의 수를 제한합니다. 아래는 저널을 저장하는 현재 컨트롤러입니다.
public function storejournal(JournalRequest $request) {
$input = $request->all();
$input['user_id'] = Auth::id();
//Input PDF
if ($request->hasFile('file')) {
$input['file'] = $this->uploadPDF($request);
}
$id = $request->id;
$journal = Edition::findOrFail($id)->journal()->create($input);
$journal->user()->attach($request->input('penulis'));
return redirect()->route('edition', ['id' => $id]);
}
누구나 도움이된다면, 저의 끔찍한 영어에 대해 고맙고 미안합니다.
세부적인 질문을하는 것이 중요하지만 명확성을 위해 불필요한 정보는 피하는 것이 중요합니다. – Wistar