ThinkingMan

ThinkingMan

Member Since 2 Years Ago

Experience Points
6,740
Total
Experience

3,260 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
43
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

Level 2
6,740 XP
Jun
01
19 hours ago
Activity icon

Replied to Fetch Data From Remote Database And Add/update To Local Database

Ok so I reworked my approach and now have the following code which handles the creates but I need to allow for updates. My cr_customer field is unique so I don't end up with duplicate accounts with the same customer number (that's what cr_customer represents).

So what is an approach to handle the updates? I don't think I can use the Eloquent addOrUpdate method with this implementation. I was going to try something like this https://stackoverflow.com/questions/48201961/laravel-addorupdate-on-basis-of-related-table-values.

And here is my updated implementation.

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

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->pushData();
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {

        $remoteCRs = DB::connection('remote')->table('CR')->where('cr_job_number',0)->orderBy('cr_customer')->get();

        $data = array();
        $data2 = array();

        foreach($remoteCRs as $remoteData){

               $data[ 'cr_customer']= $remoteData->cr_customer;
               $data['cr_job_number'] = $remoteData->cr_job_number;

                array_push($data2,$data);
        }
       return $data2;
    }

   public function pushData(){

       $values= $this->handle();

       foreach($values as $value){
           $customer = new Customers();
           $customer->cr_customer= $value['cr_customer'];
           $customer->cr_job_number= $value['cr_job_number'];
           $customer->save();

       }
   }
May
30
2 days ago
Activity icon

Replied to Fetch Data From Remote Database And Add/update To Local Database

@michaloravec I am still spinning wheels. With this code I can dd the collection (listed at bottom):

$remoteCRs = DB::connection('remote')->table('CR')->orderBy('cr_customer')->get();
        dd($remoteCRs);

But with this code I get the Undefined Index

$remoteCRs = RCustomers::all();
dd($remoteCRs);

So I think it is something with Eloquent trying to access the data vs. the builder call? Now, on my Eloquent model I have the cr_customer field set to primary. It is a char in the remote database so maybe that is the problem?

All I need to do is take the collection and add or update to my local customer table. Should I take a different approach?

