4unkur

4unkur

Web Developer at Intelliants

Member Since 1 Year Ago

Bishkek

Experience Points
6,090
Total
Experience

3,910 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
44
Lessons
Completed
Best Reply Awards
0
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
6,090 XP
Nov
20
16 hours ago
Activity icon

Started a new Conversation Browser's Back Button Works Like Ajax Request

I have CartController:

public function index(Request $request)
{
    if ($request->wantsJson()) {
        return CartItemResource::collection(cart()->content());
    }

    return view('cart.index');
}

When a user navigates to /cart he sees cart page. Items loaded via ajax. Everything works fine except when user navigates to checkout page (or any page) and then presses browser's back button, he sees json response. i.e. Laravel thinks that user was requesting the /cart endpoint via ajax so it returns json.

Why it's happening and how can I fix this?

Nov
15
5 days ago
Activity icon

Started a new Conversation How To Use Eloquent Resources Properly?

I have Product model & ProductResource in ProductResource:

public function toArray($request)
{
    return [
        'id' => $this->id,
        'category_id' => $this->category_id,
        'color_id' => $this->color_id,
        'created_at' => $this->created_at,
        'description' => $this->description,
        'discount_percentage' => $this->discount_percentage,
        'discount_percentage_enabled' => $this->discount_percentage_enabled,
        'featured' => $this->featured,
        'height' => $this->height,
        'length' => $this->length,
        'material_id' => $this->material_id,
        'media' => $this->media,
        'price' => $this->price,
        'price_formatted' => $this->price_formatted,
        'quantity' => $this->quantity,
        'sale_price_formatted' => $this->sale_price_formatted,
        'sale_price_enabled' => $this->sale_price_enabled,
        'short_description' => $this->short_description,
        'slug' => $this->slug,
        'title' => $this->title,
        'translations' => $this->translations,
        'updated_at' => $this->updated_at,
        'views_count' => $this->views_count,
        'width' => $this->width,
        'small_image_url' => $this->getImageUrl(Product::CONVERSION_SMALL),
        'medium_image_url' => $this->getImageUrl(Product::CONVERSION_MEDIUM),
        'url' => route('product.show', $this),
    ];
}

All what it does is: adds the last 3 attributes, the rest is just copying the attributes from model to the resource. How can I manage this in more elegant/efficient way? i.e. I want whole model + 3 additional attributes

Oct
31
2 weeks ago
Activity icon

Started a new Conversation How To Share The Same Data Between Methods In The Controller?

    public function create()
    {
        $categories = Category::with('subCategories')->get();

        return view('product.create')->with(compact('categories'));
    }


    public function edit(Product $product)
    {
        $categories = Category::with('subCategories')->get();

        return view('product.edit')
            ->with(compact('product', 'categories'));
    }

Here's the controller and as you can see I share the same data between 2 methods. It's a simplified example, in reality there might me a lot more data. How can I make this code DRY? I know about View compose, but it seems not quite applicable for this situation and not that obvious. Maybe there are other ways?

Oct
08
1 month ago
Activity icon

Started a new Conversation Why Timestamps Are Not Used In Jobs Table?

If you use DB as a queue driver and run php artisan queue:table, jobs table will be created and it will have 3 integer columns:

            $table->unsignedInteger('reserved_at')->nullable();
            $table->unsignedInteger('available_at');
            $table->unsignedInteger('created_at');

I'm wondering, why not timestamps?

Here's the stub file: https://github.com/laravel/framework/blob/6.x/src/Illuminate/Queue/Console/stubs/jobs.stub

I already tried to ask it in official repository here: https://github.com/laravel/framework/issues/30213#event-2694725131 and issue got closed almost immediately (I undertsand that)

Any ideas?

Oct
03
1 month ago
Activity icon

Started a new Conversation How To Manage Removable Relationships

I'm not sure if my title is related, but anyway.

In the project, I'm working on (most of the code is written by me), there are some issues with deleted relations. What do you do in order to check the relation existence? Do you write:

