I want to have an input, where you put a time in EU format like 12:00 or 21:34. (hh:mm) How do I do that?
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->string('arena');
$table->date("h,i"('beginn'));
$table->timestamps();
});
This is what I have, but it's obviously wrong.
You can use
$table->time('field_name');
Since laravel migration is based on traditional SQL convention, you cannot change the format using migration. This is because SQL datetime itself is formatted as YYYY-MM-DD HH:MM:SS. But you can use Carbon date time format to show the stored date, time or both as per you wish. Refer to this link for more on Carbon. Official Link Here
In laravel 5.6 you have this new feature that you can cast your timestamp so your migration should be like this
And in your
Post
model you can simply do this:Edit
If you are NOT using laravel 5.6 you can use Accessors & Mutators to easily manipulate data on setting on database or getting it from database so you can do something like this
And every time that you echoing it out in your blade or wherever like this
{{ $post->begin }}
it automatically changes the format for you.Hope that helps.
You could do this with Carbon, which is included in Laravel by default:
$date = Carbon::now()
$date->hour = 22
$date->minutes = 54
$table->date($date)