junaidqadir

junaidqadir

Web Developer at University of Turbat

Member Since 2 Years Ago

Turbat

Experience Points
31,700
Total
Experience

3,300 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
307
Lessons
Completed
Best Reply Awards
0
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.

Level 7
31,700 XP
Jun
19
1 month ago
Activity icon

Started a new Conversation What Is The Best Way To Get The Base Path Of The Package From Within The Package?

What is the best way to get the base path of the package from within the package? Sort of base_path() but from the package.

Thanks in advance

Activity icon

Replied to App_path() In A Package

It's a helper function which is an alias for app()->basePath(). helpers.php can be found in Illuminate/Foundation

May
01
3 months ago
Activity icon

Replied to Laravel Relations With Composite Foreign Keys

Sorry, I'm still looking for a hand

Apr
29
3 months ago
Activity icon

Started a new Conversation Laravel Relations With Composite Foreign Keys

Here's what I want to achieve, we have Staff and every staff can have one Position for a department, as well as one Designation for a department and multiple Additional Charges for multiple departments, one department per Additional Charge. And I want to store all the responsibilities in the staff_responsibilities table

I have a staff table with the following columns

  • id
  • name
  • email

Then I have staff_responsibilities table with the following columns:

  • staff_id
  • designation_id
  • department_id
  • responsibility_type_id

Responsibility types can be Position and Additional Charge and one staff can have multiple designations with Additional Charge responsibility.

Then I have a responsibility_types table with the following columns:

  • id
  • name

// I have no way to tell this relationship to look for a responsibility type 2 (2 is the id of the responsibility called `Designation`) 

public function designation()
    {
        return $this->hasOne(StaffResponsibility::class);
    }

// I have no way to tell this relationship to look for a responsibility type 2 
    public function position()
    {
        return $this->hasOne(StaffResponsibility::class);
    }

// Gives error: Syntax error or access violation: 1066 Not unique table/alias: 'staff_responsibilities' 
    public function additionalCharges()
    {
        return $this->belongsToMany(StaffResponsibility::class, 'staff_responsibilities','designation_id');
    }

Any help would really be appreciated.

staff_responsibilities table

staff_responsibilities

responsibility_types table

responsibility_types table

designations table

designations table

Update

// StaffResponsibility Model (StaffResponsibility.php)

class StaffResponsibility extends Model
{

    public function scopeDesignation($query)
    {
        return $query->where('responsibility_type_id', '=', 2);
    }

    public function scopePosition($query)
    {
        return $query->where('responsibility_type_id', '=', 1);
    }

    public function scopeAdditionalCharges($query)
    {
        return $query->where('responsibility_type_id', '=', 3);
    }

    public function designation()
    {
        return $this->belongsTo(Designation::class);
    }

    public function position()
    {
        return $this->belongsTo(Designation::class, null, null, 'designation');
    }

    public function additionalCharge()
    {
        return $this->belongsTo(Designation::class, null, null, 'designation');
    }

    public function department()
    {
        return $this->belongsTo(Designation::class);
    }
}
//Staff Model (Staff.php)
class Staff extends Model
{

   // Rest of the model

    public function designation()
    {
        return $this->hasOne(StaffResponsibility::class)->designation();
    }

    public function position()
    {
        return $this->hasOne(StaffResponsibility::class)->position();
    }

    public function additionalCharges()
    {
        return $this->hasMany(StaffResponsibility::class)->additionalCharges();
    }

    public function getPhotoPathAttribute()
    {
        if (!array_key_exists('photo', $this->attributes) || !$this->attributes['photo']) {
            return null;
        }
        $imagePath = config('filesystems.disks.staff_uploads.root');
        return $imagePath . $this->attributes['photo'];
    }

    // Rest of the model

}

This is how I have to use the reslations:

    echo $staff->position->position->name;

    echo $staff->designation->designation->name;

    echo  $staff->additionalCharges[0]->additionalCharge->name;

This looks really clunky and ugly to me.

And I have no idea if I can update the models or not, even if it is possible it will be equally messy.

Mar
22
4 months ago
Activity icon

Commented on Make The Timeline Dynamic

Pretty basic video for me but still I learned a few new things. And that's why I'm here. Thanks!

Mar
11
4 months ago
Activity icon

Replied to Laravel Is A Giant Waste Of Time

Holds true for any modern stack

Mar
02
5 months ago
Activity icon

Commented on Supercharged Blade Components

Beautiful!

Feb
25
5 months ago
Activity icon

Commented on Limit Access To Authorized Users

Can you please make a video specifically for view and viewAny policy methods. Those tend to confuse me. Thanks in advance

Feb
08
5 months ago