I need pass Project Model id as project_id to My Task Model table. this is My TaskController
public function store(Request $request, Project $project)
{
$task = new Task;
$task->task_name = $request->input('name');
$task->body = $request->input('body');
$task->assign = $request->input('status');
$task->priority = $request->input('status');
$task->duedate = date("Y-m-d", strtotime($request->input("date")));
// This will set the project_id on task and save it
$project->tasks()->save($task);
}
this is My form action route regarding to store task data in projects folder blade file is show.blade.php
<form method="post" action="">
this is Task Mode
<?php
namespace App;
use App\User;
use App\Auth;
use App\Project;
use Illuminate\Database\Eloquent\Model;
class Task extends Model
{
protected $fillable = ['task_name', 'body', 'assign','priority','duedate','project_id'];
public function scopeProject($query, $id)
{
return $query->where('project_id', $id);
}
public function projects()
{
return $this->belongsTo('App\Project');
}
//
}
this is Project Model
{
protected $fillable = ['project_name','project_notes','project_status','color','group'];
//
public function tasks(){
return $this->hasMany('App\Task');
}
but I got this error massage here
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'project_id' cannot be null how can fix this problem?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2vadnkX
via IFTTT
Aucun commentaire:
Enregistrer un commentaire