0

I always send data from view like this ->with(array('message'=>'there is an error ')), and it works.

I want to allow the customer to edit some information, so when he/she clicks on the the edit like, this function in a controller is being executed:

public function edit($id)
    {
        $waitingTimes = WaitingTimes::find($id);
        return View::make('waitingtimes.edit')->with(array(
            'verticalMenu' => 'none',
            'verticalMenuTab' => 'none',
            'data' => $waitingTimes
        ));
    }

So later in the view, I should be able to say this:

$data->startTime, $data->endTime, $data->id, $data->restaurant_id

but every time I do that, I got $data->startTime printed on the browser, but I should have got the value of the startTime attribute.

This is my view:

<div class="oneInfo">
            {{ Form::text('startTime', '', array('class' => 'time ui-timepicker-input', 'id' => 'startTime', 'autocomplete' => 'off'))}}
            <span class="errorMessage">
                <?php
                echo $errors->first('startTime');
                ?>
            </span>
        </div>

The view has an input text and I want that input text to be filled with the data that has been sent from the controller.

how could I do that please?

5
  • From the looks of things, you could pull this off by using form model binding. There is a free Laracast that deals with the subject. Commented Jun 24, 2014 at 7:50
  • @Jeemusu that sounds interesting, let me try it Commented Jun 24, 2014 at 7:54
  • @Jeemusu and how to fill the inputs ? will they be filled automatically? in my case they are not Commented Jun 24, 2014 at 7:59
  • They should be filled automatically yes, I noticed on your code however you are setting the values to an empty string via the second parameter of the Form::text method. Commented Jun 24, 2014 at 8:01
  • @Jeemusu yes you right, when I did this $data->startTime in the second parameter, I got the data filled, many thanks type an answer to accept it please Commented Jun 24, 2014 at 8:03

1 Answer 1

1

The Form::text() method's second parameter allows you to pass it the value to be assigned to the input element. Your form input declarations are currently setting the value of the inputs to an empty string.

The best way to handle this would be to replace your empty string with $value=null.

{{ Form::text('startTime', $value=null, array('class' => 'time ui-timepicker-input', 'id' => 'startTime', 'autocomplete' => 'off'))}}

This will automatically replace the value with your models data or the data input by the user (should validation fail and you redirect back to the form).

From the looks of things, you could also make things a bit easier for yourself by using form model binding to bind the WaitingTimes model to your form.

Sign up to request clarification or add additional context in comments.

5 Comments

Just one thing please, when I submit the form, I got MethodNotAllowedHttpExcpetion is that related to the Form Model Binding that you told me about?
Can't be sure without more information but it sounds like it could be your route declaration? have you created a post route?
in the update method, I guess, I need a put method not post right? so I declared a put request in my form like this: {{Form::model($data, array( 'route' => array('waitingtimes.update', $data->id) , 'class' => 'mainInformationContrainer', 'method', => 'put' ))}} have I forgotten somthing?
If your update method responds to a put request then you will need a put. You may also need to designate the route it is submitting the data to. 'route' => array('foo.bar', $data->id)
I already have that design in my form. Okay no problem, I will check the problem myself, thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.