ssquare

ssquare

Member Since 10 Months Ago

Experience Points 2,190
Experience Level 1

2,810 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 2
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

27 Jun
2 weeks ago

ssquare left a reply on How To Convert Following Sql Query To Laravel Query Buillder?

@kima As you suggested, I tried with your answers but it showing Invalid parameter number

As there are parameters for latitude, longitude as well I tried with following:

$query  = \DB::table('branch')
            ->select(
                'id',
                'name',
                \DB::raw('( 3959 * acos ( cos ( radians(?) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(?) ) + sin ( radians(?) ) * sin( radians( latitude ) ) ) ) as distance',[$latitude, $longitude, $latitude])
            )
            ->having("distance", "<", $request->distance)
            ->orderBy('distance', 'asc')
            ->offset(0)
            ->limit(20);

        $data = $query->get();

But still, it's saying invalid parameter number.

ssquare left a reply on How To Convert Following Sql Query To Laravel Query Buillder?

@mahaveer I have tried raw queries already but I could not get what I am doing wrong.

ssquare left a reply on How To Convert Following Sql Query To Laravel Query Buillder?

@aurawindsurfing I don't find your answer helpful in any direction. Do you think that some people just rush without any sort of searching or going through documentation? You get the notification and rush to check the answers and get reply why don't you google yourself? What is that?

Anyway in case if you are looking for any more attempt how I tried this with a raw query before. Please refer to the question.

ssquare started a new conversation How To Convert Following Sql Query To Laravel Query Buillder?

$sql = "SELECT id, name, ( 3959 * acos ( cos ( radians(?) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(?) ) + sin ( radians(?) ) * sin( radians( latitude ) ) ) ) AS distance FROM branch HAVING distance < ? ORDER BY distance LIMIT 0 , 20";

$data = \DB::select($sql,[$latitude, $longitude, $latitude, $distance]);


I am trying to get all the branch office which is in the perimeter of a certain distance. The above code is running well with SQL query but I want to try with query builder. Could anyone suggest me its equivalent.

06 Jun
1 month ago

ssquare left a reply on Session Variable Disappeared In Controller

@SIANGBOON - I have just tried as your mentioned method, but still, it is returning an empty array.

ssquare started a new conversation Session Variable Disappeared In Controller

I am trying to store booking details using a session variable. In the first function:

public function hold(Request $request){
         $details = [
                'times' => $arr,
                'subTotal' => $subTotal,
                'tax' => $tax
            ];
            $request->session()->forget('cart');
            $request->session()->put('cart',$details);
}

Next, it will be posted to another function of same controller. Upto this point session is available.

public function checkout(){
    dd(session()->all());
}

Next route is on payment controller. This is another controller than the previous one. Here, the session variable is empty.

public function createPayment(){
    dd(session()->all());
}

What am I doing wrong? How can I access session in this createPayment function?

17 May
1 month ago

ssquare left a reply on How To Handle Reoccuring Events

@devfrey Could you explain it in detail? I could not get it.

ssquare left a reply on How To Handle Reoccuring Events

@devfrey do you have any suggestion about how can I design table instead or any third party library or package that handle this for me?

ssquare left a reply on How To Handle Reoccuring Events

@devfrey could you check it I have updated the question as per your request adding some details

16 May
2 months ago

ssquare started a new conversation How To Handle Reoccuring Events

I am trying to make booking system something like booking futsal ground. Here, the user can select the time and date and make the book for it, and they can also check for repetition like, daily, weekly, monthly until xx date. This means there will be end-date predefined.

I have searched quite for a few time as some of them are quite complex or some of them are incomplete. What do you recommend to handle such tasks?

Or, if there is any package which handles all of the tasks let me know. Later, I will be integrating with a full calendar, so please consider from that frontend point of view as well.

07 May
2 months ago

ssquare left a reply on Validate If The Combination Of Two Columns Is Unique

@foram Yeah I have But should not it return an error and returned to form? This means currently it passed validation and tried to insert data but because of database schema exception arose.

ssquare left a reply on Validate If The Combination Of Two Columns Is Unique

@foram I have tried with

            'before_hours' => 'required|unique:refunds,before_hours,NULL,id,bus_id,' . $request->bus_id,

Error: Integrity constraint violation: 1062 Duplicate entry '24-1' for key 'refunds_before_hours_bus_id_unique' ...

ssquare started a new conversation Validate If The Combination Of Two Column In Unique

Model

id, before_hours, refund_percent, bus_id

In migration:

$table->unique(['before_hours', 'bus_id']);

I find that we can make sure if a column in unique or not by

'before_hours' => 'unique:refund_table,before_hours'

But, how can I validate if the combination is unique

30 Apr
2 months ago

ssquare left a reply on Laravel Too Slow To Update 1k Records

@LOSTDREAMER_NL - @phoenix404 How did you fix it? Facing similar situation

19 Apr
2 months ago

ssquare left a reply on Jeffrey:More Javascript Framework Tutorials?

Plus one upvote for react series

18 Apr
2 months ago

ssquare left a reply on Return ID From UpdateOrInsert Laravel Query Builder

@cronix Actually, I already have an index of (id, name, city, state, zip). The code in question is just pasted from laravel documentation itself. I need to check if there is already a row with the same name, city, state, zip.

ssquare left a reply on Return ID From UpdateOrInsert Laravel Query Builder

@cronix Although I am using as follows, it is taking way lot of time to insert data. It goes increasing as the size of the table increased.

DB::beginTransaction();
$r = Model::where($conditions)->first();
if($row){
                try{
                         $row = DB::table('table1')
                                                        ->where('id', $r->id)
                                                        ->update($data_arr);
                                            $row_id= $row ->id;
                                        } catch (\Exception $e) {
                                            $this->error_arr[] = $e->getMessage();
                                            $this->error_row_numbers[] = $this->data['row_value']; 
                                            DB::rollback(); 
                           }
}else{
 try{
                         $row_id = DB::table('table_1')->insertGetId(
                                                $data_arr
                                            );
                                        } catch (\Exception $e) {
                                            $this->error_arr[] = $e->getMessage();
                                            $this->error_row_numbers[] = $this->data['row_value']; 
                                            DB::rollback(); 
                           }
}

Now, using this $row_id I will find the row on table 2. If exists update else create just as in above code. This is taking too much time. To insert around 200,000 it is taking around 2 days. Now, what is the best way to deal with this? This is currently residing inside the job.

17 Apr
2 months ago

ssquare left a reply on Return ID From UpdateOrInsert Laravel Query Builder

@varun-2301 I don't think there is a method like updateOrCreate for query builder, that is available only in the eloquent model.

ssquare started a new conversation Return ID From UpdateOrInsert Laravel Query Builder

How to return the id of las updated or Inserted id.

I am using query builder instead of eloquent. How can I return ID from the following example:

DB::table('users')
    ->updateOrInsert(
        ['email' => '[email protected]', 'name' => 'John'],
        ['votes' => '2']
    );
07 Apr
3 months ago

ssquare left a reply on Queue Worker Stops Processing Jobs

Same problem. Sincerely, I don't know what's wrong with laravel queue. They too not good enough to handle the time-consuming task. After a certain time, the queue will stop and will not work fine until you restart them.

And when you ask the question like this even on laracasts, the question will be unanswered. That's the bitter truth bro. Increasing memory, is not the reliable option, what if you have an even bigger task.

05 Apr
3 months ago

ssquare started a new conversation MySQL Server Has Gone Away

I am trying to import data from CSV file to database using laravel queue. These CSV files are huge with around 500k number of rows.

I have learned somewhere that using laravel queue we don't need to think about connection time out but this is not looking true. Maybe I was wrong.

Please, check my job code if there is anything wrong in these methods. I am using "League\Csv" to read the CSV file.

public function __construct($data,$error_arr,$error_row_numbers) {  
       $this->data = $data;
       $this->error_arr = $error_arr;
       $this->error_row_numbers = $error_row_numbers;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $offset = $this->data['offset']; 
        $limit = $this->data['limit'];

        $filename = $this->data['file_name'];
        $service = new Service();
        $table = 'committees';
        $dbase = new Committee();

        //map_data have array about which csv column
        //should be inserted in which column of database
        $map_data = $this->data['map_data'];
        
    //get all columns name of a table
        $db_header_obj = new Committee();
        $db_header = $db_header_obj->getTableColumns();

        $csv_file_path = storage_path('app/files/committee/').$filename;
        if (!ini_get("auto_detect_line_endings")) {
            ini_set("auto_detect_line_endings", TRUE);
        }
        $csv = Reader::createFromPath($csv_file_path, 'r');

        $csv->setOutputBOM(Reader::BOM_UTF8);
        $csv->addStreamFilter('convert.iconv.ISO-8859-15/UTF-8');

            $csv->setHeaderOffset(0); 
            $csv_header = $csv->getHeader();    


           
            $rec_arr = array();
            $records = array();
            $records_arr = array();

                    $stmt = (new Statement())
                    ->offset($offset)
                    ->limit($limit)
                    ;

                    $records = $stmt->process($csv);

                    foreach ($records as $record) 
                    {
                        $rec_arr[] = array_values($record);
                    }

                    //trim index if the value of an array is empty
                    $records_arr = $service->trimArray($rec_arr);

                    if(count($records_arr)>0)
                    {
                        foreach($records_arr as $ck => $cv){

                            
                            $committee_arr = array();
                            foreach ($map_data as $mk => $mv) {
                                if(isset($mv)){
                                    $data_type = $service->getDatabaseColumnType($table,$mv);
                                    //if data is one of datetime data type
                                    //then format the csv data to mysql datetime format
                                    if($data_type == 'date' || $data_type == 'datetime' || $data_type == 'timestamp'){
                                        $datetime =  (array)$cv[$mk];
                                        $dt = array_shift($datetime);
                                        $dt = date('Y-m-d h:i:s', strtotime($dt));
                                        $committee_arr[$mv] = $dt;
                                    }else{
                                        $committee_arr[$mv] = $cv[$mk];
                                    }  

                                }
                            }

                            $error_encountered = false;


                            DB::beginTransaction();

                            if(!empty($committee_arr['com_id'])){

                                try{
                                        $committee_row = Committee::updateOrCreate(
                                            ['com_id' => $committee_arr['com_id']],
                                            $committee_arr
                                        );
                                        if ($committee_row->wasRecentlyCreated === true) {
                                            $committee_row->created_by = $this->data['user_id'];
                                        }else{
                                            $committee_row->updated_by = $this->data['user_id'];
                                        }
                                        $committee_row->save();
                                    } catch (\Exception $e) {
                                        $error_encountered = true;
                                         $this->error_arr[] = $e->getMessage();
                                         $this->error_row_numbers[] = $this->data['row_value']; 
                                    }

                            }


                            DB::commit();
                            //just to keep track which row is currently processing
                            //so that user can be notified in which row of csv
                            //there is an error
                            $this->data['row_value'] = $this->data['row_value'] + 1;

                        }

                        //offset just to start fectch next chunk of data from csv
                        $this->data['offset'] = $offset + $limit;
            
            //Call to same job but with increased offset value
                        $committeeInsertJob = (new StoreCommittee($this->data,$this->error_arr,$this->error_row_numbers))->delay(Carbon::now()->addSeconds(3)); 
                        dispatch($committeeInsertJob);

                    }else{

                        //Store activity just to keep track of activity
                        $activity = new Activity();
                        $activity->url = $this->data['url'];
                        $activity->action = 'store';
                        $activity->description = $table;
                        $activity->user_id = $this->data['user_id'];
                        $activity->created_at = date('Y-m-d H:i:s');
                        $activity->save();

                        $arr_data = [
                                'filename' => $filename,
                                'user_name' => $this->data['user_name'],
                                'error' => $this->error_arr,
                                'error_row_numbers' => $this->error_row_numbers
                            ];
                        //Notify user that the job is complete
                        Mail::to($this->data['user_email'])->send(new CSVImportJobComplete($arr_data));

                    }


            
            if (!ini_get("auto_detect_line_endings")) {
                ini_set("auto_detect_line_endings", FALSE);
            }
        }

Error: From (laravel.log inside storage)

[2019-04-05 07:13:23] local.ERROR: PDOStatement::execute(): MySQL server has gone away (SQL: insert into `jobs` (`queue`, `attempts`, `reserved_at`, `available_at`, `created_at`, `payload`) values (default, 0, , 1554448406, 1554448403, ....................................................(long list)

From: command terminal

$ php artisan queue:work --tries=3
[2019-04-05 07:09:11][1] Processing: App\Jobs\StoreCommittee
[2019-04-05 07:09:33][1] Processed:  App\Jobs\StoreCommittee
[2019-04-05 07:09:36][2] Processing: App\Jobs\StoreCommittee
[2019-04-05 07:09:58][2] Processed:  App\Jobs\StoreCommittee
[2019-04-05 07:10:01][3] Processing: App\Jobs\StoreCommittee
[2019-04-05 07:10:23][3] Processed:  App\Jobs\StoreCommittee
[2019-04-05 07:10:26][4] Processing: App\Jobs\StoreCommittee
[2019-04-05 07:10:48][4] Processed:  App\Jobs\StoreCommittee
[2019-04-05 07:10:51][5] Processing: App\Jobs\StoreCommittee
[2019-04-05 07:11:13][5] Processed:  App\Jobs\StoreCommittee
[2019-04-05 07:11:17][6] Processing: App\Jobs\StoreCommittee
[2019-04-05 07:11:40][6] Processed:  App\Jobs\StoreCommittee
[2019-04-05 07:11:43][7] Processing: App\Jobs\StoreCommittee
[2019-04-05 07:12:05][7] Processed:  App\Jobs\StoreCommittee
[2019-04-05 07:12:08][8] Processing: App\Jobs\StoreCommittee
[2019-04-05 07:12:31][8] Processed:  App\Jobs\StoreCommittee
[2019-04-05 07:12:34][9] Processing: App\Jobs\StoreCommittee
[2019-04-05 07:12:57][9] Processed:  App\Jobs\StoreCommittee
[2019-04-05 07:13:00][10] Processing: App\Jobs\StoreCommittee

[email protected] MINGW64 /d/wamp64/www/project(master)
$
(it stops without any error or failed notifications)

Is there anything I can improve on my job logic? How can I handle all this connection drop, or maxed timed out or some other stuff? I don't think the increasing timeout is the solution. As it can't be guaranteed that it will be finished within this fixed time.

Instead is there a way, were connection can be closed and again reconnect between each queue working?

26 Feb
4 months ago

ssquare started a new conversation UpdateOrCreate Is Creating New Row Instead Of Updating Old One

$map_data = Map_data::updateOrCreate(
                                    [ 'map_data' => json_encode($request->row), 'up_to_date' => 1],
                                    [ 'table_name' => 'table1' ]);

Already existed row have table_name => table1 map_data => json_encoded_array up_to_date => 0

I just want to check either table_name is already existed or not. It should not check either up_to_date is either 0 or 1. No matter what is its previous results, it should be updated to 1.

21 Feb
4 months ago

ssquare left a reply on Best Way To Handle Huge Insertion In Laravel Considering Both Timeout And Memory Issue

@aundunru I mean this will create a series of the job. For example in console we can se something like

Job[1] processing
Job[1] processed
Job[2] processing
Job[2] processed
Job[3] processing
Job[3] Processed
....
....
....

In this scenario, What will happen to those already processed jobs? Can this create a scarcity of queue worker in the future? Or as soon as the Job[1] processed the queue worker will be released?

16 Feb
5 months ago

ssquare left a reply on Best Way To Handle Huge Insertion In Laravel Considering Both Timeout And Memory Issue

By that way, will the first job shut automatically or because of the chaining of the 2nd job from first job, will that 2nd job considered as the part of first job?

14 Feb
5 months ago

ssquare started a new conversation Best Way To Handle Huge Insertion In Laravel Considering Both Timeout And Memory Issue

Currently, I am trying to insert data to the database using Laravel Queue. This is importing data from csv formatting some columns and the finally dump to the database.

The size of this csv is so huge that it could take more than 24 hours or even more as it has more than 500k rows of data.

Previously, I thought this queue is going to work with no time limits and memory but it does not seem to work in that way.

I am using LeagueCSV and reading csv rows on chunk until the read rows are not empty. This is reading data in for each loop.

How can I deal with this, Let me know if you need any more information?

Let me know if there is a way to break job connection and reconnect and work from next chunk removing this timeout and out of memory issue.

ssquare started a new conversation Raw Query Not Running

I am trying to run raw query as follow:

$rawStatement = 'SELECT table_rows "Rows Count" FROM information_schema.tables WHERE table_name="table_name" AND table_schema="db_name"';
DB::statement(DB::raw($rawStatement));

ERROR:

Too few arguments to function Illuminate\Database\Connection::raw(), 0 passed in D:\wamp64\www\project\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php on line 327 and exactly 1 expected

This sql is running from phpyadmin

04 Feb
5 months ago

ssquare started a new conversation Extra Data Not Sending To Server Using Ajax Datatable

I am detecting page click "First", "Previous", "Next", "Last" using a callback function and trying to send this data to the server.

I could successfully detect and console.log the current page, however, I am unable to send data to the server.

var page;
var dataTable = $('#DataTable').DataTable( {

                drawCallback: function(){
                    $('.paginate_button.first:not(.disabled)', this.api().table().container())          
                    .on('click', function(){
                        page = 'first';
                        console.log(page);
                    });
                    $('.paginate_button.previous:not(.disabled)', this.api().table().container())          
                    .on('click', function(){
                        page = 'previous';
                        console.log(page);
                    });
                    $('.paginate_button.next:not(.disabled)', this.api().table().container())          
                    .on('click', function(){
                        page = 'next';
                        console.log(page);
                    });
                    $('.paginate_button.last:not(.disabled)', this.api().table().container())          
                    .on('click', function(){
                        page = 'last';
                        console.log(page);
                    });       
                },
    "ajax": {
                    "url":base_path +'/other_path',
                    "dataType":"json",
                    "type":"POST",
                    "data":{"_token":csrf_token,"page":page}
                }
        ......
});

Header, does not show any page information being sent

08 Jan
6 months ago

ssquare left a reply on Help Needed To Convert Update Query To UpdateOrCreate

@snapey I got the sense but could you suggest me how can I filter and create $student with only fields that are present. You can see my previous logic in question.

ssquare left a reply on Help Needed To Convert Update Query To UpdateOrCreate

How am I supposed to get that student_id???? As this is the scenario of update or create. If there was some field something like id. Will it ever be necessary to write such long code?

ssquare left a reply on Help Needed To Convert Update Query To UpdateOrCreate

@vajid the phone and email are not compulsory fields. They might be present or not. So, its necessary to check them if they are present.

ssquare left a reply on Help Needed To Convert Update Query To UpdateOrCreate

@vajid and what about this part

->where(function($query) use ($student) {
        if (array_key_exists('phone_preferred', $student) && !empty($student['phone_preferred'])) {
            $query->where('phone_preferred', $student['phone_preferred']);
        }

        if (array_key_exists('email_preferred', $student) && !empty($student['email_preferred'])) {
            $query->where('email_preferred', $student['email_preferred']);
        }

        if (array_key_exists('home_street_address_1', $student) && !empty($student['home_street_address_1'])) {
            $query->where('home_street_address_1', $student['home_street_address_1']);
        }

        if (array_key_exists('mailing_street_address_1', $student) && !empty($student['mailing_street_address_1'])) {
            $query->where('mailing_street_address_1', $student['mailing_street_address_1']);
        }
        
        if (array_key_exists('mailing_address_city', $student) && !empty($student['mailing_address_city'])) {
            $query->where('mailing_address_city', $student['mailing_address_city']);
        }

ssquare started a new conversation Help Needed To Convert Update Query To UpdateOrCreate

My current code:

$existing = Student::where('name_last', $student['name_last'])
    ->where('name_first', $student['name_first'])
    ->where(function($query) use ($student) {
        if (array_key_exists('phone_preferred', $student) && !empty($student['phone_preferred'])) {
            $query->where('phone_preferred', $student['phone_preferred']);
        }

        if (array_key_exists('email_preferred', $student) && !empty($student['email_preferred'])) {
            $query->where('email_preferred', $student['email_preferred']);
        }

        if (array_key_exists('home_street_address_1', $student) && !empty($student['home_street_address_1'])) {
            $query->where('home_street_address_1', $student['home_street_address_1']);
        }

        if (array_key_exists('mailing_street_address_1', $student) && !empty($student['mailing_street_address_1'])) {
            $query->where('mailing_street_address_1', $student['mailing_street_address_1']);
        }
        
        if (array_key_exists('mailing_address_city', $student) && !empty($student['mailing_address_city'])) {
            $query->where('mailing_address_city', $student['mailing_address_city']);
        }

 })->first();

 if($existing){

        try{
            Student::where('id', $existing->id)
            ->update($student);
            } catch (\Exception $e) {
             $error_encountered = true;
             $error_arr[] = $e->getMessage();
             $error_row_numbers[] = $row_no; 
            }

}

I could convert it to update or create in following ways.

        try{
            Student::updateOrCreatewhere(
                         ['name_first' => $student['name_first], 'name_last' => $student['name_last]],
                        $student
               );
    
            } catch (\Exception $e) {
             $error_encountered = true;
             $error_arr[] = $e->getMessage();
             $error_row_numbers[] = $row_no; 
            }

But, I could not get how to implement that where query functions in this updateOrCreate.

17 Dec
6 months ago

ssquare started a new conversation Laravel Create Method Inserting Timestamp To Updated_at Column As Well

I am trying to insert data with something simple like

$data_arr['created_by'] = $this->data['user_id'];
$data_table = Model::create($data_arr);

But it is updating both created_at and updated_at table at once. I don't want to fill updated_at column at the time of creation.

How can I get rid of this?

12 Dec
7 months ago

ssquare started a new conversation Help To Implement Logic By Detecting End Of File And Loop Out While Parsing Csv And Dumping To Database

I am using CSVLeague to parse csv file and then later dumping those data to the database. The structure looks like.

$loop = true;

            while($loop){

                    $stmt = (new Statement())
                    ->offset($offset)
                    ->limit($limit)
                    ;

                    $records = $stmt->process($csv);

                    foreach ($records as $record) 
                    {
                        $rec_arr[] = array_values($record);  
                    }

                    $records_arr = $service->trimArray($rec_arr);  //removes if any empty row 
 encounters 

                    if(count($records_arr)>0){
                foreach($records_arr as $rk => $rv){
                    //here map csv column to database column and insert into database
                }
                $offset = $offset + $limit; 
            }else{
                $loop = false;  
            }

Currently, I am implementing this logic inside laravel queue. It is successfully inserting the whole set of data but it is not halting the process. It keeps stuck with message processing. However, if I removed that while loop then it will be stopped with message processed. So, I think it should be something that I am implementing some bad logic there.

Looking for an idea to tackle with this.

ssquare left a reply on Illuminate\Database\Eloquent\ModelNotFoundException: No Query Results For Model [App\Models\Model_name] Inside Laravel JOB

@mithrandir Thank you. I just removed those lines from construct and create directly inside handle as $model = new Model().

11 Dec
7 months ago

ssquare left a reply on Illuminate\Database\Eloquent\ModelNotFoundException: No Query Results For Model [App\Models\Model_name] Inside Laravel JOB

Well, that's not the full code. I was just trying to print out $records_arr till that. But, later it will be used in something like:

if(count($records_arr)>0)
            {
                foreach($records_arr as $ck => $cv){


                    $colorado_voter_arr = array();
                    foreach ($map_data as $mk => $mv) {
                        if(!isset($skip[$mk])){
                                // if (strpos($mv, '_date') !== false) {
                            $data_type = $this->service->getDatabaseColumnType($this->table,$mv);
                            if($data_type == 'date' || $data_type == 'datetime' || $data_type == 'timestamp'){
                                $datetime =  (array)$cv[$mk];
                                $dt = array_shift($datetime);
                                $dt = date('Y-m-d h:i:s', strtotime($dt));
                                $colorado_voter_arr[$mv] = $dt;
                            }else{
                                $colorado_voter_arr[$mv] = $cv[$mk];
                            }  
                /*Some other code*/
                 Colorado_voter::create($colorado_voter_arr);

                        }
                    }
        }
}

ssquare started a new conversation Illuminate\Database\Eloquent\ModelNotFoundException: No Query Results For Model [App\Models\Model_name] Inside Laravel JOB

I am trying to dump data from csv to database. But, I am getting an error as ModelNotFound inside laravel job. Although I have already imported model.

Error

Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\Models\Colorado_voter]. in D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php:414
Stack trace:
#0 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\SerializesAndRestoresModelIdentifiers.php(85): Illuminate\Database\Eloquent\Builder->firstOrFail()
#1 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\SerializesAndRestoresModelIdentifiers.php(55): App\Jobs\StoreColorado->restoreModel(Object(Illuminate\Contracts\Database\ModelIdentifier))
#2 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\SerializesModels.php(45): App\Jobs\StoreColorado->getRestoredPropertyValue(Object(Illuminate\Contracts\Database\ModelIdentifier))
#3 [internal function]: App\Jobs\StoreColorado->__wakeup()
#4 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(42): unserialize('O:22:"App\Jobs\...')
#5 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(83): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#6 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(326): Illuminate\Queue\Jobs\Job->fire()
#7 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(276): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#8 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#9 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(101): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#10 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#11 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#12 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Array, Array)
#13 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#14 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#15 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\Container.php(564): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#16 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Command.php(179): Illuminate\Container\Container->call(Array)
#17 D:\wamp64\www\kabza\vendor\symfony\console\Command\Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#18 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Command.php(166): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#19 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(886): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(262): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(145): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Application.php(89): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(122): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 D:\wamp64\www\kabza\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 {main}

My JobFile

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

use League\Csv\Reader;
use League\Csv\Statement;

use App\Http\Service\KabzaService;
use App\Models\Colorado_voter;
use App\Models\Base_voter;

class StoreColorado implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */

    private $service;
    private $table_name;
    private $dbase;

    public function __construct() {  
        $this->service = new KabzaService();
        $this->table = 'colorado_voter';
        $this->dbase = new Colorado_voter();
    }
 
    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $offset = 0;
        $limit = 50;
        $filename = '1000.csv';

        $skip = array
        (
            8 => 1,
            25 => 1,
            26 => 1,
            27 => 1,
            31 => 1,
            44 => 1,
            49 => 1
        );
        $map_data = array
        (
            0 => 'voter_id',
            1 => 'voter_county_code',
            2 => 'voter_county',
            3 => 'name_last',
            4 => 'name_first',
            5 => 'name_middle',
            6 => 'name_suffix',
            7 => 'name_voter',
            8 => 'id',
            9 => 'voter_precinct_name',
            10 => 'voter_library_id',
            11 => 'home_house_number',
            12 => 'home_house_suffix',
            13 => 'home_direction',
            14 => 'home_street_name',
            15 => 'home_street_type',
            16 => 'home_direction',
            17 => 'home_unit_type',
            18 => 'home_unit_number',
            19 => 'home_street_address_1',
            20 => 'home_address_city',
            21 => 'home_address_state',
            22 => 'home_address_zip',
            23 => 'home_address_zip_plus',
            24 => 'home_address_effective_date',
            25 => 'id',
            26 => 'id',
            27 => 'id',
            28 => 'birth_year',
            29 => 'gender',
            30 => 'voter_precinct_name',
            31 => 'id',
            32 => 'voter_status_id',
            33 => 'voter_party',
            34 => 'voter_party_affiliation_date',
            35 => 'phone_preferred',
            36 => 'mailing_street_address_1',
            37 => 'mailing_street_address_2',
            38 => 'mailing_street_address_3',
            39 => 'mailing_address_city',
            40 => 'mailing_address_state',
            41 => 'mailing_address_zip',
            42 => 'mailing_address_zip_plus',
            43 => 'mailing_address_country',
            44 => 'id',
            45 => 'permanent_mail_in_voter',
            46 => 'voter_congressional_district',
            47 => 'voter_state_district',
            48 => 'voter_house_district',
            49 => 'id'
        );

        $db_header_obj = new Colorado_voter();
        $db_header = $db_header_obj->getTableColumns();

        $base_voter_header = new Base_voter();
        $base_voter_columns = $base_voter_header->getTableColumns();

        $csv_file_path = storage_path('app/files/colorado_voter/').$filename;
        if (!ini_get("auto_detect_line_endings")) {
            ini_set("auto_detect_line_endings", TRUE);
        }
        $csv = Reader::createFromPath($csv_file_path, 'r');

        $csv->setOutputBOM(Reader::BOM_UTF8);
        $csv->addStreamFilter('convert.iconv.ISO-8859-15/UTF-8');

            $csv->setHeaderOffset(0); //set the CSV header offset
            $csv_header = $csv->getHeader();    

            $rec_arr = array();
            $records = array();
            $records_arr = array();

            $stmt = (new Statement())
            ->offset($offset)
            ->limit($limit)
            ;

            $records = $stmt->process($csv);

            foreach ($records as $record) 
            {
                $rec_arr[] = array_values($record);
            }

            $records_arr = $this->service->trimArray($rec_arr);

            print_r($records_arr);

            if (!ini_get("auto_detect_line_endings")) {
                ini_set("auto_detect_line_endings", FALSE);
            }
        }


}

Skip and map data are just an array used to determine which column from csv map to which column in database

ssquare left a reply on SQLSTATE[42S02]: [Microsoft][ODBC Driver 13 For SQL Server][SQL Server]Invalid Object Name 'failed_jobs'.

@globals Could you suggest why it is saying, model, not found. I think I have used use App\Models\Colorado_voter; there.

ssquare left a reply on SQLSTATE[42S02]: [Microsoft][ODBC Driver 13 For SQL Server][SQL Server]Invalid Object Name 'failed_jobs'.

@globals I have added that. But still, it showing error as some thing like

Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\Models\Colorado_voter]. in D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php:414
Stack trace:
#0 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\SerializesAndRestoresModelIdentifiers.php(85): Illuminate\Database\Eloquent\Builder->firstOrFail()
#1 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\SerializesAndRestoresModelIdentifiers.php(55): App\Jobs\StoreColorado->restoreModel(Object(Illuminate\Contracts\Database\ModelIdentifier))
#2 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\SerializesModels.php(45): App\Jobs\StoreColorado->getRestoredPropertyValue(Object(Illuminate\Contracts\Database\ModelIdentifier))
#3 [internal function]: App\Jobs\StoreColorado->__wakeup()
#4 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(42): unserialize('O:22:"App\Jobs\...')
#5 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(83): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#6 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(326): Illuminate\Queue\Jobs\Job->fire()
#7 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(276): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#8 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#9 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(101): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#10 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#11 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#12 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Array, Array)
#13 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#14 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#15 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\Container.php(564): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#16 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Command.php(179): Illuminate\Container\Container->call(Array)
#17 D:\wamp64\www\kabza\vendor\symfony\console\Command\Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#18 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Command.php(166): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#19 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(886): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(262): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(145): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Application.php(89): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(122): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 D:\wamp64\www\kabza\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 {main}

ssquare started a new conversation SQLSTATE[42S02]: [Microsoft][ODBC Driver 13 For SQL Server][SQL Server]Invalid Object Name 'failed_jobs'.

I have a demo csv file and I want to dump this data from csv file to database using laravel jobs. But I am receiving the following error.

[2018-12-11 05:46:23] local.ERROR: SQLSTATE[42S02]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Invalid object name 'failed_jobs'. (SQL: insert into [failed_jobs] ([connection], [queue], [payload], [exception], [failed_at]) values (database, default, {"displayName":"App\Jobs\StoreColorado","job":"Illuminate\Queue\[email protected]","maxTries":null,"timeout":null,"timeoutAt":null,"data":{"commandName":"App\Jobs\StoreColorado","command":"O:22:\"App\Jobs\StoreColorado\":10:{s:31:\"\u0000App\Jobs\StoreColorado\u0000service\";O:29:\"App\Http\Service\KabzaService\":0:{}s:34:\"\u0000App\Jobs\StoreColorado\u0000table_name\";N;s:29:\"\u0000App\Jobs\StoreColorado\u0000dbase\";O:45:\"Illuminate\Contracts\Database\ModelIdentifier\":4:{s:5:\"class\";s:25:\"App\Models\Colorado_voter\";s:2:\"id\";N;s:9:\"relations\";a:0:{}s:10:\"connection\";N;}s:6:\"\u0000*\u0000job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:5:\"delay\";O:13:\"Carbon\Carbon\":3:{s:4:\"date\";s:26:\"2018-12-11 05:46:21.085543\";s:13:\"timezone_type\";i:3;s:8:\"timezone\";s:3:\"UTC\";}s:7:\"chained\";a:0:{}}"}}, Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\Models\Colorado_voter]. in D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php:414
Stack trace:
#0 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\SerializesAndRestoresModelIdentifiers.php(85): Illuminate\Database\Eloquent\Builder->firstOrFail()
#1 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\SerializesAndRestoresModelIdentifiers.php(55): App\Jobs\StoreColorado->restoreModel(Object(Illuminate\Contracts\Database\ModelIdentifier))
#2 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\SerializesModels.php(45): App\Jobs\StoreColorado->getRestoredPropertyValue(Object(Illuminate\Contracts\Database\ModelIdentifier))
#3 [internal function]: App\Jobs\StoreColorado->__wakeup()
#4 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(42): unserialize('O:22:"App\Jobs\...')
#5 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(83): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#6 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(326): Illuminate\Queue\Jobs\Job->fire()
#7 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(276): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#8 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#9 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(101): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#10 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#11 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#12 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Array, Array)
#13 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#14 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#15 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\Container.php(564): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#16 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Command.php(179): Illuminate\Container\Container->call(Array)
#17 D:\wamp64\www\kabza\vendor\symfony\console\Command\Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#18 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Command.php(166): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#19 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(886): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(262): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(145): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Application.php(89): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(122): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 D:\wamp64\www\kabza\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 {main}, 2018-12-11 05:46:23.888)) {"exception":"[object] (Illuminate\Database\QueryException(code: 42S02): SQLSTATE[42S02]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Invalid object name 'failed_jobs'. (SQL: insert into [failed_jobs] ([connection], [queue], [payload], [exception], [failed_at]) values (database, default, {\"displayName\":\"App\\Jobs\\StoreColorado\",\"job\":\"Illuminate\\Queue\\[email protected]\",\"maxTries\":null,\"timeout\":null,\"timeoutAt\":null,\"data\":{\"commandName\":\"App\\Jobs\\StoreColorado\",\"command\":\"O:22:\\"App\\Jobs\\StoreColorado\\":10:{s:31:\\"\u0000App\\Jobs\\StoreColorado\u0000service\\";O:29:\\"App\\Http\\Service\\KabzaService\\":0:{}s:34:\\"\u0000App\\Jobs\\StoreColorado\u0000table_name\\";N;s:29:\\"\u0000App\\Jobs\\StoreColorado\u0000dbase\\";O:45:\\"Illuminate\\Contracts\\Database\\ModelIdentifier\\":4:{s:5:\\"class\\";s:25:\\"App\\Models\\Colorado_voter\\";s:2:\\"id\\";N;s:9:\\"relations\\";a:0:{}s:10:\\"connection\\";N;}s:6:\\"\u0000*\u0000job\\";N;s:10:\\"connection\\";N;s:5:\\"queue\\";N;s:15:\\"chainConnection\\";N;s:10:\\"chainQueue\\";N;s:5:\\"delay\\";O:13:\\"Carbon\\Carbon\\":3:{s:4:\\"date\\";s:26:\\"2018-12-11 05:46:21.085543\\";s:13:\\"timezone_type\\";i:3;s:8:\\"timezone\\";s:3:\\"UTC\\";}s:7:\\"chained\\";a:0:{}}\"}}, Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\Models\Colorado_voter]. in D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php:414
Stack trace:
#0 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\SerializesAndRestoresModelIdentifiers.php(85): Illuminate\Database\Eloquent\Builder->firstOrFail()
#1 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\SerializesAndRestoresModelIdentifiers.php(55): App\Jobs\StoreColorado->restoreModel(Object(Illuminate\Contracts\Database\ModelIdentifier))
#2 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\SerializesModels.php(45): App\Jobs\StoreColorado->getRestoredPropertyValue(Object(Illuminate\Contracts\Database\ModelIdentifier))
#3 [internal function]: App\Jobs\StoreColorado->__wakeup()
#4 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(42): unserialize('O:22:\"App\\Jobs\\...')
#5 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(83): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#6 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(326): Illuminate\Queue\Jobs\Job->fire()
#7 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(276): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#8 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#9 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(101): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#10 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#11 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#12 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Array, Array)
#13 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#14 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#15 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\Container.php(564): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#16 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Command.php(179): Illuminate\Container\Container->call(Array)
#17 D:\wamp64\www\kabza\vendor\symfony\console\Command\Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#18 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Command.php(166): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#19 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(886): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(262): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(145): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Application.php(89): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(122): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 D:\wamp64\www\kabza\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 {main}, 2018-12-11 05:46:23.888)) at D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664, Doctrine\DBAL\Driver\PDOException(code: 42S02): SQLSTATE[42S02]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Invalid object name 'failed_jobs'. at D:\wamp64\www\kabza\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:144, PDOException(code: 42S02): SQLSTATE[42S02]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Invalid object name 'failed_jobs'. at D:\wamp64\www\kabza\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:142, Illuminate\Database\Eloquent\ModelNotFoundException(code: 0): No query results for model [App\Models\Colorado_voter]. at D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php:414)
[stacktrace]
#0 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Database\Connection.php(624): Illuminate\Database\Connection->runQueryCallback('insert into [fa...', Array, Object(Closure))
#1 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Database\Connection.php(459): Illuminate\Database\Connection->run('insert into [fa...', Array, Object(Closure))
#2 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Database\Connection.php(411): Illuminate\Database\Connection->statement('insert into [fa...', Array)
#3 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Database\Query\Processors\SqlServerProcessor.php(24): Illuminate\Database\Connection->insert('insert into [fa...', Array)
#4 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(2494): Illuminate\Database\Query\Processors\SqlServerProcessor->processInsertGetId(Object(Illuminate\Database\Query\Builder), 'insert into [fa...', Array, NULL)
#5 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Failed\DatabaseFailedJobProvider.php(62): Illuminate\Database\Query\Builder->insertGetId(Array)
#6 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(188): Illuminate\Queue\Failed\DatabaseFailedJobProvider->log('database', 'default', '{\"displayName\":...', 'Illuminate\\Data...')
#7 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(137): Illuminate\Queue\Console\WorkCommand->logFailedJob(Object(Illuminate\Queue\Events\JobFailed))
#8 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(360): Illuminate\Queue\Console\WorkCommand->Illuminate\Queue\Console\{closure}(Object(Illuminate\Queue\Events\JobFailed))
#9 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(209): Illuminate\Events\Dispatcher->Illuminate\Events\{closure}('Illuminate\\Queu...', Array)
#10 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\FailingJob.php(36): Illuminate\Events\Dispatcher->dispatch('Illuminate\\Queu...')
#11 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(131): Illuminate\Queue\FailingJob::handle('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Database\Eloquent\ModelNotFoundException))
#12 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(45): Illuminate\Queue\CallQueuedHandler->handleModelNotFound(Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Database\Eloquent\ModelNotFoundException))
#13 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(83): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#14 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(326): Illuminate\Queue\Jobs\Job->fire()
#15 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(276): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#16 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#17 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(101): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#18 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#19 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#20 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Array, Array)
#21 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#22 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#23 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Container\Container.php(564): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#24 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Command.php(179): Illuminate\Container\Container->call(Array)
#25 D:\wamp64\www\kabza\vendor\symfony\console\Command\Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#26 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Command.php(166): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#27 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(886): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#28 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(262): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#29 D:\wamp64\www\kabza\vendor\symfony\console\Application.php(145): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#30 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Console\Application.php(89): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#31 D:\wamp64\www\kabza\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(122): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#32 D:\wamp64\www\kabza\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 {main}
"} 


My Jobs file looks like

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

use League\Csv\Reader;
use League\Csv\Statement;

use App\Http\Service\KabzaService;
use App\Models\Colorado_voter;
use App\Models\Base_voter;

class StoreColorado implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */

    private $service;
    private $table_name;
    private $dbase;

    public function __construct() {  
        $this->service = new KabzaService();
        $this->table = 'colorado_voter';
        $this->dbase = new Colorado_voter();
    }
 
    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $offset = 0;
        $limit = 50;
        $filename = '1000.csv';

        $skip = array
        (
            8 => 1,
            25 => 1,
            26 => 1,
            27 => 1,
            31 => 1,
            44 => 1,
            49 => 1
        );
        $map_data = array
        (
            0 => 'voter_id',
            1 => 'voter_county_code',
            2 => 'voter_county',
            3 => 'name_last',
            4 => 'name_first',
            5 => 'name_middle',
            6 => 'name_suffix',
            7 => 'name_voter',
            8 => 'id',
            9 => 'voter_precinct_name',
            10 => 'voter_library_id',
            11 => 'home_house_number',
            12 => 'home_house_suffix',
            13 => 'home_direction',
            14 => 'home_street_name',
            15 => 'home_street_type',
            16 => 'home_direction',
            17 => 'home_unit_type',
            18 => 'home_unit_number',
            19 => 'home_street_address_1',
            20 => 'home_address_city',
            21 => 'home_address_state',
            22 => 'home_address_zip',
            23 => 'home_address_zip_plus',
            24 => 'home_address_effective_date',
            25 => 'id',
            26 => 'id',
            27 => 'id',
            28 => 'birth_year',
            29 => 'gender',
            30 => 'voter_precinct_name',
            31 => 'id',
            32 => 'voter_status_id',
            33 => 'voter_party',
            34 => 'voter_party_affiliation_date',
            35 => 'phone_preferred',
            36 => 'mailing_street_address_1',
            37 => 'mailing_street_address_2',
            38 => 'mailing_street_address_3',
            39 => 'mailing_address_city',
            40 => 'mailing_address_state',
            41 => 'mailing_address_zip',
            42 => 'mailing_address_zip_plus',
            43 => 'mailing_address_country',
            44 => 'id',
            45 => 'permanent_mail_in_voter',
            46 => 'voter_congressional_district',
            47 => 'voter_state_district',
            48 => 'voter_house_district',
            49 => 'id'
        );

        $db_header_obj = new Colorado_voter();
        $db_header = $db_header_obj->getTableColumns();

        $base_voter_header = new Base_voter();
        $base_voter_columns = $base_voter_header->getTableColumns();

        $csv_file_path = storage_path('app/files/colorado_voter/').$filename;
        if (!ini_get("auto_detect_line_endings")) {
            ini_set("auto_detect_line_endings", TRUE);
        }
        $csv = Reader::createFromPath($csv_file_path, 'r');

        $csv->setOutputBOM(Reader::BOM_UTF8);
        $csv->addStreamFilter('convert.iconv.ISO-8859-15/UTF-8');

            $csv->setHeaderOffset(0); //set the CSV header offset
            $csv_header = $csv->getHeader();    

            $rec_arr = array();
            $records = array();
            $records_arr = array();

            $stmt = (new Statement())
            ->offset($offset)
            ->limit($limit)
            ;

            $records = $stmt->process($csv);

            foreach ($records as $record) 
            {
                $rec_arr[] = array_values($record);
            }

            $records_arr = $this->service->trimArray($rec_arr);

            print_r($records_arr);

            if (!ini_get("auto_detect_line_endings")) {
                ini_set("auto_detect_line_endings", FALSE);
            }
        }


}

