-1

I just found out that input data to db on laravel could use Model::create() but my question is what if i want to submit specific column? How do i do it? For example table user with name, email, address, and phone. Bug only input the name only without email, address, and phone.

Martin Christopher
  • 389
  • 1
  • 7
  • 21

1 Answers1

0

You can simply do this

 Model::create(['name' => $name]);

But make sure to make other columns email, address, and phone nullable or keep the default value for them, else it will throw any error.

Note: If you are using MySQL database, then you have to set the default to nullable from MySQL database data structure.

But if you are using MongoDB with Laravel then you don't need to set other fields as nullable Because MongoDB is an unstructured (NoSql) database.

Don't Panic
  • 13,965
  • 5
  • 32
  • 51
Prashant Deshmukh.....
  • 2,244
  • 1
  • 9
  • 11