不断出错:implode():更新数据时传递了无效的参数 [英] Keep getting error: implode(): Invalid arguments passed when updating data

查看:114
本文介绍了不断出错:implode():更新数据时传递了无效的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试将某些内容更新到我的数据时,我都会不断收到此错误.上次并没有发生很多,但是在放置了新的更新功能之后,错误不断弹出,由于某种原因,即使我是在旧功能上进行更新,它也会指向我输入的新功能.

控制器:

//update for user
    public function edit($id){
        $object = user::find($id);

        return view('edit', compact('object'));

    }

    public function update(Request $request, $id){
        $object = user::find($id);
        $object->Name = $request->input('Name');
        $object->update();

        return redirect('/home');
    }


    //update for Schools table
    public function edit1($id){
      $object2 = school::find($id);
       return view('edit1', compact('object2'));

    }
    public function update1(Request $request, $id){
        $object2 = school::find($id);
        $test = array();
    $test['School'] = implode(' , ', $request->School);
    $test['SDate'] = implode(' , ', $request->SDate);
    $test['EDate'] = implode(' , ', $request->EDate);
        $object2->update($test);
        return redirect('/home');
    }

    //error start here after putting this whole thing in. (I tried putting it into another separate controller but the error still continues)
            public function edit2($id){
      $object3 = hobby::find($id);
       return view('edit2', compact('object3'));

    }
    public function update2(Request $request, $id){
        $object3 = hobby::find($id);
    $test2 = array();
    $test2['computer_game'] = implode(' , ', $request->computer_game);
    $test2['reading_book'] = implode(' , ', $request->reading_book);
        $object3->update($test2);
        return redirect('/home');
    }

即使我尝试更新用户或学校数据,错误也会突出显示此部分

$test2['computer_game'] = implode(' , ', $request->computer_game);

它说

:implode():传递了无效的参数

我没有任何兴趣更新兴趣爱好数据,但是错误始终将其指向兴趣爱好内爆部分.

有可能我只能在一次爆破功能上使用一次更新吗?预先感谢

edit2.blade.php(爱好的编辑页面,如图所示,它是一个数组)

  <form class="form-horizontal" method="post" action="{{ url('/user/show/'.$object3->id) }}">
              {{ method_field('PUT')  }}
              {{ csrf_field() }}
     <table class="table table-bordered table-hover" id="tab_logic">
            <thead>
              <tr >
                            <th class="text-center">
                  #
                </th>
                <th class="text-center">
                  Sports:
                </th>
                <th class="text-center">
                  Books read:
                </th>
                              </tr>
            </thead>
            <tbody>
              <tr id='addr0'>
                <td>
                1
                </td>
                <td>
                <input type="text" name='computer_game[]' class="form-control"/>
                </td>
                <td>
                <input type="text" name='reading_book[]' class="form-control"/>
                </td>
                              </tr>
                        <tr id='addr1'></tr>
            </tbody>
          </table>
 <input type="submit" class="btn btn-primary" value="Save">

解决方案

简单尝试以下操作:

$test2['computer_game'] = implode(' , ', (array)$request->computer_game);

如果尚未将$request->computer_game转换为数组,则会将其转换为数组.

I keep on getting this error whenever I try to update something into my data. It didn't happen a lot the last time but after putting the new update function, the error keep popping out and for some reason it points back to the new function that I had entered even though I am updating at the old function.

Controller:

//update for user
    public function edit($id){
        $object = user::find($id);

        return view('edit', compact('object'));

    }

    public function update(Request $request, $id){
        $object = user::find($id);
        $object->Name = $request->input('Name');
        $object->update();

        return redirect('/home');
    }


    //update for Schools table
    public function edit1($id){
      $object2 = school::find($id);
       return view('edit1', compact('object2'));

    }
    public function update1(Request $request, $id){
        $object2 = school::find($id);
        $test = array();
    $test['School'] = implode(' , ', $request->School);
    $test['SDate'] = implode(' , ', $request->SDate);
    $test['EDate'] = implode(' , ', $request->EDate);
        $object2->update($test);
        return redirect('/home');
    }

    //error start here after putting this whole thing in. (I tried putting it into another separate controller but the error still continues)
            public function edit2($id){
      $object3 = hobby::find($id);
       return view('edit2', compact('object3'));

    }
    public function update2(Request $request, $id){
        $object3 = hobby::find($id);
    $test2 = array();
    $test2['computer_game'] = implode(' , ', $request->computer_game);
    $test2['reading_book'] = implode(' , ', $request->reading_book);
        $object3->update($test2);
        return redirect('/home');
    }

Error is highlighting this part even though when I try to update user or school data

$test2['computer_game'] = implode(' , ', $request->computer_game);

And it says

:implode(): Invalid arguments passed

I have no issue updating the hobby data but it the error keep pointing it back to the hobby implode part.

Is it possible I could only use update once on an implode function? Thanks in advance

edit2.blade.php (edit page for hobby, as shown it is an array)

  <form class="form-horizontal" method="post" action="{{ url('/user/show/'.$object3->id) }}">
              {{ method_field('PUT')  }}
              {{ csrf_field() }}
     <table class="table table-bordered table-hover" id="tab_logic">
            <thead>
              <tr >
                            <th class="text-center">
                  #
                </th>
                <th class="text-center">
                  Sports:
                </th>
                <th class="text-center">
                  Books read:
                </th>
                              </tr>
            </thead>
            <tbody>
              <tr id='addr0'>
                <td>
                1
                </td>
                <td>
                <input type="text" name='computer_game[]' class="form-control"/>
                </td>
                <td>
                <input type="text" name='reading_book[]' class="form-control"/>
                </td>
                              </tr>
                        <tr id='addr1'></tr>
            </tbody>
          </table>
 <input type="submit" class="btn btn-primary" value="Save">

解决方案

Just simple try the following:

$test2['computer_game'] = implode(' , ', (array)$request->computer_game);

This will convert $request->computer_game in to an array if it is not already.

这篇关于不断出错:implode():更新数据时传递了无效的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