1

Is there a way to do something like this in the controller?

$request->input(['new_field_name' => 'new_val']);

I've googled a lot, but the only thing I've found was related to Laravel's 4.x formatInput method, which has been removed from the 5.x

I need to inject a specific field in the $request when the request has passed the validation, then save the new record in the db.

Any clue? Thanks to everyone!

4
  • Did you try it?? Commented Aug 1, 2016 at 15:37
  • @RiggsFolly yeah, but it doesn't work.. still no errors though... Commented Aug 1, 2016 at 15:41
  • 1
    Try to do $inputs = $request->all(); then $inputs['new_field_name'] = 'new_val' ! Commented Aug 1, 2016 at 15:44
  • @Maraboc Mmmh! This should solve the problem, I'll try this when I'll be back home, then I'll let you know. Thanks! Commented Aug 1, 2016 at 15:49

1 Answer 1

2

Method merge is the right tool for this.

Example of a typical use case (saving a slug given a title):

$request->merge(['slug' => Str::slug($request->title)]);
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.