简体   繁体   中英

Laravel collective how to set Form::date default value based on the object value

I have my edit route which displays an edit form view to allow me to edit details for specific member.

I have forms such as

{{Form::text('first_name', $member->first_name, ['class' => 'form-control'])}}

For all Form::text it is easy to set default value as all I do is fetching first_name value from $member object.

How can I apply the same thing for my Form::date?

{{Form::date('dob', '\Carbon\Carbon::now()')}}

I have tried adding parameter similar to ::text but it does not work. Also the database value uses format of YYYY-MM-DD, whereas Form::date displays YYYY/MM/DD

我认为您应该尝试在无碳的情况下使用单引号

{{Form::date('dob', \Carbon\Carbon::now())}}

You can try do the following in the view

{{Form::date('dob', $member->date->format('Y-m-d'), ['class' => 'form-control'])}}

If you want you can add the date properties from your database to protected $dates . This will parse your dates to a carbon instance when you try to retrieve it.

model

protected $dates = ['date_column', 'deleted_at'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM