title: SQLSTATE[23000]: Integrity constraint violation: in Laravel 5.2
body: <p>I need pass Project Model id as project_id to My Task Model table. this is My TaskController</p>
  
  <pre><code>     public function store(Request $request, Project $project)
  {
      $task = new Task;
      $task-&gt;task_name   = $request-&gt;input('name');
      $task-&gt;body = $request-&gt;input('body');
      $task-&gt;assign = $request-&gt;input('status');
      $task-&gt;priority = $request-&gt;input('status');
       $task-&gt;duedate  = date("Y-m-d", strtotime($request-&gt;input("date")));
       $task-&gt;project_id = $project-&gt;id;
  
  
      // This will set the project_id on task and save it
      $project-&gt;tasks()-&gt;save($task);
  }
  </code></pre>
  
  <p>this is My form action route regarding to store task data in projects folder blade file is show.blade.php</p>
  
  <pre><code>&lt;form method="post" action="{{ route('tasks.store') }}"&gt;
  </code></pre>
  
  <p>this is Task Mode</p>
  
  <pre><code>&lt;?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-&gt;where('project_id', $id);
      }
  
  
       public function projects()
       {
           return $this-&gt;belongsTo('App\Project');
       }
  
  
      //
  }
  </code></pre>
  
  <p>this is Project Model</p>
  
  <pre><code> {
          protected $fillable = ['project_name','project_notes','project_status','color','group'];
          //
  
          public function tasks(){
               return $this-&gt;hasMany('App\Task');
      }
  
  
  but I got this error massage here
  </code></pre>
  
  <p>SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'project_id' cannot be null
   how can fix this problem?</p>