abdulaziz

abdulaziz

Member Since 2 Years Ago

Tajikistan Dushanbe

Experience Points
2,910
Total
Experience

2,090 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
5
Lessons
Completed
Best Reply Awards
2
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 1
2,910 XP
Oct
26
2 weeks ago
Activity icon

Replied to Please Help To Fetch Certain Data

Mr @snapey can you help me please

Activity icon

Replied to Please Help To Fetch Certain Data

Another solution that comes to my mind is this:

$features = json_decode($request->feature_with_values);

$result = [];

foreach ($features as $key => $value) {
            $result[] = FeatureValue::where('feature_id', $key)
                                    ->where('value_id', $value)
                                    ->first();
        }
return $result;

So if the input is this:

"feature_with_values": "{"1":1,"2":2,"3":1,"4":2}"

It returns this:

[
{
"id": 5,
"value_id": 1,
"feature_id": 1
},
{
"id": 8,
"value_id": 2,
"feature_id": 2
},
{
"id": 9,
"value_id": 1,
"feature_id": 3
},
{
"id": 12,
"value_id": 2,
"feature_id": 4
}
]

This is exactly what I need but if the number of elements grows in JSON the number of queries will grow too which is not good. Is it possible to achieve such result by using a single query?

Activity icon

Replied to Please Help To Fetch Certain Data

First solution that comes to my mind is this:

$features = json_decode($request->feature_with_values);
        $featureIDs = [];
        $valueIDs = [];

        foreach ($features as $key => $value) {
            $featureIDs[] = $key;
            $valueIDs[] = $value;
        }
$featureValues = FeatureValue::whereIn('feature_id', $featureIDs)
                                    ->whereIn('value_id', $valueIDs)
                                    ->get();

So if the input is this:

"feature_with_values": "{"1":1,"2":2,"3":1,"4":2}"

and the result of my query is this:

[
{
"id": 5,
"value_id": 1,
"feature_id": 1
},
{
"id": 6,
"value_id": 2,
"feature_id": 1
},
{
"id": 7,
"value_id": 1,
"feature_id": 2
},
{
"id": 8,
"value_id": 2,
"feature_id": 2
},
{
"id": 9,
"value_id": 1,
"feature_id": 3
},
{
"id": 10,
"value_id": 2,
"feature_id": 3
},
{
"id": 11,
"value_id": 1,
"feature_id": 4
},
{
"id": 12,
"value_id": 2,
"feature_id": 4
}
]

so as you can see I am getting all features and values that are in the json but the result is not their combination as they are not connected to each other. How to get their combination?

Activity icon

Started a new Conversation Please Help To Fetch Certain Data

Here is the digram of my Database:

https://drive.google.com/file/d/14-aKskgtvuxHXLOVXoWEiLyvN_vIm13k/view?usp=sharing

This is what I get from my post form.:

"feature_with_values": "{"8":1,"9":1,"10":2,"11":2}"

So the key of feature_with_values is feature_id and the value is value_id. For example take a look at first element

"8":1

So in this case 8 is feature_id and 1 is value_id. I need to select FeatureValues from feature_value pivot table (marked green in the digram) that has these combinations of feature_id and value_id that was shown above.

Oct
07
1 month ago
Activity icon

Replied to Latest()->first() Not Working

Oops this code only returns Auth user's message as a last message. But need as a last message: sent by auth or sent to auth ( Trying to fix

Activity icon

Replied to Latest()->first() Not Working

Came up with this. Thanks to all. You are the best!

User.php

    public function latestComment()
    {
        return $this->hasOne('App\Comment','commentable_id')
                    ->where('commentable_type','App\User')
                    ->latest();
    }

Controller

        $messagedUsers = User::whereHas('latestComment',function(Builder $query){
            $query->where('commentable_id', auth()->user()->id)
                  ->orWhere('user_id', auth()->user()->id); 
        })->with('latestComment')
        ->get();
Oct
04
1 month ago
Activity icon

Replied to Latest()->first() Not Working

auth()->user()->id?

Yes I have this code right now. He wanted me to change it to auth()->user()

Activity icon

Replied to Latest()->first() Not Working

Figured out something: In my result I am getting all User that I have chated with but only one of those Users has last comment attached it. So maybe latest()->first() is working after all but not the way it suppose to?

Activity icon

Replied to Latest()->first() Not Working

auth()->user() return User himself with all fields but I need only ID to compare. Thats why auth()->user() wont work

Activity icon

Replied to Latest()->first() Not Working

same thing (

Activity icon

Replied to Latest()->first() Not Working

I have a comments model that has One To Many Polymorphic relationship to models like Task, Product, Chat and User. This is what my Comment looks like:

create_comments_table.php

Schema::create('comments', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('commentable_id');
            $table->string('commentable_type');
            $table->text('body');
            $table->timestamps();
        });

user_id is sender of comment

Comment.php

protected $fillable = ['user_id', 'body', 'commentable_id', 'commentable_type'];

protected $with = ['sender'];

public function commentable()
{
         return $this->morphTo();
}

public function sender()
{
        return $this->belongsTo('App\User','user_id');
}

Chat.php

public function comments()
    {
        return $this->morphMany('App\Comment','commentable');
    }

User.php

public function comments()
    {
        return $this->morphMany('App\Comment','commentable');
    }

As you can see Chat and User have comments. So what I am trying to do is:

Get list of Users that I have sent or received messages from with last message attached to the result (doesn't matter sent by him or me) so that I can sort Users by last message date later on

$messagedUsers = User::
        with(['comments' => function ($query) {
            $query->latest()->take(1); // last message doesnt matter whose 
        }])
        ->whereHas('comments', function (Builder $query) {
            $query->where('user_id', auth()->user()->id) // sent by me
                  ->orWhere('commentable_id', auth()->user()->id); // sent to me
        })
        ->get();
Activity icon

Replied to Latest()->first() Not Working

Yes I did. The same thing empty array of comments

Activity icon

Started a new Conversation Latest()->first() Not Working

Hi! When I run this query :

User::
        with(['comments' => function ($query) {
            $query->latest();
        },'department'])
        ->whereHas('comments', function (Builder $query) {
            $query->where('from_id', auth()->user()->id)
                  ->orWhere('to_id', auth()->user()->id);
        })
        ->get();

I get an array of Users where the first User has 3 comments. But when add first() after latest() like so:

User::
        with(['comments' => function ($query) {
            $query->latest()->first();
        },'department'])
        ->whereHas('comments', function (Builder $query) {
            $query->where('from_id', auth()->user()->id)
                  ->orWhere('to_id', auth()->user()->id);
        })
        ->get();

First User has an empty array of comments. Also if I try to get only one User like so:

User::
        with(['comments' => function ($query) {
            $query->latest()->first();
        },'department'])
        ->whereHas('comments', function (Builder $query) {
            $query->where('from_id', auth()->user()->id)
                  ->orWhere('to_id', auth()->user()->id);
        })
        ->first();

Last comment is present. I dont understand such behaviour. What am I doing wrong? Please help

Sep
17
1 month ago
Activity icon

Replied to How To Get Rating Average?

@ashraam Thank you! You are the best!

Activity icon

Started a new Conversation How To Get Rating Average?

I have Business model which has the reviews relationships. Review has rating field in it which is integer between 1 and 5. I needed to get Businesses with their reviews ordered by number of reviews. This worked for me:

Business::withCount('reviews')
        ->orderBy('reviews_count','DESC')
        ->with(['images','category','tags','reviews'])
        ->paginate(30);

But I cant figure out how to get the same thing ordered by rating average. Please help