Laravel 4, ->withInput(); = Undefined offset: 0

前端 未结 1 617
离开以前
离开以前 2021-02-04 12:04

I have had a lengthy search both here and the Laravel forums, but i can\'t find an answer to this problem. ->withInput() coughs up an Undefined offset: 0

1条回答
  •  抹茶落季
    2021-02-04 12:39

    withInput() doesn't work the way you think it does. It's only a function of Redirect, not View.

    Calling withInput($data) on View has a completely different effect; it passes the following key value pair to your view: 'input' => $data (you get an error because you're not passing any data to the function)

    To get the effect that you want, call Input::flash() before making your view, instead of calling withInput(). This should allow you to use the Input::old() function in your view to access the data.

    Alternatively, you could simply pass Input::all() to your view, and use the input[] array in your view:

    View::make(...)->withInput(Input::all());
    

    which is translated to

    View::make(...)->with('input', Input::all());
    

    As for your comment, I recommend doing it like so:

    $position_options = DB::table('jposition')->lists('friendly','id');
    $category_options = DB::table('jcategory')->lists('friendly','id');
    $location_options = DB::table('jlocation')->lists('friendly','id');
    $category = Input::get('category');
    $location = Input::get('location');
    $type = Input:: get('type'); 
    
    $data = compact('position_options', 'category_options', 'location_options', 'category', 'type', 'location');
    
    return View::make('jobsearch.search', $data);
    

    0 讨论(0)
提交回复
热议问题