I am using CSV league to parse csv file. Those skip and map_data are just the array which will be used later to map which column from csv to which column in database and skip will be used to skip some columns.

01 Nov
8 months ago

ssquare left a reply on Cannot Insert Duplicate Key Row In Object 'dbo.student' With Unique Index 'dept_id_room_id_roll_id_unique'. The Duplicate Key Value Is (<NULL>, <NULL>, <NULL>)

Isn't there any other way? I think it might lead to another confusion during update. Such as update where roll_ id = $roll_id .

ssquare started a new conversation Cannot Insert Duplicate Key Row In Object 'dbo.student' With Unique Index 'dept_id_room_id_roll_id_unique'. The Duplicate Key Value Is (<NULL>, <NULL>, <NULL>)

I have created migration as

            $table->bigInteger('dept_id')->unsigned()->nullable(); 
            $table->bigInteger('room_id')->unsigned()->nullable(); 
            $table->bigInteger('roll_id')->unsigned()->nullable();
            $table->unique(['dept_id', 'room_id','roll_id']);

I am using MsSQL 2017 as the database. It is now allowing to have null value in these unique columns for more than once. What I am missing?

ssquare started a new conversation Data Missing ERROR!!

I am trying to insert data to the table as follows:

FEC::create($fec_arr);

dd($fec_arr) returns