Illuminate\Support\Collection {#1311 ▼
  #items: array:1120 [▼
    0 => {#1315 ▼
      +"cr_customer": "*10"
      +"cr_job_number": 0
      +"cr_sort_name_type": "C"
      +"cr_sort_name": "EDI COURTE"
      +"cr_bill_to_customer": ""
      +"cr_zip": ""
      +"cr_zip_plus_four": ""
      +"cr_name": "INTERNET COURTESY ACCOUNT"
      +"cr_street_1": ""
      +"cr_street_2": ""
      +"cr_city": ""
      +"cr_state": ""
      +"cr_country": "USA"
      +"cr_contact": ""
      +"cr_area_code": ""
      +"cr_phone": ""
      +"cr_net_sales_running_bal": "6.50"
      +"cr_bal_current": "0.00"
      +"cr_bal_aged1": "0.00"
      +"cr_bal_aged2": "0.00"
      +"cr_bal_aged3": "0.00"
      +"cr_bal_aged4": "0.00"
      +"cr_bal_subj_to_finance_charge": "0.00"
      +"cr_sales_period_to_date": "0.00"
      +"cr_sales_year_to_date": "0.00"
      +"cr_sales_last_yr": "0.00"
      +"cr_cost_period_to_date": "0.00"
      +"cr_cost_year_to_date": "0.00"
      +"cr_cost_last_yr": "0.00"
      +"cr_account_highest_bal": "6.50"
      +"cr_credit_limit": "0.00"
      +"cr_ptd_terms_discount": "0.00"
      +"cr_stmt_terms_discount": "0.00"
      +"cr_finance_charges_ytd": "0.00"
      +"cr_last_payment_amt": "0.00"
      +"cr_dollar_returns_ytd": "0.00"
      +"cr_num_sales_credits_ytd": 0
      +"cr_balance_method": "O"
      +"cr_date_account_opened": "2001-01-18"
      +"cr_last_purchase_date": "2019-11-27"
      +"cr_last_payment_date": null
      +"cr_rev_chrg_date_min_is_due": null
      +"cr_salesman_no": "01"
      +"cr_terms_code": "1"
      +"cr_tax_code": ""
      +"cr_user_code_1": ""
      +"cr_user_code_2": ""
      +"cr_user_code_3": "N"
      +"cr_user_code_4": ""
      +"cr_store": "1"
      +"cr_trade_discount": "0.000"
      +"cr_finance_charge": "Y"
      +"cr_late_charge_pct": "0.0000"
      +"cr_standard_selling_price": "R"
      +"cr_category_plan": ""
      +"cr_job_stmt_flag": "S"
      +"cr_check_payment": "Y"
      +"cr_charge_payment": "N"
      +"cr_credit_ar_only": "N"
      +"cr_po_required_on_charge": "N"
      +"cr_taxable": "Y"
      +"cr_department_sales_history": "Y"
      +"cr_print_statements": "N"
      +"cr_statements_with_dunning": "N"
      +"cr_print_price_on_pick_ticket": "N"
      +"cr_jobs_active": "N"
      +"cr_has_had_jobs": "N"
      +"cr_open_quote_allowed": "N"
      +"cr_payment_allowed": "N"
      +"cr_unused_flag1": "N"
      +"cr_unused_flag2": "N"
      +"cr_unused_flag3": "N"
      +"cr_resale_number": ""
      +"cr_credit_msg_1": ""
      +"cr_credit_msg_2": ""
      +"cr_stmt_balance": "0.00"
      +"cr_monthly_payment_amt": "0.00"
      +"cr_transfer_store": "N"
      +"cr_last_activity_date": "2019-11-27"
      +"cr_lumber_units_to_print": "N"
      +"cr_pricing_um": ""
      +"cr_quick_recall_days": 0
      +"cr_suspended_customer_account": ""
      +"cr_rental_price_indicator": ""
      +"cr_social_security_no": ""
      +"cr_birth_date_mo": ""
      +"cr_birth_date_da": ""
      +"cr_birth_date_cen": ""
      +"cr_birth_date_yr": ""
      +"cr_fax_area_code": ""
      +"cr_fax_phone": ""
      +"cr_member_type": ""
      +"cr_times_current": 0
      +"cr_times_1_30": 0
      +"cr_times_31_60": 0
      +"cr_times_61_90": 0
      +"cr_times_over_90": 0
      +"cr_times_no_activity": 0
      +"cr_last_date_current": "0000-00-00"
      +"cr_last_date_1_30": "0000-00-00"
      +"cr_last_date_31_60": "0000-00-00"
      +"cr_last_date_61_90": "0000-00-00"
      +"cr_last_date_over_90": "0000-00-00"
      +"cr_last_date_no_activity": "0000-00-00"
      +"cr_january": 0
      +"cr_february": 0
      +"cr_march": 0
      +"cr_april": 0
      +"cr_may": 0
      +"cr_june": 0
      +"cr_july": 0
      +"cr_august": 0
      +"cr_september": 0
      +"cr_october": 0
      +"cr_november": 0
      +"cr_december": 0
      +"cr_pst_registration": ""
      +"cr_gst_registration": ""
      +"cr_prompt_for_cust_info": "N"
      +"cr_cash_prompt_threshold": "0.00"
      +"cr_open_order_balance": "0.00"
      +"cr_declining_credit_limit_fg": "N"
      +"cr_use_ord_bal_in_crd_avail_fg": ""
      +"cr_main_job_global_crdlm_ck_fg": ""
      +"cr_finance_charges_last_yr": "0.00"
      +"cr_pesticide_license": ""
      +"cr_pesticide_expiration_date": null
      +"cr_auto_fax_flag": "N"
      +"cr_default_po_number": ""
      +"cr_freight_factor": "0.00"
      +"cr_print_invoice_flag": "N"
      +"cr_loyalty_id": ""
      +"cr_ignore_past_due_warning_fg": ""
      +"cr_alt_intl_phone": ""
      +"cr_alt_intl_fax": ""
      +"cr_treat_like_cash_cust": ""
      +"cr_email_statement": ""
      +"cr_email_invoice": "R"
      +"cr_email_format": ""
      +"cr_open_quote_doc": ""
      +"cr_open_quote_store": ""
      +"cr_ptd_trip_points_not_use": 0
      +"cr_ytd_trip_points_not_use": 0
      +"cr_email_order": ""
      +"cr_fax_invoice": ""
      +"cr_fax_order": ""
      +"cr_ship_method": ""
      +"cr_route_number": ""
      +"cr_route_day": ""
      +"cr_route_stop": ""
      +"cr_charge_freight_flag": "Y"
      +"cr_substitutesallowedfg": "Y"
      +"cr_backordersallowedfg": "Y"
      +"cr_backorder_complete_flag": "N"
      +"cr_duplicate_po_allowed_flag": "Y"
      +"cr_customer_priority_flag": "N"
      +"cr_po_expiration_date": "0000-00-00"
      +"cr_restock_fee_percent": "0.000"
      +"cr_rebate_plan_id": ""
      +"cr_tax_plan_id": ""
      +"cr_pesticide_plan_id": ""
      +"cr_pesticide_applicator_id": ""
      +"cr_pesticide_app_exp_date": "0000-00-00"
      +"cr_pesticide_restrict_id": ""
      +"cr_pesticide_restrict_exp_date": "0000-00-00"
      +"cr_ag_account_flag": "N"
      +"cr_dual_use_flag": "N"
      +"cr_fax_statement": ""
      +"cr_inet_customer_flag": "N"
      +"cr_core_selling_price": ""
      +"cr_auto_suspend_when_over_cl": "N"
      +"cr_chrg_not_allw_no_warning": "N"
      +"cr_alt_items_to_excl_in_pos": ""
      +"cr_auto_mcl_id": ""
      +"cr_credit_hold_after_days": 0
      +"cr_high_balance_date": null
      +"cr_part_disqualified_flag": ""
      +"cr_statement_format": "0"
      +"cr_stop_ship_flag": "N"
      +"cr_special_charge_1": "0.00"
      +"cr_special_charge_2": "0.00"
      +"cr_special_charge_3": "0.00"
      +"cr_cust_last_crdt_sort_no": 0
      +"cr_cust_last_crdt_posted": 0
      +"cr_service_charge": "0.0000"
      +"cr_movement_code_disc_flag": "N"
      +"cr_allow_regular_promo_price": "Y"
      +"cr_adis_unapplied_cash": "0.00"
      +"cr_adis_total_owing": "0.00"
      +"cr_ar_last_crdt_sort_no": 0
      +"cr_ar_last_crdt_posted": 0
      +"cr_allow_special_promo_price_1": "N"
      +"cr_allow_special_promo_price_2": "N"
      +"cr_dated_billing_allowed_flag": "N"
      +"cr_unusual_usage_flag": "N"
      +"cr_lost_sale_flag": "Y"
      +"cr_printing_plan": ""
      +"cr_store_group_id": ""
      +"cr_oem_part_xref_line": ""
      +"cr_core_bank": ""
      +"cr_ace_rewards_cust_profile": ""
      +"cr_exempt_check_verification": ""
      +"cr_pos_price_rnding": ""
      +"cr_csbp_group_number": ""
      +"cr_csbp_store_name": ""
      +"cr_central_order_desk_store": ""
      +"cr_job_auth_name_flag": ""
      +"cr_job_email_address_flag": ""
      +"cr_job_pos_message_flag": ""
      +"cr_display_past_due_warning": ""
      +"cr_ptd_trip_points": 0
      +"cr_ytd_trip_points": 0
      +"cr_subtotal_on_invoice": ""
      +"cr_delivery_point": ""
      +"cr_post_pos_adder_flag": ""
      +"cr_post_adder_sku_1": ""
      +"cr_post_adder_sku_2": ""
      +"cr_post_adder_sku_3": ""
      +"cr_job_pos_adder_flag": ""
      +"cr_resale_expiration_date": "0000-00-00"
      +"cr_add_names_pos_allowed_flag": ""
      +"cr_chrg_req_on_sale_credit": "N"
      +"cr_prospect": ""
      +"cr_num_sales_credits_lyr": 0
      +"cr_birth_month": 0
      +"cr_tv_loyalty_attribute_1": ""
      +"cr_tv_loyalty_attribute_2": ""
      +"cr_tv_loyalty_attribute_3": ""
      +"cr_tv_loyalty_attribute_4": ""
      +"cr_transmit_einvoices_flag": ""
      +"cr_address_type_flag": ""
      +"cr_freight_alw_min_pur_grd": 0
      +"cr_freight_alw_min_pur_truck": 0
      +"cr_sales_rep": ""
      +"cr_sign_req_note_id": ""
      +"cr_sign_req_threshold": 0
      +"cr_cod_flag": ""
      +"cr_loyalty_level": ""
      +"cr_segment_type": ""
      +"cr_status_flag": ""
      +"cr_loyalty_subscription_flag": ""
      +"cr_loyalty_subscription_item": ""
      +"cr_customer_ffl": ""
      +"cr_date_1_for_compass": null
      +"cr_date_2_for_compass": null
      +"cr_date_3_for_compass": null
      +"cr_date_4_for_compass": null
      +"cr_date_5_for_compass": null
      +"cr_date_6_for_compass": null
      +"cr_ffl_city_long": ""
    }
May
29
3 days ago
Activity icon

Replied to Fetch Data From Remote Database And Add/update To Local Database

@michaloravec ok so getting a bit frustrated over here on trying to set the Index of the RCustomers model. I don't think there is an index that the remote model is providing so trying to determine where to best set the index. I cannot change the database on the remote system, only read the data and I was trying to build an Eloquent model to get the data. But no matter what I do I cannot seem to set the index. Suggestions?

Activity icon

Replied to Fetch Data From Remote Database And Add/update To Local Database

@michaloravec ok so then do I need to map the data? or do I just need to identify the cr_customer field as the index?

Activity icon

Replied to Fetch Data From Remote Database And Add/update To Local Database

@tray2 I don't know that I want to blind sync all the data each time. For performance reasons I will want to grab the deltas plus I dont want to break any local relationships that are built from other tables in my app.

Activity icon

Replied to Fetch Data From Remote Database And Add/update To Local Database

@michaloravec I am getting slightly changed the code to the following because the getAttributes method was available to eloquent.

 RCustomers::where('cr_job_number',0)->chunk(10, function ($remoteCRs) {
            foreach ($remoteCRs as $remoteCR) {
                Customers::updateOrCreate([
                    'cr_customer' => $remoteCR->cr_customer
                ], $remoteCR->getAttributes());
            }
        });

Now I am getting Undefined index: App\RCustomers. Is it because I missed identifying a key in my remote customer model? I need to be able to match on the cr_customer field value between the remote and local table. Perhaps that's what was missed?

May
28
4 days ago
Activity icon

Started a new Conversation Fetch Data From Remote Database And Add/update To Local Database

Background:

My app has a customers table that I want to "sync" with customer records from a remote database. The remote database contains customer records with core information like account number, name, address, etc... I want to add or update those records in my app so I can extend the functionality for things like call tasks and marketing or other CRM related functions.

I have to do this because the customer uses an on-premise solution which doesn't have API's. But I do have access to the MySQL data so I can read the records. I'll do an initial load then look for deltas based on the "last updated" field on the remote data.

Code:

Remote Customer Table Model

class RCustomers extends Model
{
    //
    use RemoteConTrait;

    protected $primaryKey = 'cr_customer';

    protected $table= "CR";

    protected $connection = 'remote';

    protected static function boot()
    {
        static::addGlobalScope('cr_customer', function (Builder $builder) {
            $builder->where('cr_customer', '<>' , 0);
        });

        static::addGlobalScope('select_fields', function (Builder $builder) {
            $builder->select(
                [
                    'cr_customer as cr_customer',
                    'cr_job_number as cr_job_number',
                    'cr_sort_name_type as cr_sort_type',
...

Local Customer Table Model

class Customers extends Model
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    //
    protected $fillable = [
        'cr_customer',
        'cr_job_number',
	...

I was going to have a job that ran daily to do this. This is where I keep getting hung up. I have tried a few approaches and I know I am wrong but this is where I am. What's the best approach?

 DB::connection('remote')->table('CR')->orderBy('cr_customer')->chunk(10, function ($remoteCRs) {
                $remoteCRs->map( function ($data){

                    return $data;
                });
                foreach ($remoteCRs as $remoteCR) {

                    //customer record
                    Customers::all()

                        ->updateOrCreate([
                            'cr_customer' => $remoteCR->cr_customer
                        ],
                            $remoteCR->getAttributes());

                    echo $remoteCR->order_number."\n";



                }
            });
May
24
1 week ago
May
23
1 week ago
Activity icon

Replied to Tools For Auto Deployment After Subscription

But I wanted each customer to have their own instance

Activity icon

Started a new Conversation Tools For Auto Deployment After Subscription

does anybody know of some tools or projects that would allow me to auto deploy a laravel site to a subdomain after a customer signs up for my service?

So they would come to some site, register with a preferred subdomain name for their site, and after the successful registration my app would deploy as a subdomain for them.

May
15
2 weeks ago
Activity icon

Awarded Best Reply on Fresh Laravel 7 Install And Getting Error

I loaded PHP 7.3 and it's all working now. My composer could be a bit out of date but everything I read tied the issue to 7.4 PHP.

Activity icon

Replied to Fresh Laravel 7 Install And Getting Error

I loaded PHP 7.3 and it's all working now. My composer could be a bit out of date but everything I read tied the issue to 7.4 PHP.

Activity icon

Replied to Fresh Laravel 7 Install And Getting Error

@haz_ 7.4 was already running when I installed Laravel 7.

Activity icon

Replied to Fresh Laravel 7 Install And Getting Error

@haz_ found those same articles and tried matching the PHP version. Not sure what exactly is going on but going to try to step down to 7.3.X PHP since this really seems to be a 7.4 issue.

Activity icon

Started a new Conversation Fresh Laravel 7 Install And Getting Error

So I have seen several threads on this problem but no real clear answer. I am just installed a fresh 7.11.0 version of Laravel and am trying to perform a Composer Update but get "ErrorException Trying to access array offset on value of type null". I am running XAMMP with PHP 7.4.3

No project built or even scaffolded. Totally vanilla with the exception of adding in my Nova folder.

Anyone else bump into this yet?

Mar
28
2 months ago
Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

Seeing some working arounds on this issue but is there a approach to resolve the array? So I get the error because of the segment "$mc_lists = collect($mc_lists['lists'])->pluck('name', 'id');" in the code below.

$settings = MerchantSetting::get();

        $mc_service = new MailchimpService(auth()->user());
        $mc_valid   = $mc_service->isValidToken;
        $mc_lists   = $mc_valid ? $mc_service->getLists() : null;
        $mc_lists   = collect($mc_lists['lists'])->pluck('name', 'id');

        return view('configurator.configurator')->with([
            'getswift_key'   => $settings->where('slug', MerchantSetting::GETSWIFT_KEY_SLUG)->first(),
            'order_code'     => $settings->where('slug', MerchantSetting::MERCHANT_ORDER_CODE_SLUG)->first(),
            'mc_customer'    => $settings->where('slug', MerchantSetting::MAILCHIMP_CUSTOMERS_LIST_SLUG)->first(),
            'mc_transaction' => $settings->where('slug', MerchantSetting::MAILCHIMP_TRANSACTIONS_LIST_SLUG)->first(),
            'mc_valid'       => $mc_valid,
            'mc_lists'       => $mc_lists,

I saw @snapey posted a solution to catch the array on this post https://laracasts.com/discuss/channels/laravel/trying-to-access-array-offset-on-value-of-type-null but not sure if that would work here.

Mar
11
2 months ago
Activity icon

Awarded Best Reply on Hard Time Connecting MySQL Workbench To Forge Provisioned Server

Used DBeaver as a workaround to WorkBench

Activity icon

Replied to Hard Time Connecting MySQL Workbench To Forge Provisioned Server

Used DBeaver as a workaround to WorkBench

Activity icon

Started a new Conversation Hard Time Connecting MySQL Workbench To Forge Provisioned Server

I cannot access any AWS server that was provisioned by Forge. I get a message in Workbench that states "Authentication Error, unhandled exception caught in tunnel manager,..." At one point I could but not sure why I cannot access servers that were recently deployed. I am fairly confident that I have set my private and public keys up properly so just wondering if anyone else has this problem.

As an aside, I looked elsewhere for an answer but all solutions pointed to the fact that AWS would also have a RDS instance. I have never seen Forge deploy a Laravel project with an RDS instance. Separate point just calling it out as I don't have any RDS instance on my Forge deployed servers. Thoughts/Opinions?

Jan
05
4 months ago
Activity icon

Replied to How To Build A Basic SaaS Application Using Hyn.

@pranshubheda or @snapey would either of you have an opinion on whether or not the Hyn package provides a decent boilerplate for separating the data and providing the basic multi-tenant scaffolding? I am going to install and setup a sandbox instance to get a better feel for the landscape but thought I would ask since this thread was out there. Thanks in advance!