@if (!empty($model->relation)) 
  {{ $model->relation->value }} 
@endif

each time, where relation can be deleted?

The worst part is when I try to get a value from chained relations like:

<td>{{ $message->thread->resume->jobCategory->name }}<</td>

Here all 3 relations can be deleted in the admin panel i.e. thread, resume, jobCategory models can be deleted. We have Sentry integration, so I receive quite a lot of Trying to get property 'user' of non-object like exceptions.

I find these exceptions happen mostly in blade files, where I show the information like job category name etc.

Are there any guidelines on how to avoid such issues and manage everything in a way, so you don't fall into exceptions trap?

Jul
25
3 months ago
Activity icon

Replied to Querying Many To Many Relationship Based On Other Many To Many Relationsihp

I did wrote a raw SQL and converted it to Eloquent and here what I got:

$query = Resume::join('language_resume_pivot', 'language_resume_pivot.resume_id', '=', 'resumes.id')
    ->join('resume_languages', 'resume_languages.id', '=', 'language_resume_pivot.language_id');

$languages = $position->languages()->get();
$i = 0;
foreach ($languages as $language) {
    $proficiency = $language->pivot->proficiency;
    if ($i++) {
        if ($proficiency === 'any') {
            $query->orwhere('language_id', $language->id);
        } else {
            $query->orwhere(function ($query) use ($language, $proficiency) {
                $query->where('language_id', $language->id)
                    ->where('proficiency', $proficiency);
            });
        }
    } else {
        if ($proficiency === 'any') {
            $query->where('language_id', $language->id);
        } else {
            $query->where(function ($query) use ($language, $proficiency) {
                $query->where('language_id', $language->id)
                    ->where('proficiency', $proficiency);
            });
        }
    }
}

$query->groupBy('resumes.id')->havingRaw("COUNT(language_resume_pivot.language_id) = $i");

$resumes = $query->get();

This is also not 100% as it doesn't add to count the higher proficiencies. i.e. if user searches for English speaker with basic knowledge, this means that Good, Native speakers should also show up, but the code above checks for exact matching. I'll do it later, that's not that hard

Jul
24
3 months ago
Activity icon

Started a new Conversation Querying Many To Many Relationship Based On Other Many To Many Relationsihp

I'm building a website where users can post their job listings and emlployers can find matching candidates. The website is almost complete, but I need to add some feature, which client requested recently.

In short user can create a resume and select multiple languages, ex: English - native Spanish - basic

and on the other hand employer, who seeks the candidates (it's done by creating positions) have the ability to find only resumes which has matching languages (but level is optional), ex: English - native Spanish - any

I have 3 models: Resume, Position, Language and db is like this:

positions table
resumes table

language_resume table
language_id, resume_id, proficiency

language_position table
language_id, position_id, proficiency

The relationships are: Resume.php

public function languages()
{
    return $this->belongsToMany(Language::class)->withPivot('proficiency');
}

the same for Position.php

So, currently I'm struggling to compose Eloquent query to get all resumes based on positions criterias (languages in this case).

Below code gets all the resumes if at least 1 language matches i.e. my position has English Native, Spanish Any

it will return any resumes with at least English or Spanish. and I need to find only those which have both.

$resumes = Resume::whereHas('languages', function ($query) use ($position) {
    $query->where(function ($query) use ($position) {
        $languages = $position->languages()->get();
        $language = $languages->shift();

        $proficiency = $language->pivot->proficiency;
        if ($proficiency === 'any') {
            $query->where('language_id', $language->id);
        } else {
            $query->where(function ($query) use ($language, $proficiency) {
                $query->where('language_id', $language->id)
                    ->where('proficiency', $proficiency);
            });
        }

        foreach ($languages as $language) {
            $proficiency = $language->pivot->proficiency;
            if ($proficiency === 'any') {
                $query->orWhere('language_id', $language->id);
            } else {
                $query->orWhere(function ($query) use ($language, $proficiency) {
                    $query->where('language_id', $language->id)
                        ->where('proficiency', $proficiency);
                });
            }
        }
    });
});