array:22 [
  "cmte_id" => "C00343863"
  "amndt_ind" => "N"
  "rpt_tp" => "Q3"
  "transaction_pgi" => "P"
  "image_num" => "27990795810"
  "transaction_tp" => "15"
  "entity_tp" => "IND"
  "name_voter" => "HOETGER, JACQUELINE Middle_ini Midlle mr."
  "mailing_address_city" => "FENTON"
  "mailing_address_state" => "MI"
  "mailing_address_zip" => "48430"
  "employer" => "SELF"
  "occupation" => "MOTT MEDIA"
  "donation_date" => "2007-08-30 12:00:00"
  "donation_id" => "A-C39094"
  "fec_federal_num" => "307489"
  "fec_memo_cd" => ""
  "fec_memo_text" => ""
  "fec_sub_id" => "4.10E+18"
  "name_last" => "HOETGER"
  "base_voter_id" => 5
  "created_by" => 1
]

Columns List in FEC Modal

       [cmte_id]
      ,[amndt_ind]
      ,[rpt_tp]
      ,[transaction_pgi]
      ,[image_num]
      ,[transaction_tp]
      ,[entity_tp]
      ,[name_last]
      ,[name_voter]
      ,[mailing_address_city]
      ,[mailing_address_state]
      ,[mailing_address_zip]
      ,[employer]
      ,[occupation]
      ,[donation_date]
      ,[donation_amount]
      ,[donation_id]
      ,[fec_other_id]
      ,[fec_federal_num]
      ,[fec_memo_cd]
      ,[fec_memo_text]
      ,[fec_sub_id]
      ,[base_voter_id]
      ,[created_by]
      ,[updated_by]
      ,[deleted_at]
      ,[created_at]
      ,[updated_at]

