duanbi7204 2016-02-04 08:17
浏览 21
已采纳

将所有值(由表单接收)存储在数据库中,除了2以便在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)

  • 写回答

1条回答 默认 最新

  • douyan8267 2016-02-04 08:26
    关注

    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";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题