MarkyzZz

MarkyzZz

Member Since 1 Year Ago

Experience Points 10,430
Experience Level 3

4,570 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 89
Lessons
Completed
Best Reply Awards 2
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

04 Apr
1 month ago

MarkyzZz left a reply on Any Ideas How To Extract Certain Fields After A GroupBy() On A Collection?

@XSECRETS - Sorry for the long response. I've already tried that and didn't achieve what i wanted. I ended up doing a double map on the javascript side to remove the keys inside the objects and the keys inside the array that are grouped by. Not much what can I do here.

02 Apr
1 month ago

MarkyzZz left a reply on Any Ideas How To Extract Certain Fields After A GroupBy() On A Collection?

@XSECRETS - Yes i want them grouped by scooter_id and without this field in the collection. If i remove the scooter_id from select at the Query level, i won't be able to group them properly at the Collection level.

MarkyzZz started a new conversation Any Ideas How To Extract Certain Fields After A GroupBy() On A Collection?

$gpsdata = Gpsdata::select(['scooter_id', 'lat', 'long'])
->whereIn('scooter_id', $scooter_ids);
->get()
 ->groupBy('scooter_id');

All good, but i don't have any idea how to extract only lat, long fields after groupBy().

Example output:

Illuminate\Database\Eloquent\Collection {#1099
     all: [
       34 => Illuminate\Database\Eloquent\Collection {#1053
         all: [
           App\Models\Gpsdata {#1071
             scooter_id: 34,
             lat: "47.057042",
             long: "28.885650",
           },   
        App\Models\Gpsdata {#1142  
        scooter_id: 34,          
        lat: "47.052042",        
        long: "28.893650",       
          },                                              
     ],
       },
       35 => Illuminate\Database\Eloquent\Collection {#1054
         all: [
           App\Models\Gpsdata {#1082
             scooter_id: 35,
             lat: "47.051042",
             long: "28.861650",
           },
      App\Models\Gpsdata {#1081
             scooter_id: 35,        
             lat: "47.076042",      
             long: "28.863650",     
      },     
    ]
      }
    ]
  }     

22 Mar
2 months ago

MarkyzZz left a reply on Simple Search

@ERIKTOBBEN - By using multiple ->where() you combine conditions with AND operator. By using ->orWhere() you combine conditions with OR operator. So i think it matters which one you use. But in your line its okay if you use where because this condition will always be applied.

MarkyzZz left a reply on Getting Null In Eloquent Relation Data After 3 Records !

i think the problem is that the relationship foreign keys are not set right. The second argument of hasOne() should be the explicit foreign key, which in this case is set as the id of the table Article, where it should be the moderator_id or the author_id. And if i understand correctly, the article belongs to a User that can be an Author or a Moderator. Try this and see if it works: Article model:

public function author()
{
    return $this->belongsTo(User::class, 'author_id');
}

public function moderator()
{
    return $this->belongsTo(User::class, 'moderator_id');
}

And in your User Model:

public function articleAsAuthor()
{
    return $this->hasOne(Article::class, 'author_id');
}

public function articleAsModerator()
{
    return $this->hasOne(Article::class, 'moderator_id');
}

MarkyzZz left a reply on Issue Checking If Variables Exist On Database

$events = Event::all()->isCompleted()->get();
        return view('events.approval.index', compact('events'));

Here you are extracting all events which returns a Collection of Events. To filter the records i suggest you do this:

$events = Event::get()->filter(function($event){
    return $event->isCompleted();
});

Checkout this doc: https://laravel.com/docs/5.5/collections#method-filter

MarkyzZz left a reply on How Can I Refactor This Queries To Get The Number Of Specific Users

Extract to a scope in your User model:

public function scopeWhereRole($query, $role){
    return $query->whereHas("roles", function($q){ $q->where("name",$role); });
}   

This way you are making it chainable, reusable and more readable :)

$PremiumUser = User::whereRole("Premium-Subscriber")->count();
$PremiumUser = User::whereRole("Subscriber")->count();

MarkyzZz left a reply on Should A Scope Return The Builder?

Not quite sure what you're trying to achieve, but the where clause is returning an instance of the QueryBuilder so you can chain multiple queries. If you don't return an instance of query builder, you are losing the ability to chain multiple queries.

21 Mar
2 months ago

