Fix question crud
- remover answer on create form - add brand_id onto fillable - readonly on brand (dont change brand after question create) - add cascade delete on question You should create questions the add answers
This commit is contained in:
parent
febae0f282
commit
39e71e1965
2 changed files with 39 additions and 2 deletions
|
|
@ -39,7 +39,8 @@ class Question extends Model
|
|||
*/
|
||||
protected $fillable = [
|
||||
'question',
|
||||
'type'
|
||||
'type',
|
||||
'brand_id'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -77,6 +78,7 @@ class Question extends Model
|
|||
'brand_id' => [
|
||||
'label' => Str::ucfirst(trans('models.classes.brand')),
|
||||
'type' => CrudType::belongsTo(),
|
||||
'readonly' => true,
|
||||
'belongsTo' => Brand::class,
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
|
|
@ -94,7 +96,6 @@ class Question extends Model
|
|||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
CrudAction::view(),
|
||||
CrudAction::create(),
|
||||
CrudAction::update(),
|
||||
]
|
||||
]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CascadeDeleteQuestionAnswers extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// * Add cascade delete
|
||||
Schema::table('answers', function (Blueprint $table) {
|
||||
$table->dropForeign(['question_id']);
|
||||
$table->foreign('question_id')->references('id')->on('questions')->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// * Undo cascade delete (restrict as default)
|
||||
Schema::table('answers', function (Blueprint $table) {
|
||||
$table->dropForeign(['question_id']);
|
||||
$table->foreign('question_id')->references('id')->on('questions');
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue