lundi 14 mars 2016

laravel excel redirect inside Excel:: after validating duplicates

Hi I'm using laravel and im stuck with this problem. I want to validate records imported in an excel file if duplicates exists in the database. if duplicate is true it will still save the other records but skip those with duplicates. After saving all records, duplicates must be printed in a page warning the user that these records exists in the database and was not uploaded as a rule. Everything works fine except that I can't redirect it to a page. I'm hoping for any help from laravel experts. I am using laravel 5.2. Thanks guys. Here's my code:

Excel::filter('chunk')->load($fullpath)->chunk(10000, function ($results)
             // Excel::filter('chunk')->load($fullpath)->chunk(5000, function($results)
            {
                $counter = 0;
                foreach ($results as $row) {
                    $duplicates =DB::table('tblhere')->where('field1', '=', $row->field1)->get();

                    if (count($duplicates) == 0 ) {
                        uploader::create
                        ([
                            'field1' => $row->field1,

                        ]);
                    }
                    else {
                        $items = array();
                        foreach ($duplicates as $duplicate) {
                            $items[$counter] = $duplicate->id;
                            $counter=$counter+1;
                        }
                    }
                }
                if($counter > 0){

//items is an array of IDs of duplicated records, which will be passed
// to hitcontroller and query each record to retrieve other details and
// print it in a page.

                    return redirect('/hit')->with('message', $items);
                }
                else{
                    return redirect('/home')->with('message', 'Records Successfully Saved!');
                }
            });



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire