MarkyzZz

MarkyzZz

Member Since 1 Year Ago

Experience Points 10,510
Experience Level 3

4,490 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-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.

05 Jun
1 month ago

MarkyzZz left a reply on Approach Question On Multi-step Form Ajax Laravel

@BOBBYBOUWMANN - Guess i don't have much time to think about which solution is better so I'm gonna stick with this one. Thank you! :)

04 Jun
1 month ago

MarkyzZz left a reply on Approach Question On Multi-step Form Ajax Laravel

@JLRDW - Not really. It would take me too much time. I have already implemented the create method with this wizard

MarkyzZz left a reply on Approach Question On Multi-step Form Ajax Laravel

@BOBBYBOUWMANN - Yea, that's basically what i did when i made the create method. But when editing, i don't know at which point should i validate and send. I am using the FuelUX Wizard. https://getfuelux.com/javascript.html#wizard . Not quite sure, should I validate each step in particular, which involves validating and sending an ajax request each time the user clicks on a step in the wizard which doesn't seem quite right for me, OR, should I send everything on the last step, which doesn't seem right for me too because i have to call those 5 endpoints i made earlier.

MarkyzZz started a new conversation Approach Question On Multi-step Form Ajax Laravel

I have a multi-step form that consist of five steps. On create, each form in each step is validated(validation occurs when you click on next step button) and if it is valid it sends an ajax request to store the data on the database. However, on edit, i need to make it somehow, so the user can click on any of the steps, and each form must be validated too. Any ideas how to do it?

04 Apr
3 months 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
3 months 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
3 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
3 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
4 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
10 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
10 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');
}