Corbin

Member Since 5 Years Ago

Experience Points
36,810
Total
Experience

3,190 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
366
Lessons
Completed
Best Reply Awards
1
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.

  • Community Pillar

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

Level 8
36,810 XP
Mar
04
2 months ago
Activity icon

Awarded Best Reply on Custom Validation For JSON Not Working

I needed to add integer to the validation rules

Activity icon

Replied to Custom Validation For JSON Not Working

I needed to add integer to the validation rules

Mar
03
2 months ago
Activity icon

Replied to Custom Validation For JSON Not Working

Do you mean like I am in my original code?

$record =Record::create([/*inputs*/]);

return new RecordResource($record);

Mar
02
2 months ago
Feb
28
2 months ago
Activity icon

Replied to Custom Validation For JSON Not Working

Would it be cool if I post a repo tomorrow?

Activity icon

Replied to Custom Validation For JSON Not Working

It seems like everything is okay.

I tried breaking the code:

$validation = \Validator::make($data, [
            'las;lld;asd*.id' => 'between:1,70|123kpfkdskfsfds',
            '*.intensity' => 'between:0,100',
            '*.new_intensity' => 'between:0,100'
        ]);

And nothing happened. Is it possible Validator::make isn't working?

Activity icon

Replied to Custom Validation For JSON Not Working

Yeah, it's not throwing a 422 and I'm getting the RecordResource returned to me. I'm getting a 200 status.

Activity icon

Started a new Conversation Custom Validation For JSON Not Working

I'm posting to api/record that's suppose to catch validation errors in the JSON that I intentionally set:

Vue AJAX

this.$http({
    method: 'POST',
    url: 'api/record',
    data: {
        emotions: [{'id': 1001, 'intensity': 20, 'new_intensity': 50}],//this.selectedEmotions,
        distortions: [{'id': 1001}],//this.selectedDistortions,
        situation: this.situation,
    }
})

RecordController.php

public function store(Request $request)
{
    $this->validate($request, [
            'situation' => 'required',
        ]);
       
        $emotions = ['data' => $request->input('emotions')];

        $emotionsValidation = \Validator::make($emotions, [
            'data.*.id' => 'between:1,70',
            'data.*.intensity' => 'between:0,100',
            'data.*.new_intensity' => 'between:0,100'
        ]);

        if($emotionsValidation->fails()) {
             //return $validation->errors(); Gets all errors
            return response(['error' => 'There was a problem'],422);
        }
        
        $data = ['data' => $request->input('emotions')];

        $distortionsValidation = \Validator::make($data, [
            'data.*.id' => 'between:1,14',
        ]);

        if($distortionsValidation->fails()) {
             //return $validation->errors(); Gets all errors
            return response(['error' => 'There was a problem'],422);
        }
    
    //store record

    return new RecordResource($record);
}

The problem I'm having is that my validation isn't failing when it should be. How do I fix this?

Jan
18
4 months ago
Activity icon

Replied to Structuring The SQL JSON Data Type And Adding New Key Values To The Output Using An Api Resource?

Just expanding on @newbie360 answer. Here's the code:

Record.php

class Record extends Model
{
    use HasFactory;

    /*protected $casts = [
        'emotions' => 'json',
    ];*/

    public $emtionsLabels = ['Happy', 'Sad'];

    public function getEmotionsAttribute($value)
    {
        $emotions = json_decode($value, true);
        foreach($emotions as $emotion){
            $newEmotions[] = 
                [
                    'intensity' => $emotion['intensity'],
                    'new_intensity' => $emotion['newIntensity'],
                    'emotion_id'=> $emotion['emotion_id'],
                    'label' => $this->emtionsLabels[$emotion['emotion_id'] - 1]
                ];
        }

        return collect($newEmotions); 
    }
}
Activity icon

Started a new Conversation Structuring The SQL JSON Data Type And Adding New Key Values To The Output Using An Api Resource?

I'm trying to add a label that is matched to an array on my records model and an is_picked: false to the json emotions collection in an API resource:

** Example Current Output**

"data":[
   {
      "id":91,
      "title":"Temporibus sed ut voluptas nesciunt.",
      "emotions":[
         {
            "intensity":10,
            "emotion_id":1,
            "newIntensity":3
         },
         {
            "intensity":10,
            "emotion_id":2,
            "newIntensity":3
         }
      ]
   },
   {
      "id":92,
      "title":"Facilis provident qui tempore sit illum fuga incidunt odio.",
      "emotions":[
         {
            "intensity":10,
            "emotion_id":1,
            "newIntensity":3
         },
         {
            "intensity":10,
            "emotion_id":2,
            "newIntensity":3
         }
      ]
   }
]

Desired Output Example

"data":[
   {
      "id":91,
      "title":"Temporibus sed ut voluptas nesciunt.",
      "emotions":[
         {
            "intensity":10,
            "emotion_id":1,
            "newIntensity":3
            "label": "Happy",
            "is_picked": false
         },
         {
            "intensity":10,
            "emotion_id":2,
            "newIntensity":3
            "label": "Sad",
            "is_picked": false
         }
      ]
   },
   {
      "id":92,
      "title":"Facilis provident qui tempore sit illum fuga incidunt odio.",
      "emotions":[
         {
            "intensity":10,
            "emotion_id":1,
            "newIntensity":3
            "label": "Happy",
            "is_picked": false
         },
         {
            "intensity":10,
            "emotion_id":2,
            "newIntensity":3
            "label": "Sad",
            "is_picked": false
         }
      ]
   }
]

My Record Table

Schema::create('records', function (Blueprint $table) {
    $table->id();
    $table->text('title')->nullable();
    $table->json('emotions')->nullable();
    $table->timestamps();
});

Model

class Record extends Model
{
    use HasFactory;

    protected $casts = [
        'emotions' => 'json',
    ];

    public $emtionsLabels = ['Happy', 'Sad'];
}

I was able to structure the JSON output for the emotions to be closer to the Desired Output Example in the Controller:

class RecordController extends Controller
{
    public function index()
    {

        $emotions = Record::first()->emotions;

        $phpRecords = json_decode($emotions, true);

        $newEmotions;
        $record = new Record();
        $labels = $record->emtionsLabels;
        foreach($phpRecords as $emotion){
            $newEmotions[] = 
                [
                    'intensity' => $emotion['intensity'],
                    'new_intensity' => $emotion['newIntensity'],
                    'emotion_id'=> $emotion['emotion_id'],
                    'label' => $labels[$emotion['emotion_id'] - 1]
		    'is_picked' => false
                ];
        }

        return collect($newEmotions);

    }
}

Now what I'm trying to figure out is how to format that json output in my API RecordResource, or Record model, to be the similar to the code in my controller example:

Current RecordResource

class RecordResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'emotions' => $this->emotions
        ];
    }
}
Jan
16
4 months ago
Activity icon

Replied to Airlock + Safari Issues

Are you still having issues? Or has it changed?

Dec
29
4 months ago
Activity icon

Started a new Conversation What Are The Steps For Deploying A Vue SPA With A Laravel Backend On Forge?

I have Laravel/Vue SPA using Laravel Sanctum. Both the Frontend and backend have their own repository. What would be the rough steps for deploying something like this using Laravel Forge?

I've never deployed a SPA before, will this be very hard to do?