samedi 19 août 2017

why unable to pass project_id to Task Model in Laravel 5.2

need pass project model id as project_id to the Task model and save. this is My TaskController method

public function postNewTask(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")));
     $task->project_id = $project->id;

     // This will set the project_id on task and save it
    $project->tasks()->save($task);

}

this is Task 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 form action of My task related data saving

<form  method="post" action="">

and this is My routes

Route::post('projects/{projects}/tasks', [
    'uses' => '\App\Http\Controllers\TasksController@postNewTask',
    'as' => 'projects.tasks.create'
]);

but I got this error messages

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'project_id' cannot be null

how can soloed this problem. why unable to pass project_id



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2x0GRns
via IFTTT

Aucun commentaire:

Enregistrer un commentaire