gbryant200

gbryant200

Member Since 1 Year Ago

Experience Points 8,680
Experience Level 2

1,320 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 82
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

16 Apr
2 months ago

gbryant200 left a reply on Internal Laravel Website - Setup

Thanks - I did finally find Satis. Now to configure it!

15 Apr
2 months ago

gbryant200 started a new conversation Internal Laravel Website - Setup

I'm setting up some internal web servers. I'm using Ubuntu 18.04. These web servers aren't allowed to access the internet due to our companies security restrictions. I've created a local Ubuntu mirror to maintain the Ubuntu servers (I did get approval for the apt-mirror to download updates from the internet but VLAN restrict a lot of the network traffic).

Anyway - I need to setup something on our local Ubuntu mirror to provide composer and the packages for our internal web servers.

Any suggestions?

Thanks.

17 May
1 year ago

gbryant200 left a reply on Collection Filtering On Relationship

Nevermind - I had pushed some non-object items in to the collection that I forgot to pull out before I did my filtering.

gbryant200 left a reply on Collection Filtering On Relationship

Inside the filter, if I

dd($load->LoadNumber, $load->shipswith->value2);

I get results. Inside the if ($load->shipswith->value2 == $value2) I get a 'trying to get property of non-object'.

16 May
1 year ago

gbryant200 left a reply on Collection Filtering On Relationship

I'm also getting a 'filter method not found' in phpStorm

gbryant200 started a new conversation Collection Filtering On Relationship

I have a collection of models with relationships. I need to filter the collection on a relationship's attribute's value.

Collection:

Collection {
#items: array:10 [
0 => Load{}
.
.
6=>Load{
   .
   .
   #relations: array:2 [
    "coils" => Collection {}
    "shipswith"=>Shipswith{
        .
        .
        #attributes: array 3 [
            "key1" => "value1"
            "key2" => "value2"
            "key3" => "value3"
            ]
   .
   .
9=>Load{}
]}

I need to filter the collection into a new collection of loads where the "shipswith" key2, value2 = the key2, value2 of a given Load (for load consolidation).

$loads is my collection of Loads Given Load ($id is the load number)

$load = $loads->where('LoadNumber', $id)->first();

$value2 = $load->shipswith->value2;  (getValue2Attribute defined on model)

Now I need to filter the collection for other loads with the same 'shipswith->value2'.

$consolidated_load = $loads->filter (function ($load) use ($value2) {

    return $load->shipswith->value2 == $value2;
});

Not sure what I'm missing since I get value2 from the load model without any issues.

How does the filter method know that the collection it is filtering is a collection of Load objects? I think that's something I'm missing.

Any ideas? Any help is greatly appreciated.

gbryant200 started a new conversation Retrieving Data From Cache (Redis)

I'm storing a database query - a collection of models with relationships - in cache with a single key.

LoadRepositoryEloquent method:

public function getLoads() {

        $loads = Cache::remember( 'loads_waiting_cache', 15, function () {

    $query_time = Carbon::now();
    $start_time = Carbon::now()->subHour( 12 );
    $end_time   = Carbon::now()->addHour( 12 );

    $loads = $this->model::doors()->scheduled($start_time, $end_time)->with([
    'coils:LDVH_LOAD_NO,LDVH_STCKCRD_NO,LDVH_STCKCRD_DA_ID',
    'shipswith:SWTH_AK_LOAD_REF,SWTH_RYD_SHIP_NBR,SWTH_MASTER_LD_IN'])->get();

    $nbr_loads = $loads->count();

    // add these values to the $loads collection
    $loads->put('loads_cnt',$nbr_loads)
        ->put('end_time',($end_time->toRfc850String()))
        ->put('start_time',($start_time->toRfc850String()))
        ->put('query_time',($query_time->toRfc850String()));

    return $loads;
    } );
        return $loads;
    }

so the entire collection is returned from this method either from the cache or from the database if expired. I have a view that displays the collection's information.

I want to define another method to retrieve a single 'Load' with its relationships from the collection stored in cache.

