kevinbui

Full Stack Developer at Bitcoin Australia

Member Since 6 Years Ago

Melbourne, Australia

Experience Points
73,560
Total
Experience

1,440 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
595
Lessons
Completed
Best Reply Awards
23
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 15
73,560 XP
Jan
03
2 months ago
Activity icon

Awarded Best Reply on How To Do A Query In Laravel

Lets make some parentheses:

SELECT * 
FROM `conversations` 
WHERE (sender_id = 3 AND receiver_id = 6)
OR (receiver_id = 6 AND sender_id = 3);

Or writing a query in the code:

Conversation::where(function ($query) use ($request) {
    $query->where('sender_id', $request->input('sender_id'))->where('receiver_id', $request->input('receiver_id'));
})->orWhere(function ($query) use ($request) {
    $query->where('sender_id', $request->input('receiver_id'))->where('receiver_id', $request->input('sender_id'));
})
->get();
Activity icon

Replied to Vuex - Do Not Mutate Vuex Store State Outside Mutation Handlers

Which line of code causes the issue?

Activity icon

Replied to Gument 1 Passed To Illuminate\Database\Eloquent\Relations\HasOneOrMany::create() Must Be Of The Type Array

The error happens at this line:

$purchase->productattribute()->createMany([
    'product_id' => $product->id,
    'sku'=>$request->sku,
    'colour'=>$request->colour        
]);

Instead of using the createMany method, pls simply use the create method:

$purchase->productattribute()->create([
    'product_id' => $product->id,
    'sku'=>$request->sku,
    'colour'=>$request->colour        
]);
Activity icon

Replied to How To Do A Query In Laravel

@jimb814 You miss the semicolon ; inside each closure.

Activity icon

Replied to The Array Value Must Be Greater Than The Previous Value

You might want to create custom validation rules for this:

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class ArrayContainsUniqueValues implements Rule
{
    public function passes($attribute, $value)
    {
        return collect($value)->duplicates()->isEmpty();
    }

    public function message()
    {
        return 'The :attribute array contains duplicate values.';
    }
}
namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class ArrayContainsSequentialValues implements Rule
{
    public function passes($attribute, $value)
    {
        return $value == collect($value)->sort()->values()->toArray();
    }

    public function message()
    {
        return 'The :attribute array contains values that are not in sequential order.';
    }
}

Finally, inside the controller, you can say something like:

$request->validate([
    'your_array_field' => ['array', new ArrayContainsUniqueValues, new ArrayContainsSequentialValues]
]);
Activity icon

Replied to How To Do A Query In Laravel

@jimb814 I have updated my answer accordingly above. Pls use the use keyword to include outside objects to be used in a closure.

Activity icon

Replied to How To Do A Query In Laravel

Lets make some parentheses:

SELECT * 
FROM `conversations` 
WHERE (sender_id = 3 AND receiver_id = 6)
OR (receiver_id = 6 AND sender_id = 3);

Or writing a query in the code:

Conversation::where(function ($query) use ($request) {
    $query->where('sender_id', $request->input('sender_id'))->where('receiver_id', $request->input('receiver_id'));
})->orWhere(function ($query) use ($request) {
    $query->where('sender_id', $request->input('receiver_id'))->where('receiver_id', $request->input('sender_id'));
})
->get();
Sep
15
5 months ago
Activity icon

Awarded Best Reply on Counting Records In Categories And Subcategories

We have the following models and relationships:

class Category extends Model
{
    public function subCategories()
    {
        return $this->hasMany(SubCategory::class);
    }
}

class SubCategory extends Model
{
    public function records()
    {
        return $this->hasMany(Record::class);
    }
}

class Record extends Model
{
}

In the controller, you can do something like:

class CategoriesController extends Controller
{
    public function index()
    {
        $categories = Category::with('subCategories.records')->get();

        return view('categories.index', compact('categories'));
    }
}

And finally, in the view, you can say:

@foreach($categories as $category)
    <h1>{{ $category->name }} ({{$category->subcategories->flatMap->records->count()}}):</h1>
    @foreach($category->subCategories as $subCategory)
        <h3>{{ $subCategory->name }} ({{$ subCategory->records->count() }})</h3>
    @endforeach
@endforeach

I believe there are cleaner and more performant approach, but this is gonna achieve your results straightaway.

Activity icon

Replied to Counting Records In Categories And Subcategories

We have the following models and relationships:

class Category extends Model
{
    public function subCategories()
    {
        return $this->hasMany(SubCategory::class);
    }
}

class SubCategory extends Model
{
    public function records()
    {
        return $this->hasMany(Record::class);
    }
}

class Record extends Model
{
}

In the controller, you can do something like:

class CategoriesController extends Controller
{
    public function index()
    {
        $categories = Category::with('subCategories.records')->get();

        return view('categories.index', compact('categories'));
    }
}

And finally, in the view, you can say:

@foreach($categories as $category)
    <h1>{{ $category->name }} ({{$category->subcategories->flatMap->records->count()}}):</h1>
    @foreach($category->subCategories as $subCategory)
        <h3>{{ $subCategory->name }} ({{$ subCategory->records->count() }})</h3>
    @endforeach
@endforeach

I believe there are cleaner and more performant approach, but this is gonna achieve your results straightaway.