php - Store all values (received by form) in database except 2 for modification in laravel
Get the solution ↓↓↓I am new in Laravel, i am trying to send all the values of a form to a database along with some other/modified values by usingfill()
in laravel 5.1.
here is how my controller looks like
public function store(Request $request)
{
$pages = new Pages; //i have a model with name Pages
$pages->fill(Input::all());
$pages->save();
return "data saved successfully";
}
Whenever i want to fill data into the table i get these values.
But before sending the data into database i want to mention some other attributes as well like$userid
,change the datetime format to timestamp
and then i want to send the data to database.
I want to usefill(Input::all());
method because if i need to add more field in the form, then i wont have to modify my controller or model.
Any suggestion will be helpful.Or any other best practice will also work. Thank you! (in advance)
Answer
Solution:
You can use eloquent
public function store(Request $request)
{
$request['user_id']='your id';
Pages::create($request->all());
return "data saved successfully";
}
If not eloquent
try this
$pages = new Pages; //i have a model with name Pages
$request['user_id']='your id';
$pages->fill(Input::all());
$pages->save();
return "data saved successfully";
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: ftp_put(): can't open that file: no such file or directory
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.