Laravel 5: The Eloquent Model for Working Hours

I am trying to implement working hours for my users. So, I have a table of main users and a table user_business_hours, which looks like this:

| id | user_id | weekDay | start_time | end_time | created_at | updated_at |
|---:|---------|--------:|------------|----------|------------|------------|
| 1  | 10      | 1       | 10:00:00   | 12:00:00 | ...        | ...        |
| 2  | 10      | 1       | 13:30:00   | 18:00:00 | ...        | ...        |

Now the problem: How to request this model and configure Form :: model () / input, will this laravel automatically fill in unnecessary inputs with the provided values ​​that update the hours of operation for a particular user?

I was thinking about this input organization:

| ...     | Work From | Work From | add new row |
|---------|-----------|-----------| ----------- |
| Monday  | 10:00:00  | 12:00:00  | +           |
| Monday  | 13:30:00  | 18:00:00  | +           |
| Tuesday | <input>   | <input>   | +           |

Please note that the user can configure as many times each day as he wants (add a new row column).

Thanks for your ideas.

+4
source share
1 answer

, :

{!! Form::model($model->toArray(), []) !!}
    {!! Form::text('business_hour[0][from]', null, []) !!}
    {!! Form::text('business_hour[0][to]', null, []) !!}
    {!! Form::text('business_hour[1][from]', null, []) !!}
    {!! Form::text('business_hour[2][to]', null, []) !!}
{!! Form::close() !!}

- array_get() transformKey().

protected function transformKey($key)
{
    return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $key);
}

, , , - :

{
    'key' => [
        'hallo' => 'welt'
    ]
}
0

Source: https://habr.com/ru/post/1607150/


All Articles