0

I'm following along with laracast fundamentals. Things that should not be working, seem to be working just fine. For instance, When you create a database migration in Laravel, any field not explicitly defined as nullable, is supposed to have a null constraint. This shows in mysql:

mysql> describe articles;
+--------------+------------------+------+-----+---------------------+----------------+
| Field        | Type             | Null | Key | Default             | Extra          |
+--------------+------------------+------+-----+---------------------+----------------+
| id           | int(10) unsigned | NO   | PRI | NULL                | auto_increment |
| title        | varchar(255)     | NO   |     | NULL                |                |
| body         | text             | NO   |     | NULL                |                |
| created_at   | timestamp        | NO   |     | 0000-00-00 00:00:00 |                |
| updated_at   | timestamp        | NO   |     | 0000-00-00 00:00:00 |                |
| published_at | varchar(255)     | NO   |     | NULL                |                |
| excerpt      | text             | YES  |     | NULL                |                |
+--------------+------------------+------+-----+---------------------+----------------+
7 rows in set (0.00 sec)

In his videos, he goes to sunbmit without a published_at field and it throws an error. Mine works fine:

>>> App\Article::find(3)
=> App\Article {#734
     id: "3",
     title: "dtt",
     body: "dtt",
     created_at: "2015-11-23 01:10:05",
     updated_at: "2015-11-23 01:10:05",
     published_at: "",
     excerpt: null,
   }

I commit my data using:

public function store()
{
    Article::create(Request::all());
    return redirect('articles');
}
  • As @Gaz_Edge told me just recently in my question: "the point of tutorials is not just copy and paste, try and learn as their will be mistakes in tutorials" – davejal Nov 23 '15 at 23:55
  • As a sidenote I'm also curious if your following a laravel 5.1 course, because in my experience, their are so many ways (read differences) to achieve the same thing and you should find out which fits you the most. Taking that into consideration along with the big differences between versions (even between 5 and 5.1), I wouldn't fall over something that's working the way I want it to, but the other way around ... that will get my attention – davejal Nov 23 '15 at 23:58
  • I think my question was a bit nebulous so I cut it down. It is a 5.0 tutorial, and I can roll with that, but this is a core feature in both versions that is being ignored here. It's even set in the DB that NULL is not allowed. – Ryan Lewkowicz Nov 24 '15 at 00:05
  • I hope you recognize that published_at is a varchar field and not a date field, so please see this as your answer http://stackoverflow.com/q/18908309/3664960 – davejal Nov 24 '15 at 00:15
  • Thats it! @davejal if you would like to post that as the answer, I would gladly accept it. Thank you. – Ryan Lewkowicz Nov 25 '15 at 17:58
  • glad it did work out – davejal Nov 25 '15 at 18:45

2 Answers2

0

I think you are using Firefox. Google Chrome may solve the problem. Mozilla still don't has a format for date field.

smartrahat
  • 5,381
  • 6
  • 47
  • 68
0

Don't know if you noticed that your published_at is not a date, but a varchar field

published_at | varchar(255) | NO | | NULL

See this answer given to another question for the explanation

You are inserting empty strings, and empty string are not NULL

Community
  • 1
  • 1
davejal
  • 6,009
  • 10
  • 39
  • 82