narwen's avatar

Error using https://github.com/Maatwebsite/Laravel-Excel

I am using https://github.com/Maatwebsite/Laravel-Excel this package. And when I upload my file the and dd(result) is

    CellCollection {#842 ▼
             #title: null
            #items: array:4 [▼
             "news_title" => "7th AGM of ADBL today; endorsing 47% cash             dividend"
             "desc" => "The AGM will be endorsing 47% percent cash dividend to its shareholders from the net profit it earned in last fiscal year 2070/71. "
                "link" => "http://www.sharesansar.com/viewnews.php?id=26224&cat=news"
             "stock_code" => "LBL"
            ]
        }

So, here the #items contains my data whereas I don't know why is #title being output. And when I try to store my data, I am getting Integrity Violation Error due to this #title? So, is there a solution?

Here is my code to store the data

    public function excelNews()
        {
            if (Input::hasFile('file')) {
                $file = Input::file('file');
                Excel::load($file, function($reader) {
                    $reader->setDateFormat('j/n/Y H:i:s');
                    $results = $reader->get();
                     foreach ($results as $result)
                    {
                            dd($result); // for testing
                $news = new StockNews;
                $news->title = $result->news_title;
                $news->desc = $result->desc;
                $news->save()
                    }
                
             });
        }
            Flash::success('News has been successfully updated');
            return redirect::back();
        }
0 likes
1 reply
narwen's avatar

It was a strange error and haven't figured it out yet. But when I do like something like this

    if(!empty($result->title))
    {
        //Save the data
    }

It works fine!

Please or to participate in this conversation.