neeonline

Member Since 4 Years Ago

Experience Points
37,600
Total
Experience

2,400 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
335
Lessons
Completed
Best Reply Awards
4
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.

  • Community Pillar

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

Level 8
37,600 XP
Mar
26
2 weeks ago
Activity icon

Replied to PostgreSQL Multiple Users

That does not work.

I did try to GRANT ALL PRIVILEGES to both users, migrate:fresh, and the external-user cannot see any tables created in the migration.

Activity icon

Replied to Just Trying To Understand

This is not a guess, it is the right answer =)

When you add a name to a group it gets prefixed to all inner routes.

Activity icon

Replied to Is It Possible To Use `like` With "%" In A Collection ?

You can use the collection filter for that. The filter callback must return a boolean value.

To achieve the SQL like behavior you can use the PHP strpos native function which will return false with the searched value cannot be found:

$collection = collect([
  ['comment' => 'first comment'],
  ['comment' => 'test comment'],
  ['comment' => 'another comment'],
  ['comment' => 'forthy test comment'],
  ['comment' => 'comment test'],
  ['comment' => 'last comment'],
]);

$collection->filter(function ($item) {
  return strpos($item['comment'], 'test') !== false; // If strpos returns anything other than false, means 'test' exists somewhere in the string.
});
Activity icon

Started a new Conversation PostgreSQL Multiple Users

Hey y'all,

I have a PostgreSQL database that should have two users, one will be used locally by Laravel and the other by another app.

My problem is, I've created the database, the two users, and granted all permissions to both. Once I ran the migrations everything works fine on Laravel's side. But the second user cannot see any tables generated by the migration.

Will be nice to know how to give only read/write permissions to the external-user.

Any help is appreciated.

This is the code PostgreSQL code:

su – postgres

psql

CREATE DATABASE "laravel-db";

CREATE USER "laravel-user" WITH PASSWORD '[PASSWORD]';

GRANT ALL ON DATABASE "laravel-db" TO "laravel-user";

CREATE USER "external-user" WITH PASSWORD '[PASSWORD]';

GRANT ALL ON DATABASE "laravel-db" TO "external-user";
Mar
05
1 month ago
Activity icon

Replied to WhereHas Count Based On Column

Found a solution to my problem, if anyone want to see it is here: whereHas/having based on another column.

Activity icon

Awarded Best Reply on WhereHas/having Based On Another Column

Found the solution...

In the end I had to work with a manual left join so I could work with having statement.

public function scopeBelowThreshold(Builder $builder, $option = true): Builder
{
    return $builder->whereNotNull('threshold')
        ->leftJoin('units', 'items.id', '=', 'units.item_id')
        ->whereNull("units.owner_id")
        ->whereNull("units.deleted_at")
        ->havingRaw('count(units.id) ' . ($option ? '<=' : '>') . ' items.threshold')
        ->groupBy('items.id');
}
Activity icon

Replied to WhereHas/having Based On Another Column

Found the solution...

In the end I had to work with a manual left join so I could work with having statement.

public function scopeBelowThreshold(Builder $builder, $option = true): Builder
{
    return $builder->whereNotNull('threshold')
        ->leftJoin('units', 'items.id', '=', 'units.item_id')
        ->whereNull("units.owner_id")
        ->whereNull("units.deleted_at")
        ->havingRaw('count(units.id) ' . ($option ? '<=' : '>') . ' items.threshold')
        ->groupBy('items.id');
}
Activity icon

Replied to WhereHas Count Based On Column

Hello,

I'm having a similar situation. Have you found a solution?

Activity icon

Started a new Conversation WhereHas/having Based On Another Column

Hello all,

In my project I have Items. An item can have many units. A unit can be available or not (based if owner_id is null or not).

Schema::create('items', function (Blueprint $table) {
    $table->uuid('id')->primary();
    $table->foreignUuid('user_id')->constrained()->onDelete('cascade');
    $table->foreignUuid('location_id')->constrained()->onDelete('cascade');
    $table->string('name');
    $table->text('description')->nullable();
    $table->integer('threshold')->nullable();
    $table->timestamps();
    $table->softDeletes();
});

Schema::create('units', function (Blueprint $table) {
    $table->uuid('id')->primary();
    $table->foreignUuid('item_id')->constrained()->onDelete('cascade');
    $table->uuid('owner_id')->nullable();
    $table->timestamps();
    $table->softDeletes();

    $table->foreign('owner_id')->references('id')->on('users')->onDelete('cascade');
});

On my Unit model I have a local scope that works like a charm:

public function scopeAvailable(Builder $builder, $option = true): Builder
{
    return $option ? $builder->whereNull('owner_id') : $builder->whereNotNull('owner_id');
}

With that in mind, I need to know which items have fewer available units than their threshold. The following code works as an example:

public function scopeBelowThreshold(Builder $builder, $option = true): Builder
{
    return $builder->whereNotNull('threshold')->whereHas('units', function ($query) use ($option) {
        $query->whereNull('owner_id'); // Available Unit
    }, $option ? '<' : '>', 10); // Note that 10 is hardcoded
}

What I need to do is use the threshold value instead of the hardcoded value, something like:

public function scopeBelowThreshold(Builder $builder, $option = true): Builder
{
    return $builder->whereNotNull('threshold')->whereHas('units', function ($query) use ($option) {
        $query->whereNull('owner_id');
    }, $option ? '<' : '>', 'threshold');
}

This does not work since whereHas expects the third parameter to be an int.

I also tried to use withCount:

public function scopeBelowThreshold(Builder $builder, $option = true): Builder
{
    return $builder->whereNotNull('threshold')->withCount(['units as available_units_count' => function ($query) {
        $query->whereNull('owner_id');
    }])->whereColumn('available_units_count', $option ? '<' : '>', 'threshold');
}

But then SQL rejects the query since the column "available_units_count" does not exist.

Any help is appreciated.

Thank you in advance.

Regards,

Feb
09
2 months ago
Activity icon

Replied to OrderBy WhereHas/having?

Thank you again for your reply, the method when will not work in my case.

It is not a case of "when" but how.

How to sort a model by its relationship status? Let's say I have a post model that has comments. I want to sort posts based on having/notHaving comments.

Something like:

Posts::orderBy('has_comments', $asc ? 'having' : 'not_having');

The issue is that has_comments does not exist once it is based on a relationship:

$postsWithComments = Posts::whereHas('comments');
$postsWithoutComments = Post::whereDoesntHave('comments');

This is why I am lost. I need to sort models based on having/notHaving a relationship.

Regards,

Activity icon

Replied to OrderBy WhereHas/having?

@jlrdw, unfortunately, the method when has no use for me.

I need a way to orderBy using whereHas as boolean so I can sort it.

Appreciate your help.

Activity icon

Started a new Conversation OrderBy WhereHas/having?

Hey yall,

Is there any way to order a query by a whereHas/having status?

What I mean is... Let's say if the model has the relation, the value is 1, else then the value is 0. Then sort by this value.

Thank you in advance.