Home > Backend Development > PHP Tutorial > php laravel add $request

php laravel add $request

WBOY
Release: 2016-09-14 09:23:55
Original
965 people have browsed it

php code

<code>public function store(Request $request)
{
    
    $name = $request->get('namne', 0);
    
    $newname = $request->set('newname', 0);  
    
    // 前端提交 `data` 里面没有 `newname` 这个字段,
    // 需要在这里处理一些业务逻辑,新增一个字段然后到下面一起保存起来
    
    // $request->newname = 'newname' 
    // 尝试过这样好像没写进入
    
    //想在保存数据前,添加一个字段 ;
    // $request->all()->'新的字段名称' = '我是新加的字段值';
    // 这个时候 $request->all() 会多出来上面新添加的字段
    
    $post = Post::create($request->all());

}</code>
Copy after login

vue code

<code>this.$http.post('/backend/post', data).then(function(result) {

})</code>
Copy after login

Master, does anyone know how to add a field in $request->all() before saving?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template