Reputation: 2275
In reference to this stockoverflow question
I created a new request with php artisan make:request ApplicationFormRequest
public function rules() {
return ['first_name' => 'required']
}
I also have a controller as such,
public function store(ApplicationFormRequest $request){
//empty
}
I have seen an example on stackoverflow with
return Redirect::to('/')->withInput();
they seem to put their validation together with the controller, but I am not sure how to go about it this way.
Where would I put that? How do I retrieve old input even with validation fail?
EDIT you see my controller is empty, it validate automatically with the rule i set at ApplicationFormRequest. when it failed it automatically redirect to the view where the input is submitted with error
@foreach ($errors->all() as $error)
<li class="alert label">{{$error}}</li>
@endforeach
but I am unable to fill the input with the input user just submitted, I try to do
<input type="text" value="{{ old('first_name') }}" \>
but this give me error Use of undefined constant
Upvotes: 1
Views: 2854
Reputation: 5016
In Laravel 5.2, if the view forms are not being populated with old data sent back from a custom Request
class, do the following:
1) Place all routes related to the request in the route group, which should be included in 5.2
Route::group(['middleware' => ['web']], function () {
// routes here
});
2) Run php artisan key:generate
EDIT: This fix may not be applicable for versions other than 5.2.
Credits:
Laravel - Session store not set on request
No supported encrypter found. The cipher and / or key length are invalid.
Upvotes: 1
Reputation: 9044
You can do this by checking if a value is available in the POST or GET array first. If it is available in the POST or GET array, then echo it in the value
attribute of the input.
Your input field would look something like this:
<input type="text" name="first_name" value="if (Input::has('first_name')){ @echo Input::get('first_name');}" \>
Upvotes: 0
Reputation: 633
as the error say use of undefined constant. Your errors variable is not in the scope of view. check what you are doing wrong.
use Docs for further reading.
Upvotes: 0