MarkyzZz left a reply on Is It Possible To Check For Model Relation In Where Clause?

This will extract all the products with the $product_name and with the specific $marketplace_name:

Product::
whereHas('marketplace', function($query){ 
    $query->where('name', $marketplace_name); // market place query
})
->where('name', $product_name)
->get()

MarkyzZz left a reply on Laravel Training

Hi my name is MarkyzZz and i am a banana.

MarkyzZz left a reply on Method Delete Does Not Exist.

$po_item = POItem::where('cost_item_id', $cost_item->id)->get(); will return a collection of items. I assume you want to delete records from DB. If that's the case, you have to apply the ->delete() method on the query builder like so: $po_item = POItem::where('cost_item_id', $cost_item->id)->delete();

15 Mar
2 months ago

MarkyzZz left a reply on Check If Polymorphic Relation Exists Returns Empty

@RICHARD - I was looking to store both notifications and notification histories in same table. Both of these have almost the same columns, except for the notification history that has one more column "status". I didn't want to create another table only because of one column difference. Apparently, by creating another table and storing the notification histories apart solves my problem in the way you mentioned. Thank you very much :))

MarkyzZz left a reply on Check If Polymorphic Relation Exists Returns Empty

@STAUDENMEIR - The problem with this approach is that the Notification will always have an emitter_id though the model with this emitter_id might not exist.

MarkyzZz started a new conversation Check If Polymorphic Relation Exists Returns Empty

Basically, i have model Notification that morphs to two other models (Company and Scooter), i called them "the emitter". The problem is that i cannot get the notification for the companies or scooters that exist. It always returns me empty collection. This is my code: Notification.php :

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

Scooter.php and Company.php:

public function notifications()
{
    return $this->morphMany(Notification::class, 'emitter');
}

migration:

Schema::create('notifications', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('emitter_id')->unsigned()->index()->nullable();
            $table->string('emitter_type')->nullable();
            $table->timestamps();
        });

And the queries i've tried:

$notification = Notification::has('emitter')->get(); // returns empty collection
$notification = Notification::whereHas('emitter', function($inner_query){ return $inner_query; })->get(); //same
12 Sep
8 months ago

MarkyzZz left a reply on Laravel Polymorphic Relationship On Same Table (different User Managers)

@Vilfago

public function managedByArea()
    {
        return $this->hasMany(User::class, 'area_manager_id');
    }

    public function area_manager()
    {
        return $this->belongsTo(User::class, 'area_manager_id');
    }

    public function managedByCountry()
    {
        return $this->hasMany(User::class, 'country_manager_id');
    }

    public function country_manager()
    {
        return $this->belongsTo(User::class, 'country_manager_id');
    }
    public function managedByFleet()
    {
        return $this->hasMany(User::class, 'fleet_manager_id');
    }

    public function fleet_manager()
    {
        return $this->belongsTo(User::class, 'fleet_manager_id');
    }

This is the solution i've come so far. Thanks for the reply! Saved myself alot of time and headaches :).

11 Sep
8 months ago

MarkyzZz started a new conversation Laravel Polymorphic Relationship On Same Table (different User Managers)

I have the users table, where each user can be assigned to a manager. I have 3 types of Managers (Country Manager, Area Manager and Fleet Manager). One Area manager can have many Fleet Manager and Country Manager, and one Country Manager can have many Fleet Manager. My users table have the columns fleet_manager_id, country_manager_id,area_manager_id that reference on id of users table. The question is that i don't know how to set a polymorphic relationship on same table. Migration:

Schema::table('users', function (Blueprint $table) {
    $table->integer('fleet_manager_id')->unsigned()->nullable();
    $table->foreign('fleet_manager_id')->references('id')->on('users');
    $table->integer('country_manager_id')->unsigned()->nullable();
    $table->foreign('country_manager_id')->references('id')->on('users');
    $table->integer('area_manager_id')->unsigned()->nullable();
    $table->foreign('area_manager_id')->references('id')->on('users');
});

My User Model:

public function fleetManagers()
{
    return $this->hasMany(User::class, 'fleet_manager_id');
}

public function countryManager()
{
    return $this->belongsTo(User::class, 'country_manager_id');
}

public function areaManager()
{
    return $this->belongsTo(User::class, 'area_manager_id');
}