Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 850 Bytes

How to “artificially” add values to Request array.md

File metadata and controls

32 lines (26 loc) · 850 Bytes
Title Tip-number Tip-username Tip-username-profile Tip-description
How to “artificially” add values to Request array
7
Vijayanand
How to “artificially” add values to Request array.

We often come in an situation that a store() or update() method with Request parameter need to add additional values to a request before calling Eloquent function.

Here is the normal code without additional values.

function store(Request $request) 
{
  // some additional code goes here 
  User::create($request->all());
}

This is how we can change the code to get additional values.

function store(Request $request) 
{
  // some additional code goes here 
  $mark = 100; // some logic that decies your mark
  $request->request->add(['mark' => $mark]);
  User::create($request->all());
}