Do I have to retrieve the entire cache by its key or is there a way to grab a specific load by its load number? The array of Loads in the collection has numeric keys. Would it be better to store each model with its relationships separately in cache using the load number as the key?

15 May
1 year ago

gbryant200 left a reply on Eager Loading Not Retrieving Results

I don't have any control of the tables but I will be cutting down the columns I need considerably. Just trying to get things working for now.

I did find a solution to my issue.

I cast'd the load numbers from characters to integers and that took care of the issue.

14 May
1 year ago

gbryant200 left a reply on Eager Loading Not Retrieving Results

Well, the camel case apparently was an issue but now ...

$loads = $this->model::doors()->scheduled($start_time, $end_time)->with(['coils','shipswith'])->get();

is returning the 3 expected queries AND a separate query for each ShipsWith model.

I might look at creating a custom copy tomorrow.

Thanks everyone for your help. This has been frustrating.

gbryant200 left a reply on Eager Loading Not Retrieving Results

I don't have any default columns or keys so it seems I have to specify all the keys on all the relationships. Yes - it is confusing and I've tried the relationships with the keys swapped too. If they're not correct, I get a 'column not found' QueryException.

Here's what debugger is showing. Query 1

select * from USERID.SHIPCAR where (SHPCAR_DOOR1 in (?, ?, ?, ?, ?, ?) or SHPCAR_DOOR2 in (?, ?, ?, ?, ?, ?)) and (TIMESTAMP(SHPCAR_SCHD_PU_D, SHPCAR_SCHD_PU_T) between ? and ?) and SHPCAR_MILL = ? and SHPCAR_GATE_LOC = ? and SHPCAR_PRIMARY_FLG = ? and SHPCAR_SCAC <> ? FETCH FIRST 1000 ROWS ONLY

0. 77
1. 78
2. 166
3. 167
4. 185A
5. 191
6. 77
7. 78
8. 166
9. 167
10. 185A
11. 191
12. TIMESTAMP('2018-05-14 14:54:46')
13. TIMESTAMP('2018-05-15 18:54:46')
14. M
15. W
16. P
17. RMBX

These are correct and it returns a list of load numbers - in this instance, 154 load numbers.

Query 2

select * from USERID.LOADVEH where USERID.LOADVEH.ldvh_load_no in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) FETCH FIRST 1000 ROWS ONLY

Bindings    
0. 4687389
1. 4707535
...
152. 4734248
153. 4734571

Query 3

select * from USERID.SHIPWTH where USERID.SHIPWTH.swth_ak_load_ref in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Bindings    
0. 4687389
1. 4707535
...
152. 4734248
153. 4734571

So, there's just something wrong with how the third query is retrieving results.

Is there a way to dump the bindings as they are sent to the third query to check their datatype/size? Can you cast the bindings to a different datatype before they're applied to the query?

gbryant200 started a new conversation Eager Loading Not Retrieving Results

Load Model Relationships:

public function shipsWith() {
        return $this->hasOne('App\Models\ShipsWith','swth_ak_load_ref','shpcar_load_nbr');
    }

    public function coils() {
        return $this->hasMany('App\Models\Coil','ldvh_load_no','shpcar_load_nbr');
    }

Coil Model Relationship:

public function trkLoad() { 
        return $this->belongsTo('App\Models\Load','shpcar_load_nbr','ldvh_load_no');
    }

ShipsWith Model Relationship:

public function swLoad(){
        return $this->belongsTo('App\Models\Load','shpcar_load_nbr','swth_ak_load_ref');
    }

LoadRepositoryEloquent:

$loads = $this->model::doors()->scheduled($start_time, $end_time)->with(['coils','shipsWith'])->get();

doors() and sheduled() are local scopes on the Load Model.

Using the laravel debug toolbar - this logic runs 3 queries:

select * from USERID.SHIPCAR where (SHPCAR_DOOR1 in (?, ?, ?, ?, ?, ?) or SHPCAR_DOOR2 in (?, ?, ?, ?, ?, ?)) and (TIMESTAMP(SHPCAR_SCHD_PU_D, SHPCAR_SCHD_PU_T) between ? and ?) and SHPCAR_MILL = ? and SHPCAR_GATE_LOC = ? and SHPCAR_PRIMARY_FLG = ? and SHPCAR_SCAC <> ? FETCH FIRST 1000 ROWS ONLY

select * from USERID.LOADVEH where USERID.LOADVEH.ldvh_load_no in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) FETCH FIRST 1000 ROWS ONLY

select * from USERID.SHIPWTH where USERID.SHIPWTH.swth_ak_load_ref in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

and all the binding shown appear to be correct. However the 'shipsWith' results are all null (I can manually run a 'shipsWith' query and get results).

Load Collection returned - manually edited

**Load Model:{"shpcar_load_nbr":"4731610","shpcar_srn":"4731610","shpcar_scac":"SLTA","shpcar_carrier":"STEEL TRANSPORT, INC. (IN) ","shpcar_rrcar_nbr":" ","shpcar_rrcar_owner":" ","shpcar_barge_seq_n":"0","shpcar_assignment":" ","shpcar_mode":"TRK ","shpcar_license_nb":"62315A ","shpcar_license_st":"IN","shpcar_tractor_nb":"62315 ","shpcar_barge_owner":" ","shpcar_barge_nbr":" ","shpcar_tare_wgt":"32440","shpcar_gross_wgt":"79820","shpcar_demurrage":"0","shpcar_detn_chrg":" ","shpcar_schd_pu_d":"2018-05-14","shpcar_schd_pu_t":"16:00:00","shpcar_prev_pu_d":"9999-01-01","shpcar_prev_pu_t":"00:00:00","shpcar_prev_scac":" ","shpcar_door1":"185A","shpcar_door2":" ","shpcar_load_arrv_d":"2018-05-14","shpcar_load_arrv_t":"15:28:00","shpcar_arrival_id":"MDSERRS ","shpcar_stage_cd":"05 ","shpcar_load_admt_d":"2018-05-14","shpcar_load_admt_t":"15:33:00","shpcar_admit_id":"MDSERRS ","shpcar_comp_ld_dt":"2018-05-14","shpcar_comp_ld_tm":"16:03:00","shpcar_comp_ld_id":"MDSHAXM ","shpcar_load_dprt_d":"2018-05-14","shpcar_load_dprt_t":"16:30:00","shpcar_depart_id":"MDSEMJB ","shpcar_return_dt":"9999-01-01","shpcar_return_tm":"00:00:00","shpcar_return_id":" ","shpcar_return_cd":" ","shpcar_return_wgt":"0","shpcar_veh_status":"D","shpcar_lwgt_scale":" ","shpcar_owgt_permit":"N","shpcar_dpt_offwgt":"N","shpcar_catchup":" ","shpcar_mill":"M","shpcar_inspection":" ","shpcar_gate_loc":"W","shpcar_primary_flg":"P","shpcar_comb_load":" ","shpcar_reschd_dt":"9999-01-01","shpcar_reschd_tm":"00:00:00","shpcar_reschd_id":" ","shpcar_reschd_cd":" ","shpcar_reject_dt":"9999-01-01","shpcar_reject_tm":"00:00:00","shpcar_reject_id":" ","shpcar_reject_cd":" ","shpcar_trough_type":" ","shpcar_open_cover":" ","shpcar_last_upd_ts":"2018-05-14 16:30:01.838519","shpcar_last_upd_id":"ESADD01 ","shpcar_permit_wgt":"0","shpcar_pu_blvd_in":" ","shpcar_pu_bay_in":" ","shpcar_dlvycnfm_dt":"9999-01-01","shpcar_dlvycnfm_tm":"00:00:00","shpcar_dlvycnfm_id":" ","shpcar_match_wgt":"0","shpcar_trk_license":" ","shpcar_trk_state":" ","is_split_load":false,"coils":

**Coil Model**
[{"ldvh_load_no":"4731610","ldvh_stckcrd_no":"579871","ldvh_stckcrd_da_id":"03B ","ldvh_loaded_dt":"2018-05-14","ldvh_loaded_tm":"16:03:00","ldvh_loaded_id":"MDSHAXM ","ldvh_mode_in":"TRK ","ldvh_mill_in":"M","ldvh_rrcar_own_id":" ","ldvh_rrcar_no":" ","ldvh_door_id":"185A","ldvh_next_fac_ty":"80","ldvh_next_fac_no":"AA","ldvh_last_upd_ts":"2018-05-14 16:03:32.503586","ldvh_last_upd_id":"SF860 ","ldvh_at_dest_in":" ","ldvh_stcc_cd":"3312332"}],

**ShipsWith Model relationshiop (doesn't seem correct)***
"ships_with":null}

Also, if I modify the LoadRepository query to:

$loads = $this->model::doors()->scheduled($start_time, $end_time)->with('coils')->has('shipsWith')->get();

I get 'shipsWith' data but now it 2 queries + 1 for every load number (which can sometimes be over 100; isn't that the N+1 issue?).

select * from USERID.SHIPCAR where (SHPCAR_DOOR1 in (?, ?, ?, ?, ?, ?) or SHPCAR_DOOR2 in (?, ?, ?, ?, ?, ?)) and (TIMESTAMP(SHPCAR_SCHD_PU_D, SHPCAR_SCHD_PU_T) between ? and ?) and exists (select * from USERID.SHIPWTH where USERID.SHIPCAR.shpcar_load_nbr = USERID.SHIPWTH.swth_ak_load_ref) and SHPCAR_MILL = ? and SHPCAR_GATE_LOC = ? and SHPCAR_PRIMARY_FLG = ? and SHPCAR_SCAC <> ? FETCH FIRST 1000 ROWS ONLY

select * from USERID.LOADVEH where USERID.LOADVEH.ldvh_load_no in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) FETCH FIRST 1000 ROWS ONLY

select * from USERID.SHIPWTH where USERID.SHIPWTH.swth_ak_load_ref = ? and USERID.SHIPWTH.swth_ak_load_ref is not null FETCH FIRST 1 ROWS ONLY

select * from USERID.SHIPWTH where USERID.SHIPWTH.swth_ak_load_ref = ? and USERID.SHIPWTH.swth_ak_load_ref is not null FETCH FIRST 1 ROWS ONLY

*keeps going, one for each load number*

Any ideas as to what is going on?

The Load table and Coil table have the load number as their reference keys as characters with a length of 7; the shipsWith table's key is also the load number but a length of 16. If I manually query the shipsWith table I can use a string (trimmed) or an integer and the database will return the results. If I use a string with extra spaces, no results are returned. Looking at the parameters in the laravel php debug bar, I don't think that's an issue.

Thanks.

10 May
1 year ago

gbryant200 left a reply on Get Subquery Or Join Results As Array In Object

I was using with(coils) and getting no results - I thought I was doing everything correct.

I changed my local and foreign keys to lower case and then I started getting results. Crazy.

Thanks again for the reply and the link to the tutorial.

I appreciate it very much.

gbryant200 started a new conversation Get Subquery Or Join Results As Array In Object

I have a one-to-many relationship of loads to items (in the load). Right now the results return as an array of objects for each load's item.

Load number 4714919 has 2 items in it. The query results:

[
     {
     "load": "4714919",
     "coil": "579190-02BB"
     },
     {
     "load": "4714919",
     "coil": "579190-03B"
     }
]

What I'd like to receive:

[
     {
     "load":"4714919",
     "coils": [579190-02BB",  "579190-03B"]
    }
]

Is there a way in Laravel to query these 2 tables - Loads and Items and return the information this way?

DB::connection('QISDB')->select("SELECT L.SHPCAR_LOAD_NBR as load, C.LDVH_STCKCRD_NO CONCAT '-' CONCAT C.LDVH_STCKCRD_DA_ID as coil FROM USERID.SHIPCAR L, USERID.LOADVEH C WHERE L.SHPCAR_LOAD_NBR = :load AND L.SHPCAR_PRIMARY_FLG = 'P' AND (L.SHPCAR_LOAD_NBR = C.LDVH_LOAD_NO)",['load' => $load ]);

I thought this would be a simple relationship setup on the 2 models but I'm not getting any results from the one to many relationship even with setting the local and foreign keys for the one-to-many and belongsTo relationships.

Load relationship:

public function coils() {
return $this->hasMany('App\Models\Coil','LDVH_LOAD_NO','SHPCAR_LOAD_NBR');
    }

Coils relationship

public function trk_load() { 
        return $this->belongsTo('App\Models\Load','SHPCAR_LOAD_NBR','LDVH_LOAD_NO');
    }

Any Ideas?

09 May
1 year ago

gbryant200 left a reply on Relationships With Repositories

Thanks. I'll check those out. I've been trying to learn Laravel at the same time learn PHP while building this 'load tracking' app. All the basic Laravel tutorials were simple using MySQL and tables that you have complete control over. I came across the Repository pattern and everyone online saying it was the right thing to use (and I thought it would be good to learn).

08 May
1 year ago

gbryant200 left a reply on Relationships With Repositories

I have no control of the database - it's a very old & convoluted IBM DB2 system

gbryant200 started a new conversation Relationships With Repositories

I'm new to Laravel/Eloquent and have learned a lot using a Repository pattern to query one table in the database. I'm using a scope to query load numbers scheduled to ship between 2 times. I get back a collection of Load models that tracks when the load is scheduled to ship, if the truck has arrived and been loaded, etc. So far so good.

Now I need to setup the relationship(s) for the Load and the Items in the Load.

in the Load Model

public function items() {
    return $this->hasMany('Item', 'item_load_nbr', 'load_nbr');
}

in the Items Model

public function loads() {
    return $this->belongsTo('Load', 'load_nbr', 'item_load_nbr');
}

How can I add this relationship to my original Load Repository query to include the items in the Load? I don't necessarily want all the Item's attributes. I have a getItemIDAttribute() function setup in my Item model for instance.

My LoadsRepository query:

public function getLoads() {

        $loads = Cache::remember( 'loads_waiting_cache', 15, function () {

            $start_time = Carbon::now()->subHour( 4 );
            $end_time   = Carbon::now()->addHour( 4 );

            $loads = $this->model::scheduled($start_time, $end_time)->get();

            $nbr_loads = $loads->count();

            // add these values to the $loads collection
            $loads->put('loads_cnt',$nbr_loads)->put('end_time',($end_time->toRfc850String()))->put('start_time',($start_time->toRfc850String()));
            return $loads;
        } );
        return $loads;
    }

The documentation and demos I've watched seem very basic and I'm having trouble applying them to my situation.

How can I set things up so when I retrieve my scheduled Loads I can get the items for that load as well without another round of queries for each load?

Thanks for any help.

25 Apr
1 year ago

gbryant200 left a reply on $schedule->job(new QueryJob()) Can't Find The Model's Database Connection Driver

I had to setup the pdo_ibm driver for the cli php.ini. Everything worked fine after that!

gbryant200 left a reply on $schedule->job(new QueryJob()) Can't Find The Model's Database Connection Driver

From the Horizon Log:

PDOException: could not find driver in /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

Stack trace:

#0 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(68): PDO->__construct('ibm:QISDB', 'xxxxx', 'xxxxxx', Array)
#1 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(44): Illuminate\Database\Connectors\Connector->createPdoConnection('ibm:QISDB', 'xxxxx', 'xxxxx', Array)
#2 /var/www/ep2/vendor/cooperl/laravel-db2/src/Connectors/DB2Connector.php(24): Illuminate\Database\Connectors\Connector->createConnection('ibm:QISDB', Array, Array)
#3 /var/www/ep2/vendor/cooperl/laravel-db2/src/DB2ServiceProvider.php(81): Cooperl\Database\DB2\Connectors\DB2Connector->connect(Array)
#4 [internal function]: Cooperl\Database\DB2\DB2ServiceProvider->Cooperl\Database\DB2\{closure}(Array, 'QISDB')
#5 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php(109): call_user_func(Object(Closure), Array, 'QISDB')
#6 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php(74): Illuminate\Database\DatabaseManager->makeConnection('QISDB')
#7 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1135): Illuminate\Database\DatabaseManager->connection('QISDB')
#8 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1101): Illuminate\Database\Eloquent\Model::resolveConnection('QISDB')
#9 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(931): Illuminate\Database\Eloquent\Model->getConnection()
#10 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(877): Illuminate\Database\Eloquent\Model->newBaseQueryBuilder()
#11 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(840): Illuminate\Database\Eloquent\Model->newQueryWithoutScopes()
#12 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1504): Illuminate\Database\Eloquent\Model->newQuery()
#13 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1516): Illuminate\Database\Eloquent\Model->__call('doors', Array)
#14 /var/www/ep2/app/Repositories/LoadRepositoryEloquent.php(54): Illuminate\Database\Eloquent\Model::__callStatic('doors', Array)
#15 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(327): App\Repositories\LoadRepositoryEloquent->App\Repositories\{closure}()
#16 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php(304): Illuminate\Cache\Repository->remember('loads_waiting_c...', 5, Object(Closure))
#17 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Illuminate\Cache\CacheManager->__call('remember', Array)
#18 /var/www/ep2/app/Repositories/LoadRepositoryEloquent.php(60): Illuminate\Support\Facades\Facade::__callStatic('remember', Array)
#19 /var/www/ep2/app/Jobs/QueryLoadsJob.php(37): App\Repositories\LoadRepositoryEloquent->getLoads()
#20 [internal function]: App\Jobs\QueryLoadsJob->handle(Object(App\Repositories\LoadRepositoryEloquent))
#21 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#22 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#23 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#24 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Container/Container.php(564): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#25 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#26 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(114): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(App\Jobs\QueryLoadsJob))
#27 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\QueryLoadsJob))
#28 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#29 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(49): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\QueryLoadsJob), false)
#30 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(83): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#31 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(322): Illuminate\Queue\Jobs\Job->fire()
#32 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(272): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), Object(Illuminate\Queue\WorkerOptions))
#33 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\RedisJob), 'redis', Object(Illuminate\Queue\WorkerOptions))
#34 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\Queue\Worker->daemon('redis', 'default', Object(Illuminate\Queue\WorkerOptions))
#35 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('redis', 'default')
#36 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#37 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#38 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#39 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#40 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Container/Container.php(564): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#41 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Container\Container->call(Array)
#42 /var/www/ep2/vendor/symfony/console/Command/Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#43 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#44 /var/www/ep2/vendor/symfony/console/Application.php(865): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#45 /var/www/ep2/vendor/symfony/console/Application.php(241): Symfony\Component\Console\Application->doRunCommand(Object(Laravel\Horizon\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#46 /var/www/ep2/vendor/symfony/console/Application.php(143): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#47 /var/www/ep2/vendor/laravel/framework/src/Illuminate/Console/Application.php(88): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#48 /var/www/ep2/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))
#49 /var/www/ep2/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#50 {main}

Data

{
  "job": null,
  "connection": null,
  "queue": null,
  "chainConnection": null,
  "chainQueue": null,
  "delay": null,
  "chained": []
}
24 Apr
1 year ago

gbryant200 left a reply on $schedule->job(new QueryJob()) Can't Find The Model's Database Connection Driver

This connection has been setup since the start of the project. The Job is new but everything else isn't. I can run the same repository method from a controller and Laravel finds the database connection driver just fine and loads the data in to the redis cache.

maybe there's some linux file permission issues?

gbryant200 started a new conversation $schedule->job(new QueryJob()) Can't Find The Model's Database Connection Driver

I've setup a scheduled task to run every 5 minutes to update query results in redis cache.

app\Console\Kernel.php

namespace App\Console;

use App\Jobs\QueryLoadsJob;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

protected function schedule(Schedule $schedule)
    {
        $schedule->job(new QueryLoadsJob())->everyFiveMinutes();
    }

QueryLoadsJob.php

namespace App\Jobs;

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

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

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @param LoadRepositoryEloquent $load_repository_eloquent
     *
     * @return void
     */
    public function handle(LoadRepositoryEloquent $load_repository_eloquent)
    {
        $load_repository_eloquent->getLoads();
    }
}

My LoadsRepositoryEloquent.php

namespace App\Repositories;

use Illuminate\Support\Facades\Cache;
use Redis;
use Prettus\Repository\Eloquent\BaseRepository;
use Prettus\Repository\Criteria\RequestCriteria;
use App\Repositories\LoadRepository;
use App\Models\Load;
use App\Validators\LoadValidator;

class LoadRepositoryEloquent extends BaseRepository implements LoadRepository
{
    /**
     * Specify Model class name
     *
     * @return string
     */
    public function model()
    {
        return Load::class;
    }

    /**
    * Specify Validator class name
    *
    * @return mixed
    */
    public function validator()
    {

        return LoadValidator::class;
    }

    public function getLoads() {

        $loads = Cache::remember('loads_waiting_cache', 5, function ()
        {
            return $this->model::doors()
                                 ->scheduled()
                                 ->admitted()
                                 ->notRejected()
                                 ->notReturned()
                                 ->stillHere()->get();
        });
            return $loads;

    }
}

my model Loads.php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;
use Carbon\Carbon;
use App\Scopes\gblGateScope;
use App\Scopes\gblLimitScope;
use App\Scopes\gblMillScope;

class Load extends Model implements Transformable
{
    use TransformableTrait;
    
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];

    public $connection = 'QISDB';

    protected $table = 'USERID.SHIPCAR'; 
    protected $primarykey = null;
    public $incrementing = false;
    public $timestamps = false;

    protected static function boot() {
        parent::boot();

        // sets the SHPCAR_MILL to M for all queries
        static::addGlobalScope(new gblMillScope());

        // sets the SHPCAR_GATE_LOC to W for all queries
        static::addGlobalScope(new gblGateScope());

        // sets the limit to 1000 just in case
        static::addGlobalScope(new gblLimitScope());
    }


    /**
     *  Door scope for door numbers to be included in query.
     *
     * @param \Illuminate\Database\Eloquent\Builder $query
     *
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeDoors($query){
        return $query->wherein('USERID.SHIPCAR.SHPCAR_DOOR1',['77', '78', '166', '167', '185A', '191']);
    }

    public function scopeAdmitted($query){
        return $query->where('USERID.SHIPCAR.SHPCAR_LOAD_ADMT_D','<>','9999-01-01');
    }

    public function scopeStillHere($query){
        return $query->where('USERID.SHIPCAR.SHPCAR_COMP_LD_DT','=','9999-01-01');
    }

    public function scopeScheduled($query){
        $startTime = Carbon::now()->subHour(36)->format('Y-m-d');
        $endTime = Carbon::now()->addHour(12)->format('Y-m-d');
        return $query->whereBetween('USERID.SHIPCAR.SHPCAR_SCHD_PU_D',[$startTime, $endTime])
                     ->where('USERID.SHIPCAR.SHPCAR_SCHD_PU_D','<>','9999-01-01');
    }

    public function scopeNotRejected($query){
        return $query->where('USERID.SHIPCAR.SHPCAR_REJECT_DT','=','9999-01-01');
    }

    public function scopeNotRescheduled($query){
        return $query->where('USERID.SHIPCAR.SHPCAR_RESCHD_DT','=','9999-01-01');
    }

    public function scopeNotReturned($query){
        return $query->where('USERID.SHIPCAR.SHPCAR_RETURN_DT','=','9999-01-01');
    }
}

If I call the repository's getLoads() from a controller, the results come back fine. Running the QueryLoadsJob results in a 'could not find driver {"exception":"[object] (PDOException(code: 0): could not find driver at /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68)'

Do I need to inject the model somewhere so the Job can find the database connection?

16 Mar
1 year ago

gbryant200 left a reply on How To Use A NPM Package In Laravel?

I'm having the same issues getting an npm jquery and datatables to work. A walk-through would be great.