I am getting error as Data Missing. What I am doing wrong here?

23 Oct
8 months ago

ssquare left a reply on Laravel Execute Stored Procedure Taking More Time Than From SSMS

An invalid statement option was specified.

        $dbh = DB::connection()->getPdo();
        $sth = $dbh->prepare("EXEC [spBaseVoterIndex] ?,?,?,?",[$order, $dir, (int)$pagenum, (int)$pagesize]);
        $posts  = $sth->execute();

Also, I have already used NOCOUNT ON on stored procedure, should I used here too or can i igonre here if I have included it on stored procedure

ssquare started a new conversation Laravel Execute Stored Procedure Taking More Time Than From SSMS

I am using laravel 5.6 and MSSQL as database. I have table with records more than 100m+ rows. So whenever I execute a stored procedure through SSMS it takes around 1 sec but if I execute it through laravel execute it, this query time increases by 7-8 times.

My laravel code here looks like:


        $time_start2 = microtime(true);

        $posts = DB::select('EXEC [spBaseVoterIndex] ?,?,?,?',
                [
                    $order, $dir, (int)$pagenum, (int)$pagesize
                ]);
        
        $time_end2 = microtime(true);
        $execution_time2 = $time_end2 - $time_start2;

Is there any way to know what is Laravel doing it in the back or could anyone explain about the background stuffs included here. What might be taking the time and how can I minimize it.

