Reputation: 85
What I'm trying to do is a basic validation after a form is submitted, I am using vuejs alongside with laravel but in the blade itself there is a form that gets submitted.
Upon submission we go into the controller the validate the stuff user sent, NOW here is the problem when one of the inputs are empty, then the page goes in a redirect loop, resulting of ERR_TOO_MANY_REDIRECTS
.
the blade file that we need to be returned is "joborder/create" and we get to send to store function to check the validation. I had to use create as a post so I overwrite the default from the resource.
I have no idea what's causing the loop. I'm using laravel 5.2
Any help would highly appreciable.
Route :
Route::resource('joborder' ,'JoborderController');
Route::POST('joborder/create','JoborderController@create');
Blade File :
<div class="pubdiv col-md-12" >
{!! Form::open(['action' => 'JoborderController@store','method' =>'POST']) !!}
{{ csrf_field() }}
<h3>basicinput</h3>
<div class="row">
<div class="col-sm-3 col-xs-6 pull-right">
<div class="form-group">
{!! Form::label('company' , 'ComapnyName')!!}
<input type="text" class="form-control " name="owner" value="{{$company_owner->name}}" disabled>
</div>
<div class="form-group ">
<input type='submit' value="finish" name="submit" style="margin-top:4px" class="col-md-12 btn btn-t-primary btn-theme">
</div>
{!! Form::close() !!} <!-- end form post a job -->
Controller :
if(session()->get('role_active') != 1){
return redirect('thehood')->with('error','NO CAN DO');
}else{
$this->validate($request, [
'alljobs_id' => 'required',
'joborder_id' => 'required',
'notes'=>'required',
'state' =>'required',
'city' => 'required',
'type' => 'required',
'salary' => 'required',
'created_at' => 'required'
]);
// after moving these remove the keys from request
$alljobs_id = $request->alljobs_id;
$joborder_id = $request->joborder_id;
$request->request->remove('joborder_id');
$request->request->remove('alljobs_id');
$check_prof + $check_prof_custom = 9;
if(($check_prof + $check_prof_custom < 5 ) || ($check_behv + $check_behv_custom < 5 )){
return redirect('joborder/create')->with('error','5 input is required!');
}
}
UPDATE: I've noticed I have both post and get method which was wrong so I made a new function called creates with (s)
| | POST | joborder/crawltitle | | App\Http\Controllers\JoborderController@crawltitle | web |
| | GET|HEAD | joborder/create | joborder.create | App\Http\Controllers\JoborderController@create | web |
| | POST | joborder/creates | | App\Http\Controllers\JoborderController@creates | web |
| | POST | joborder/moveAttrib
the new function now if the validation fails it redirects me to 404 page but my address bar is /joborder/creates/
Upvotes: 0
Views: 518
Reputation: 517
Your problem is that you have a method GET on your resource
Route::resource('joborder' ,'JoborderController');
When you call the redirect function redirect('joborder/create')
you are redirecting to the resource above with the argument create
.
Try redirect('joborder')
instead.
Hope it helps.
Upvotes: 1