Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store all values (received by form) in database except 2 for modification in laravel

Tags:

php

laravel

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 using fill() 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.

enter image description here

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 use fill(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)

like image 534
user3201500 Avatar asked Nov 27 '25 04:11

user3201500


1 Answers

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";
like image 161
paranoid Avatar answered Nov 28 '25 19:11

paranoid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!