17 Oct
8 months ago

ssquare left a reply on Laravel Queue Not Working As Expected

@d9705996 I am using laravel 5.6

ssquare started a new conversation Laravel Queue Not Working As Expected

What I have done so far:

  1. Updated queue driver to database in .env
  2. My mail controller function looks like:
    public function sendEmail()
    {
       $emailJob = (new SendEmailJob())->delay(Carbon::now()->addSeconds(3));
       dispatch($emailJob);
        exit();
    }
  1. SendEmailJob handle
    public function handle()
    {
        Mail::to('[email protected]')->send(new SendMailable());
        echo 'email sent';
    }
  1. SendMailable Mail has following
    public function build()
    {
        return $this->view('emails.ownership');
    }

I want to send mail almost instantly after hitting the url. As I am running php artisan queue:listen with delay of 3 seconds it takes a lot of time before any action. I can see some data on jobs table with 0 attempts.

After long time, following error popup in command window

   Symfony\Component\Process\Exception\ProcessTimedOutException  : The process ""C:\wamp64\bin\php\php7.2.10\php.exe" "artisan" queue:work  --once --queue="default" --delay=0 --memory=128 --sleep=3 --tries=0" e
xceeded the timeout of 60 seconds.

  at C:\wamp64\www\project\vendor\symfony\process\Process.php:1154
    1150|
    1151|         if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
    1152|             $this->stop(0);
    1153|
  > 1154|             throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_GENERAL);
    1155|         }
    1156|
    1157|         if (null !== $this->idleTimeout && $this->idleTimeout < microtime(true) - $this->lastOutputTime) {
    1158|             $this->stop(0);

  Exception trace:

  1   Symfony\Component\Process\Process::checkTimeout()
      C:\wamp64\www\project\vendor\symfony\process\Process.php:383

  2   Symfony\Component\Process\Process::wait()
      C:\wamp64\www\project\vendor\symfony\process\Process.php:202

By, the way mail can be sent directly without this queue stuff. Also, is this compulsory to run php artisan queue:listen? How am I supposed to run this in server with no shell access?

11 Oct
9 months ago

ssquare started a new conversation Catch Error If Arise On A Loop But Continue Ro Process Other Data From The Loop.

Scenarion:

I am trying to dump data from csv file to MsSQL database. My code is as:

        /*here skip is just 0 or 1 if skip is 0 later that mapped row will be ignored. Map data contains index array which will later used to map csv column to database column*/

        $limit = $this->service->getSettingsNameValue('chunk_limit');
            $skip = $request->skip;
            $map_data = $request->row;

    /*Just reading csv file. Have used csv league*/
        $db_header_obj = new Sos_contribution();
            $db_header = $db_header_obj->getTableColumns();
            $csv_file_path = storage_path('app/files/sos_contribution/').$request->filename;
            $csv = Reader::createFromPath($csv_file_path, 'r');
            $csv->setOutputBOM(Reader::BOM_UTF8);
            $csv->addStreamFilter('convert.iconv.ISO-8859-15/UTF-8');
            $csv->setHeaderOffset(0); //set the CSV header offset
            $csv_header = $csv->getHeader();    

            $rec_arr = array();
            $records = array();
            $records_arr = array();

            $stmt = (new Statement())
            ->offset($offset)
            ->limit($limit)
            ;

            $records = $stmt->process($csv);

            foreach ($records as $record) 
            {
                $rec_arr[] = array_values($record);
            }

            $records_arr = $this->service->trimArray($rec_arr);

            if(count($records_arr)>0)
            {
                foreach($records_arr as $ck => $cv){

                    $sos_contribution_arr = array();
                    foreach ($map_data as $mk => $mv) {
                        if(!isset($skip[$mk])){

                                $data_type = $this->service->getDatabaseColumnType($this->table,$mv);
                                if($data_type == 'date' || $data_type == 'datetime' || $data_type == 'timestamp'){
                /*just little piece of formatting of datetime*/
                                    $datetime =  (array)$cv[$mk];
                                    $dt = array_shift($datetime);
                                    $dt = date('Y-m-d h:i:s', strtotime($dt));
                                    $sos_contribution_arr[$mv] = $dt;
                                }else{
                                    $sos_contribution_arr[$mv] = $cv[$mk];
                                }   

                        }
                    }


        /*CATCH ERROR HERE*/
                    Sos_contribution::where('voter_state_id',$sos_contribution_arr['voter_state_id'])
                        ->update($sos_contribution_arr);

                   
              }
        }

Problem:

As I have huge csv file, there might be some typo errors in some column for example here example having some string character in integer column.

So, for example if there are 10 rows and there is an sql error for row 2. this means there is an string character mapped to int column. In that case, it just throws error and halt the process.

But, what I want is not to halt the process, instead record the row number and continuing other row. In this case, store 2 in a variable and continue processing 3-10 and later return that row number.

Is that possible?

What might be the best way to deal with this as later I want to queue this job and later send email to the owner after the completion of job with failed row number.

Example error: SQLSTATE[22018]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Conversion failed when converting the nvarchar value 'abx' to data type tinyint.

24 Sep
9 months ago

ssquare started a new conversation Obtain Result In Object Type And In Single Level

My MSSQL procedure

CREATE PROCEDURE PROCEDURE_NAME
AS BEGIN
    SELECT COUNT(*) FROM users
END

Currently calling as $totalData = DB::select('EXEC PROCEDURE_NAME');

and getting result in

<pre>Array
(
    [0] => stdClass Object
        (
            [] => 200000
        )

)
</pre>

Instead of this how can I get 200000 directly in $totalData.