MarkyzZz

MarkyzZz

Member Since 2 Years Ago

Experience Points
10,660
Total
Experience

4,340 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
90
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 3
10,660 XP
Jun
05
4 months ago
Activity icon

Replied to 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! :)

Jun
04
4 months ago
Activity icon

Replied to 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

Activity icon

Replied to 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.

Activity icon

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.This is how i made the create method. 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?

Apr
04
6 months ago
Activity icon

Replied to 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 operation 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.

Apr
02
6 months ago
Activity icon

Replied to 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.

Activity icon

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",     
      },     
    ]
      }
    ]
  }     

Mar
22
6 months ago
Activity icon

Replied to 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 it doesn't matter which one you use because this condition will always be applied. You should use where in the first condition to avoid confusion though.

Activity icon

Replied to 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');
}
Activity icon

Replied to 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 that are completed 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

A refactoring tip:

if (empty($this->$attribute)) {
            return false;
            }
            return true;
        }

Could be rewritten simpler:

return empty($this->$attribute); //returns whether true or false. You don't have to be explicit about it :))
Activity icon

Replied to 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 :)

$PremiumUsers = User::whereRole("Premium-Subscriber")->count();
$Subscribers = User::whereRole("Subscriber")->count();
Mar
21
6 months ago
Activity icon

Replied to 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();

You should read the docs about querying relationships: https://laravel.com/docs/master/eloquent-relationships#querying-relations

Activity icon

Replied to Laravel Training

Hi my name is MarkyzZz and i am a banana.

Activity icon

Replied to 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();
Mar
15
6 months ago
Activity icon

Replied to 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 :))

Activity icon

Replied to 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.

Activity icon

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->exists(); })->get(); //same

Edit: Forgot to mention that i am using Laravel 5.2

Sep
12
1 year ago
Activity icon

Replied to 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 :).

Sep
11
1 year ago
Activity icon

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');
}