1

I'm trying to pull data from a table, populate a select input with that data, then post that information (and other info) to another table. When the view is rendered, it correctly populates the select with the data required, however when I submit the form, I receive an undefined variable error.

Undefined variable: secondarygenre

View

{{ Form::select('genre', $secondarygenre, null, array('class' => 'form-control', 'id' => 'genre')) }}

Controller

//Data is passed to the form in the view
public function addSubmission() {

    $secondarygenre = Genre::lists('friendlyName', 'id');

    return View::make('add')
        ->with('secondarygenre', $secondarygenre);
}

//Form is submitted
public function successfulSubmission() {

$track = new Track();
$track->genre_id = Input::get('genre');
$track->save();

}

If it's populating the select input with data, I know that it's the variable is not undefined.

I apologise if I've missed something, this is my first project with Laravel (or any MVC framework).

Any help would be greatly appreciated!

1 Answer 1

2

In the post, you have to also return the view with the variable, it looks like you're only doing that with the get, but you need to use ->with('secondarygenre', $sg) once for each type of request.

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

Comments

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.