lundi 23 novembre 2015

General Laravel 5.1 Inconsistencies

This is possibly supposed to be 2 questions. It covers a trend though, so I'm going to ask them both.

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');
}

Additionally, HTML forms seems to work differently. It's part of "collective" now but he's got a date input:

<div class="form-group">
    {!! Form::label('published_at', 'Publish On:') !!}
    {!! Form::input('date', 'published_at', null, ['class' => 'form-control']) !!}
</div>

And it shows a date field in the browser. Mine does not. Also, in place of null, he can only put a formatted date. I can put whatever I want in that field.

Weird stuff is cropping up that is not easily googled. Should I just not worry about it for now and keep moving and it will make sense later?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire