Return redirect with $errors in an if-statement












0















I think its a simple question to answer for you guys. I just want to redirect to the given page when serialnumber has an error but it tells me that $errors is undefined so i thought i have to add something like this:



use IlluminateHttpRequest;


but i coulndt find something like that what did i miss can anyone help me? :)



if ($errors->has('serialnumber')){

return redirect()->route('borrow.index')
->with('warning','Test');

}


EDIT:



I would like that with no matter what error you get rejected with a message on the page I have specified. With a single message that I define myself. The link in the comments wont help me out......










share|improve this question

























  • possible duplicate stackoverflow.com/questions/19838978/…. Take a look here

    – Dearwolves
    Nov 19 '18 at 14:07











  • Wont help me out....

    – Devi
    Nov 19 '18 at 14:21






  • 1





    where the $errors coming from?

    – Muhammad Rizwan
    Nov 19 '18 at 14:26











  • From my view so i thought i could use it in the controller. @if($errors->any()) <h4>{{$errors->first()}}</h4> @endif

    – Devi
    Nov 19 '18 at 14:27













  • @Devi no you cant. as errors. how ever you can use a validator with defined error response

    – Dearwolves
    Nov 19 '18 at 14:29
















0















I think its a simple question to answer for you guys. I just want to redirect to the given page when serialnumber has an error but it tells me that $errors is undefined so i thought i have to add something like this:



use IlluminateHttpRequest;


but i coulndt find something like that what did i miss can anyone help me? :)



if ($errors->has('serialnumber')){

return redirect()->route('borrow.index')
->with('warning','Test');

}


EDIT:



I would like that with no matter what error you get rejected with a message on the page I have specified. With a single message that I define myself. The link in the comments wont help me out......










share|improve this question

























  • possible duplicate stackoverflow.com/questions/19838978/…. Take a look here

    – Dearwolves
    Nov 19 '18 at 14:07











  • Wont help me out....

    – Devi
    Nov 19 '18 at 14:21






  • 1





    where the $errors coming from?

    – Muhammad Rizwan
    Nov 19 '18 at 14:26











  • From my view so i thought i could use it in the controller. @if($errors->any()) <h4>{{$errors->first()}}</h4> @endif

    – Devi
    Nov 19 '18 at 14:27













  • @Devi no you cant. as errors. how ever you can use a validator with defined error response

    – Dearwolves
    Nov 19 '18 at 14:29














0












0








0








I think its a simple question to answer for you guys. I just want to redirect to the given page when serialnumber has an error but it tells me that $errors is undefined so i thought i have to add something like this:



use IlluminateHttpRequest;


but i coulndt find something like that what did i miss can anyone help me? :)



if ($errors->has('serialnumber')){

return redirect()->route('borrow.index')
->with('warning','Test');

}


EDIT:



I would like that with no matter what error you get rejected with a message on the page I have specified. With a single message that I define myself. The link in the comments wont help me out......










share|improve this question
















I think its a simple question to answer for you guys. I just want to redirect to the given page when serialnumber has an error but it tells me that $errors is undefined so i thought i have to add something like this:



use IlluminateHttpRequest;


but i coulndt find something like that what did i miss can anyone help me? :)



if ($errors->has('serialnumber')){

return redirect()->route('borrow.index')
->with('warning','Test');

}


EDIT:



I would like that with no matter what error you get rejected with a message on the page I have specified. With a single message that I define myself. The link in the comments wont help me out......







php laravel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 14:21







Devi

















asked Nov 19 '18 at 13:59









DeviDevi

398




398













  • possible duplicate stackoverflow.com/questions/19838978/…. Take a look here

    – Dearwolves
    Nov 19 '18 at 14:07











  • Wont help me out....

    – Devi
    Nov 19 '18 at 14:21






  • 1





    where the $errors coming from?

    – Muhammad Rizwan
    Nov 19 '18 at 14:26











  • From my view so i thought i could use it in the controller. @if($errors->any()) <h4>{{$errors->first()}}</h4> @endif

    – Devi
    Nov 19 '18 at 14:27













  • @Devi no you cant. as errors. how ever you can use a validator with defined error response

    – Dearwolves
    Nov 19 '18 at 14:29



















  • possible duplicate stackoverflow.com/questions/19838978/…. Take a look here

    – Dearwolves
    Nov 19 '18 at 14:07











  • Wont help me out....

    – Devi
    Nov 19 '18 at 14:21






  • 1





    where the $errors coming from?

    – Muhammad Rizwan
    Nov 19 '18 at 14:26











  • From my view so i thought i could use it in the controller. @if($errors->any()) <h4>{{$errors->first()}}</h4> @endif

    – Devi
    Nov 19 '18 at 14:27













  • @Devi no you cant. as errors. how ever you can use a validator with defined error response

    – Dearwolves
    Nov 19 '18 at 14:29

















possible duplicate stackoverflow.com/questions/19838978/…. Take a look here

– Dearwolves
Nov 19 '18 at 14:07





possible duplicate stackoverflow.com/questions/19838978/…. Take a look here

– Dearwolves
Nov 19 '18 at 14:07













Wont help me out....

– Devi
Nov 19 '18 at 14:21





Wont help me out....

– Devi
Nov 19 '18 at 14:21




1




1





where the $errors coming from?

– Muhammad Rizwan
Nov 19 '18 at 14:26





where the $errors coming from?

– Muhammad Rizwan
Nov 19 '18 at 14:26













From my view so i thought i could use it in the controller. @if($errors->any()) <h4>{{$errors->first()}}</h4> @endif

– Devi
Nov 19 '18 at 14:27







From my view so i thought i could use it in the controller. @if($errors->any()) <h4>{{$errors->first()}}</h4> @endif

– Devi
Nov 19 '18 at 14:27















@Devi no you cant. as errors. how ever you can use a validator with defined error response

– Dearwolves
Nov 19 '18 at 14:29





@Devi no you cant. as errors. how ever you can use a validator with defined error response

– Dearwolves
Nov 19 '18 at 14:29












2 Answers
2






active

oldest

votes


















0














According to Laravel's documentation, The $errors variable is bound to the view by the IlluminateViewMiddlewareShareErrorsFromSession middleware, which is provided by the web middleware group.



As you shouldn't do redirects from your views, just check your condition inside your controller instead of your view.






share|improve this answer
























  • I dont know how to validate errors thats why i questioned here and posted my code cause everything what i found couldnt help me. Thanks for the answer anyway then the error makes sense but i dont know how to do it like i want to do it

    – Devi
    Nov 19 '18 at 14:36



















0














If you want to redirect with a specific error you can use you can use this from the Laravel documentation:



 $validator = Validator::make($request->all(), [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);


then get the errors :



$errors = $validator->errors();


or redirect when validator fails :



if ($validator->fails()) {
// your redirect here...
}





share|improve this answer
























  • laravel.com/docs/5.7/validation#manually-creating-validators

    – Dearwolves
    Nov 19 '18 at 14:35











  • I got this: Method IlluminateDatabaseQueryBuilder::fails does not exist. And yeah i have already this in my code: use IlluminateSupportFacadesValidator;

    – Devi
    Nov 19 '18 at 14:42











  • Can you help me please? ):

    – Devi
    Nov 19 '18 at 15:04











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376260%2freturn-redirect-with-errors-in-an-if-statement%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














According to Laravel's documentation, The $errors variable is bound to the view by the IlluminateViewMiddlewareShareErrorsFromSession middleware, which is provided by the web middleware group.



As you shouldn't do redirects from your views, just check your condition inside your controller instead of your view.






share|improve this answer
























  • I dont know how to validate errors thats why i questioned here and posted my code cause everything what i found couldnt help me. Thanks for the answer anyway then the error makes sense but i dont know how to do it like i want to do it

    – Devi
    Nov 19 '18 at 14:36
















0














According to Laravel's documentation, The $errors variable is bound to the view by the IlluminateViewMiddlewareShareErrorsFromSession middleware, which is provided by the web middleware group.



As you shouldn't do redirects from your views, just check your condition inside your controller instead of your view.






share|improve this answer
























  • I dont know how to validate errors thats why i questioned here and posted my code cause everything what i found couldnt help me. Thanks for the answer anyway then the error makes sense but i dont know how to do it like i want to do it

    – Devi
    Nov 19 '18 at 14:36














0












0








0







According to Laravel's documentation, The $errors variable is bound to the view by the IlluminateViewMiddlewareShareErrorsFromSession middleware, which is provided by the web middleware group.



As you shouldn't do redirects from your views, just check your condition inside your controller instead of your view.






share|improve this answer













According to Laravel's documentation, The $errors variable is bound to the view by the IlluminateViewMiddlewareShareErrorsFromSession middleware, which is provided by the web middleware group.



As you shouldn't do redirects from your views, just check your condition inside your controller instead of your view.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 14:31









PourbahramiPourbahrami

1648




1648













  • I dont know how to validate errors thats why i questioned here and posted my code cause everything what i found couldnt help me. Thanks for the answer anyway then the error makes sense but i dont know how to do it like i want to do it

    – Devi
    Nov 19 '18 at 14:36



















  • I dont know how to validate errors thats why i questioned here and posted my code cause everything what i found couldnt help me. Thanks for the answer anyway then the error makes sense but i dont know how to do it like i want to do it

    – Devi
    Nov 19 '18 at 14:36

















I dont know how to validate errors thats why i questioned here and posted my code cause everything what i found couldnt help me. Thanks for the answer anyway then the error makes sense but i dont know how to do it like i want to do it

– Devi
Nov 19 '18 at 14:36





I dont know how to validate errors thats why i questioned here and posted my code cause everything what i found couldnt help me. Thanks for the answer anyway then the error makes sense but i dont know how to do it like i want to do it

– Devi
Nov 19 '18 at 14:36













0














If you want to redirect with a specific error you can use you can use this from the Laravel documentation:



 $validator = Validator::make($request->all(), [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);


then get the errors :



$errors = $validator->errors();


or redirect when validator fails :



if ($validator->fails()) {
// your redirect here...
}





share|improve this answer
























  • laravel.com/docs/5.7/validation#manually-creating-validators

    – Dearwolves
    Nov 19 '18 at 14:35











  • I got this: Method IlluminateDatabaseQueryBuilder::fails does not exist. And yeah i have already this in my code: use IlluminateSupportFacadesValidator;

    – Devi
    Nov 19 '18 at 14:42











  • Can you help me please? ):

    – Devi
    Nov 19 '18 at 15:04
















0














If you want to redirect with a specific error you can use you can use this from the Laravel documentation:



 $validator = Validator::make($request->all(), [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);


then get the errors :



$errors = $validator->errors();


or redirect when validator fails :



if ($validator->fails()) {
// your redirect here...
}





share|improve this answer
























  • laravel.com/docs/5.7/validation#manually-creating-validators

    – Dearwolves
    Nov 19 '18 at 14:35











  • I got this: Method IlluminateDatabaseQueryBuilder::fails does not exist. And yeah i have already this in my code: use IlluminateSupportFacadesValidator;

    – Devi
    Nov 19 '18 at 14:42











  • Can you help me please? ):

    – Devi
    Nov 19 '18 at 15:04














0












0








0







If you want to redirect with a specific error you can use you can use this from the Laravel documentation:



 $validator = Validator::make($request->all(), [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);


then get the errors :



$errors = $validator->errors();


or redirect when validator fails :



if ($validator->fails()) {
// your redirect here...
}





share|improve this answer













If you want to redirect with a specific error you can use you can use this from the Laravel documentation:



 $validator = Validator::make($request->all(), [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);


then get the errors :



$errors = $validator->errors();


or redirect when validator fails :



if ($validator->fails()) {
// your redirect here...
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 14:35









DearwolvesDearwolves

315213




315213













  • laravel.com/docs/5.7/validation#manually-creating-validators

    – Dearwolves
    Nov 19 '18 at 14:35











  • I got this: Method IlluminateDatabaseQueryBuilder::fails does not exist. And yeah i have already this in my code: use IlluminateSupportFacadesValidator;

    – Devi
    Nov 19 '18 at 14:42











  • Can you help me please? ):

    – Devi
    Nov 19 '18 at 15:04



















  • laravel.com/docs/5.7/validation#manually-creating-validators

    – Dearwolves
    Nov 19 '18 at 14:35











  • I got this: Method IlluminateDatabaseQueryBuilder::fails does not exist. And yeah i have already this in my code: use IlluminateSupportFacadesValidator;

    – Devi
    Nov 19 '18 at 14:42











  • Can you help me please? ):

    – Devi
    Nov 19 '18 at 15:04

















laravel.com/docs/5.7/validation#manually-creating-validators

– Dearwolves
Nov 19 '18 at 14:35





laravel.com/docs/5.7/validation#manually-creating-validators

– Dearwolves
Nov 19 '18 at 14:35













I got this: Method IlluminateDatabaseQueryBuilder::fails does not exist. And yeah i have already this in my code: use IlluminateSupportFacadesValidator;

– Devi
Nov 19 '18 at 14:42





I got this: Method IlluminateDatabaseQueryBuilder::fails does not exist. And yeah i have already this in my code: use IlluminateSupportFacadesValidator;

– Devi
Nov 19 '18 at 14:42













Can you help me please? ):

– Devi
Nov 19 '18 at 15:04





Can you help me please? ):

– Devi
Nov 19 '18 at 15:04


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376260%2freturn-redirect-with-errors-in-an-if-statement%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)