laravel array to string conversion (implode doesn't work) -


hi guys i'm having trouble update function in laravel (i'm not using relationship (hasmany belongto ) laravel's uses since it's learning project , didn't work used sql statement, error on $menu_id line

    public function update($session,$date, request $request) {  /*    * */ //fetch new plats edited     $titles = $request->input('plats');      //        fetch menu id      $menu_id=$this->menu->menuid($session,$date);        //$id=implode("",$menu_id);      //dd($id);     foreach ($titles $ds) {        $plats_id=$this->menu->getplatsid($ds);          db::update("update menu_items                                 set id_plats='$plats_id'                                 id_menu= '".$menu_id."'  ");         } 

i tried implode function gave me stdclass error thank

  public function menuid($session,$date){     return db::select(db::raw("select id                               menu                               session '".$session."' ,  date ='".$date."'"));  } 

if using laravel's db wrapper, select query return collection(illuminate\support\collection) class. hence 'object' error.

change

from:

$menu_id=$this->menu->menuid($session,$date);

to:

$menu_id=$this->menu->menuid($session,$date)->implode('id');

the implode function of collection class mimics of php.

read more on collections here

the small quirks of laravel seem troublesome @ first, given enough experience, speed development projects.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo