twoarmtom

twoarmtom

Member Since 1 Year Ago

Beamsville

Experience Points
9,740
Total
Experience

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
81
Lessons
Completed
Best Reply Awards
1
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.

Level 2
9,740 XP
Nov
30
2 weeks ago
Activity icon

Replied to Failed Mail Error

But all other message are currently working without error, all of them using queue, would that make sense?

When this action is run, two messages are sent. One is a default, and this one gets sent if a condition is met (with if statement). The default queue message works fine, this conditional one is the broken one (but works when I use send instead of queue). But there seems to be no reason.

Activity icon

Replied to Failed Mail Error

When I change 'queue' to 'send' it works fine. All other messages are using 'queue' and working fine. I've updated all installs to use 'send' instead of 'queue' for this mail message, I just wish I know why it doesn't work but all my other messages using 'queue' work fine.

Activity icon

Replied to Failed Mail Error

@siangboon it's not the data, the data is not passed to the Mail class, it is the condition that causes it to send, which is working fine and is causing it to fire appropriately.

Activity icon

Replied to Failed Mail Error

@snapey I checked all files and classes, cases are all the same. I also have an online production test environment where it also seems to work fine. It's failed on two other client installs with identical code. It's so strange.

Activity icon

Replied to Failed Mail Error

@siangboon I have other mail functions firing in the same controller without any issues. I added this one just the other day and it seems to fail, but only when on production server, not locally, so I cant even test it properly.

Nov
29
2 weeks ago
Activity icon

Started a new Conversation Failed Mail Error

I'm getting the following error message in production, but everything is fine in my local environment.

Illuminate\Mail\SendQueuedMailable::handle(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "App\Mail\ConcerningFormativeEvaluation" of the object you are trying to operate on was loaded before unserialize() gets called or provide an autoloader to load the class definition

I found this similar problem already posted, and I tried what they suggested, but it did not work.

 composer dump-autoload

Here is the code:

// evaluation
$evaluation = FormativeEvaluation::create($request->all());

// find the student
$student = User::find($request->input('user_id'));

// get the school
$school = User::whereHas('roles', function($q) { 
          
          $q->where('type', 'school'); 
          
          })->first();

// set the URL
$url = "/school/student/formative-evaluation/view";

// send mail (the $data variable is set earlier based on scores submitted, it's not the issue)
$notify = $request->input('notify');
        
if (in_array(1, $data) || in_array(0, $data) || $notify == "yes") {
    $url = "/school/student/formative-evaluation/view";
         Mail::to($school)->queue(new ConcerningFormativeEvaluation($student, $url, $evaluation)); 
}

Mail

<?php

namespace App\Mail;

use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class ConcerningFormativeEvaluation extends Mailable
{
    public $student;
    public $evaluation;
    public $url;

    use Queueable, SerializesModels;

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

    public function __construct(User $student, $url, $evaluation)
    {
        //
        $this->student = $student;
        $this->evaluation = $evaluation;
        $this->url = $url;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->markdown('emails.concerning-formative');
    }
}

Any ideas what is going on?

Nov
27
2 weeks ago
Activity icon

Replied to Getting Average Scores From Objects In A Collection

@sinnbeck Thanks again, truly appreciate the help in troubleshooting this issue.

Activity icon

Replied to Getting Average Scores From Objects In A Collection

@sinnbeck I think that did it!

$q1 = $collection->avg([$professionalism_Q1]);

Gets 2.7142857142857

And I know how to clean that up.

Thank you so much!

Activity icon

Replied to Getting Average Scores From Objects In A Collection

@goldtaste It gets this error.

"class": "ErrorException", "message": "json_decode() expects parameter 1 to be string, array given",

Activity icon

Replied to Getting Average Scores From Objects In A Collection

@sinnbeck It gets this error:

"class": "Symfony\Component\Debug\Exception\FatalThrowableError", "message": "Call to a member function get() on array",

Activity icon

Replied to Getting Average Scores From Objects In A Collection

"You will probably have to loop through the collection and json_decode each item. In your loop you can build up count and total and use these to calculate average the good old fashioned way."

@goldtaste that is a bit above my skill level, but I understand exactly what you are saying. I used to have this saved separately in their own column rather than as an object and didn't foresee this issue down the road (the old columns are still in the database). Saving as an object helped me clean up code for the view showing the completed form, but made this option much more complicated.

Activity icon

Replied to Getting Average Scores From Objects In A Collection

@sinnbeck I already have it set up like that.

protected $casts = [
        'professionalism_scores' => 'array',
        'communication_scores' => 'array', 
        'analysis_problem_scores' => 'array', 
        'management_knowledge_scores' => 'array'
    ];

So I assume that won't help.

Activity icon

Replied to Getting Average Scores From Objects In A Collection

@goldtaste Yes, that is correct. They are stored from a form like this:

<input required type="radio" name="{{ $form->category }}_scores[{{ $question }}]" value="4">
<label>4</label>

//  stores the value like this, as an object

{"Question":"4"}
Activity icon

Replied to Getting Average Scores From Objects In A Collection

Thank you, here is the full code I'm using to test getting the average.

$student = User::find($id);

// Retrieve the question string
$professionalism_Q1 = EvaluationForm::where('category', 'professionalism')->value('question_1');

// Find all completed evaluations
$evaluations = Evaluation::where('user_id', $student->id)->where('completed', true)->get();

// pluck professionalism scores and filter null values
$collection = $evaluations->pluck('professionalism_scores')->filter();

// testing to see the results of $collection query
return $collection; 

// gives this result
{
"10": {
"Attitude/Presentation: Generally positive attitude/focus on learning.  Appropriate language, behavior, attire.": "2",
"Initiative/Participation: Seeks out learning opportunities. Utilizes down-time effectively.": "2",
"Reliability/Preparedness: Punctual and prepared for shift, including completion of daily goals.": "2",
"Professional Standards: Adheres to scope of practice. Acts in accordance with RT program/ hospital professional conduct.": "2",
"Patient confidentiality: As per CRTO Standards of Practice and hospital policy.": "2"
},
"11": {
"Attitude/Presentation: Generally positive attitude/focus on learning.  Appropriate language, behavior, attire.": "3",
"Initiative/Participation: Seeks out learning opportunities. Utilizes down-time effectively.": "3",
"Reliability/Preparedness: Punctual and prepared for shift, including completion of daily goals.": "3",
"Professional Standards: Adheres to scope of practice. Acts in accordance with RT program/ hospital professional conduct.": "3",
"Patient confidentiality: As per CRTO Standards of Practice and hospital policy.": "3"
},
"12": {
"Attitude/Presentation: Generally positive attitude/focus on learning.  Appropriate language, behavior, attire.": "3",
"Initiative/Participation: Seeks out learning opportunities. Utilizes down-time effectively.": "3",
"Reliability/Preparedness: Punctual and prepared for shift, including completion of daily goals.": "3",
"Professional Standards: Adheres to scope of practice. Acts in accordance with RT program/ hospital professional conduct.": "3",
"Patient confidentiality: As per CRTO Standards of Practice and hospital policy.": "3"
},
"13": {
"Attitude/Presentation: Generally positive attitude/focus on learning.  Appropriate language, behavior, attire.": "3",
"Initiative/Participation: Seeks out learning opportunities. Utilizes down-time effectively.": "3",
"Reliability/Preparedness: Punctual and prepared for shift, including completion of daily goals.": "3",
"Professional Standards: Adheres to scope of practice. Acts in accordance with RT program/ hospital professional conduct.": "3",
"Patient confidentiality: As per CRTO Standards of Practice and hospital policy.": "3"
},
"14": {
"Attitude/Presentation: Generally positive attitude/focus on learning.  Appropriate language, behavior, attire.": "2",
"Initiative/Participation: Seeks out learning opportunities. Utilizes down-time effectively.": "2",
"Reliability/Preparedness: Punctual and prepared for shift, including completion of daily goals.": "2",
"Professional Standards: Adheres to scope of practice. Acts in accordance with RT program/ hospital professional conduct.": "2",
"Patient confidentiality: As per CRTO Standards of Practice and hospital policy.": "2"
},
"15": {
"Attitude/Presentation: Generally positive attitude/focus on learning.  Appropriate language, behavior, attire.": "3",
"Initiative/Participation: Seeks out learning opportunities. Utilizes down-time effectively.": "3",
"Reliability/Preparedness: Punctual and prepared for shift, including completion of daily goals.": "2",
"Professional Standards: Adheres to scope of practice. Acts in accordance with RT program/ hospital professional conduct.": "3",
"Patient confidentiality: As per CRTO Standards of Practice and hospital policy.": "3"
},
"16": {
"Attitude/Presentation: Generally positive attitude/focus on learning.  Appropriate language, behavior, attire.": "3",
"Initiative/Participation: Seeks out learning opportunities. Utilizes down-time effectively.": "3",
"Reliability/Preparedness: Punctual and prepared for shift, including completion of daily goals.": "3",
"Professional Standards: Adheres to scope of practice. Acts in accordance with RT program/ hospital professional conduct.": "3",
"Patient confidentiality: As per CRTO Standards of Practice and hospital policy.": "3"
}
}

When I try to get the average for the first question:

// average the score for the first question
$q1 = $collection->avg($professionalism_Q1);

// check the results of the average
return $q1;

// Gives

0

If I put the string in also it gives 0.

$student = User::find($id);

// Retrieve the question string
$professionalism_Q1 = EvaluationForm::where('category', 'professionalism')->value('question_1');

// Find all completed evaluations
$evaluations = Evaluation::where('user_id', $student->id)->where('completed', true)->get();

// pluck professionalism scores and filter null values
$collection = $evaluations->pluck('professionalism_scores')->filter();

// average the score for the first question
$q1 = $collection->avg("Attitude/Presentation: Generally positive attitude/focus on learning.  Appropriate language, behavior, attire.");

// check the results of the average
return $q1;

// Gives

0

Activity icon

Replied to Getting Average Scores From Objects In A Collection

Result says 0. I can even put a random string in the avg() and it doesn't throw an error, just says 0.

Activity icon

Replied to Getting Average Scores From Objects In A Collection

This is what that gets:

array:5 [▼
  10 => array:5 [▼
    "Question One" => "3"
    "Question Two" => "2"
    "Question Three" => "2"
    "Question Four" => "2"
    "Question Five" => "2"
  ]
  11 => array:5 [▼
     "Question One" => "3"
    "Question Two" => "4"
    "Question Three" => "3"
    "Question Four" => "3"
    "Question Five" => "4"
  ]
  12 => array:5 [▼
     "Question One" => "3"
    "Question Two" => "3"
    "Question Three" => "2"
    "Question Four" => "4"
    "Question Five" => "4"
  ]
  13 => array:5 [▼
     "Question One" => "3"
    "Question Two" => "4"
    "Question Three" => "4"
    "Question Four" => "4"
    "Question Five" => "4"
  ]
  14 => array:5 [▼
     "Question One" => "4"
    "Question Two" => "4"
    "Question Three" => "4"
    "Question Four" => "4"
    "Question Five" => "4"
  ]
]

It starts at 10 because I filter out null rows.

Activity icon

Replied to Getting Average Scores From Objects In A Collection

But my pluck does not return it that way, should I do a replace function to change the values?

Activity icon

Replied to Getting Average Scores From Objects In A Collection

Sorry, I may not be using the right terms, so it works if you do this for each item in Tinker?

{
"Question One": "4",
"Question Two": "3",
"Question Three": "4",
"Questions Four": "2",
"Question Five": "1"
}

Instead of this:

[
"Question One" => "4",
"Question Two" => "2",
"Question Three" => "4",
"Questions Four" => "2",
"Question Five" => "1"
]
Activity icon

Replied to Getting Average Scores From Objects In A Collection

But you are wrapping the questions in array [ ]. They are an objects when plucked so the collection is an array of objects [{},{},{}] Also, it is Question One:4 separated by : not =>

Activity icon

Replied to Getting Average Scores From Objects In A Collection

The result says 0 even though the average score is 3. Even if I use sum() I get 0. The lowest score is 3 (out of 4) in the database, so it makes no sense. If I substitute any random string in the avg("string") I get the same result of 0, so something is not right.

Activity icon

Replied to Getting Average Scores From Objects In A Collection

Unfortunately, none of these work. To clarify, the collection is obtained by using pluck to get the values of a column. But the values are saved as an object.

This is how the value of question_answers is stored:

{
"Question One": "4",
"Question Two": "3",
"Question Three": "4",
"Questions Four": "2",
"Question Five": "1"
}

So the example above is the result of pluck .

$collection = Model::where(‘user_id’, $id)->pluck(‘question_answers’);

// results are

[
{
"Question One": "4",
"Question Two": "3",
"Question Three": "4",
"Questions Four": "2",
"Question Five": "1"
},
{
"Question One": "4",
"Question Two": "3",
"Question Three": "4",
"Questions Four": "2",
"Question Five": "1"
},
{
"Question One": "4",
"Question Two": "3",
"Question Three": "4",
"Questions Four": "2",
"Question Five": "1"
}
]

Nov
26
2 weeks ago
Activity icon

Started a new Conversation Getting Average Scores From Objects In A Collection

I have a collection of questions and values (scores), and I'd like to get the average of all values for a specific question, but I'm worried that saving them as an object has made this difficult. Is there a way to average these?

Here is an example of how the collection appears:

[
{
"Question One": "4",
"Question Two": "3",
"Question Three": "4",
"Questions Four": "2",
"Question Five": "1"
},
{
"Question One": "3",
"Question Two": "2",
"Question Three": "1",
"Questions Four": "3",
"Question Five": "3"
},
{
"Question One": "3",
"Question Two": "3",
"Question Three": "2",
"Questions Four": "4",
"Question Five": "2"
}
]

I want to get the average scores for Question One, the average scores for Question Two, etc.

Any help would be amazing. Thank you.

Nov
20
3 weeks ago
Activity icon

Replied to Merge Plucked Arrays

@nakov Perfect. Thank you! (it does return as a collection, I also added ->sort()->values() to extract only the values)

Activity icon

Started a new Conversation Merge Plucked Arrays

I'm having trouble doing something I thought would be simple. I want to pluck the values of a column that stores an array, merge them into one array, and remove any duplicate values.

Here are my plucked values (I'm using Laravel v. 5.6):

$plucked_values = $all_cases->pluck('area_codes');

// returns this  

[["A1","A3","A5"],["A3","A7","A9"],["A1","A3","A8","A9","A10"]];

I've gotten close with str_replace and implode/exploding values, but I still end up with some duplicates. There must be a simple way to do combine them all and remove the duplicates.

Any suggestions?