-4

I can't figure out the problem, I tried the ones on stack overflow and did not work.

Can anyone help me with this?

error

The TaskController

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Task;

class TaskController extends Controller
{
    public function index() {
        return view('tasks.index');
    }

    public function store(Request $request) {
        $request->validate([
            'title' => 'required'
        ]);

        Task::create([
            'title' => $request->title
        ]);

        session()->flush('msg', 'Task has been created');
        return redirect('/');
    }
}

The Model

namespace App;

use Illuminate\Database\Eloquent\Model;

class Task extends Model {
    protected $fillable = ['title'];
    public $timestamps = false;
}
matiaslauriti
  • 7,065
  • 4
  • 31
  • 43

1 Answers1

4

As the error shows you, you have to add title to your $fillable model properties... Read this part of the documentation...

protected $fillable = ['title'];

As Tem Lewis said, you can also read this one.

matiaslauriti
  • 7,065
  • 4
  • 31
  • 43