세 가지 모델이 있습니다. 사용자, 알림 및 Lmo 알림. 관계는 사용자 hasMany Notifications이고 통지에는 많은 LmoNotification이 있습니다.hasMany 및 belongsTo Laravel
알림을 삽입하려면 lmoNotification 두 모델과 컨트롤러를 만들었고 별도의 데이터베이스 테이블이 있습니다.
내 문제는 데이터베이스에 알림을 입력 할 때 외래 키로 user_id에 아무런 문제없이 데이터를 삽입 할 때 발생합니다. 그러나 다음에 내가 화해에 들어가려고 할 때, 그것은 오류를 준다.
통지 모델 :
class Notification extends Model
{
protected $table = "notifications";
protected $fillable = [
'unit_code', 'unit_name', 'project_title', 'project_ref_number', 'storage_location', 'keeper_name', 'user_id',
];
public function user(){
return $this->belongsTo('App\User');
}
}
LmoNotification 모델
class AddLmoNotification extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $table = "lmo_notifications";
protected $fillable = [
'lmo_name', 'lmo_risk_level', 'lmo_quantity', 'lmo_volume', 'notification_id',
];
public function notification(){
return $this->belongsTo('App\Notification');
}
}
통지 제어부는 통지를 만드는
public function create(Request $request)
{
$notification = Notification::create([
'unit_code'=>$request->unit_code,
'unit_name'=>$request->unit_name,
'project_title'=>$request->project_title,
'project_ref_number'=>$request->project_ref_number,
'storage_location'=>$request->storage_location,
'keeper_name'=>$request->keeper_name,
'user_id'=>Auth::user()->id
]);
return redirect()-> route('show.lmo_form', $notification->id);
// return view('ApplicationForms.notifi', $notification);
}
Lmonotification 제어기
0,123,169,532 78,347,web.php
Route::prefix('notification')->group(function(){
/*show notification main page*/
Route::get('/', '[email protected]')->name('show.go_to_notification');
/*route to lmo_notification_form*/
Route::get('/personal_information_notification_form', '[email protected]');
/*route to biohazardous material notification form*/
Route::get('/biohazardous_material_notification_form', '[email protected]')->name('show.biohazardous_material_notification_form');
/*submit lmo notification route*/
Route::post('/personal_information_notification_form/submit', '[email protected]')->name('submit.personal_Info_Notification');
/*Rtoute to lmo form*/
Route::get('/personal_information_notification_form/add_lmo/{notification_id}', '[email protected]')->name('show.lmo_form');
/*Route to submit lmo list for notification*/
Route::post('/personal_information_notification_form/add_lmo', '[email protected]')->name('submit.lmo_list');
});
알림 테이블
Schema::create('notifications', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
$table->string('unit_code')->nullable();
$table->string('unit_name')->nullable();
$table->string('project_title')->nullable();
$table->string('project_ref_number')->nullable();
$table->string('storage_location');
$table->string('keeper_name');
$table->timestamps();
});
LMO 알림 테이블
public function up()
{
Schema::create('lmo_notifications', function (Blueprint $table) {
$table->increments('id');
$table->integer('notification_id')->unsigned();
$table->foreign('notification_id')->references('id')->on('notifications')->onDelete('cascade')->onUpdate('cascade');
$table->string('lmo_name');
$table->string('lmo_risk_level');
$table->string('lmo_quantity');
$table->string('lmo_volume');
$table->timestamps();
});
}
알림 표는 몇 가지 개인 정보 필드를 포함하고 lmonotification 제품의 목록이 포함되어 있습니다.
는오류 메시지가 말한다
SQLSTATE [23000] : 무결성 제약 조건 위반 : 1,048 열 'notification_id는'널 (SQL 수 없습니다 : (
lmo_notifications
에 삽입lmo_name
,lmo_risk_level
,lmo_quantity
,lmo_volume
,notification_id
,updated_at
,created_at
) 값은 (ASD, 중간, 2, 2, 2017년 5월 9일 22시 35분 15초, 2017년 5월 9일 22시 35분 15초는))
도와주세요.
감사합니다. 나는 이미 다른 방식으로 이것을 해왔다. 나는 ('notification', $ notification);을 사용하여보기를 ' '보기 ('Notification.notification_for_lmo ') ->로 직접 다음보기로 보냈습니다. – Mill3r