dipherent

Member Since 2 Years Ago

Experience Points
11,990
Total
Experience

3,010 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
114
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.

  • Community Pillar

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

Level 3
11,990 XP
Jan
23
1 day ago
Activity icon

Replied to Add Stripe To Laravel

Thank you @jlrdw

Activity icon

Replied to Add Stripe To Laravel

So, you recommend using cashier for this? I read somewhere that Cashier shouldn't be used if the purpose is a single payment (without the need to login, or subscribe...

If using Cashier for such a scenario is ok, I can follow the tutorial here in laracasts and try to do it...

Please advice, and I really appreciate your help :)

Thanks

Activity icon

Started a new Conversation Add Stripe To Laravel

Hi friends,

I am trying to integrate Stripe in Laravel for a single charge without a subscription or login or registration. I tried to follow their PHP guide and it is confusing to me because I am a beginner.

Is there any simple to use guide or a source that you recommend?

How do I do this in Laravel?

Thanks

Jan
14
1 week ago
Activity icon

Awarded Best Reply on How To Update A Select Field Filter Based On The One Before

I figured it out...

I defined a public property inside the Livewire controller, and then I used the update method to query the companies with the relevant id and was able to retrieve only the companies in that locations... I know this looks easy but the problem I had is that there was a joint table between companies and locations... so, I used the whereHas to connect them..

Thanks

Activity icon

Replied to How To Update A Select Field Filter Based On The One Before

I figured it out...

I defined a public property inside the Livewire controller, and then I used the update method to query the companies with the relevant id and was able to retrieve only the companies in that locations... I know this looks easy but the problem I had is that there was a joint table between companies and locations... so, I used the whereHas to connect them..

Thanks

Activity icon

Started a new Conversation How To Update A Select Field Filter Based On The One Before

Hi friends,

I have a table in livewire, and I have two filters like this: By Location. - By Company.

I can filter the table with each field separately, but what I want is to update the By Company filter based on the By Location selected... for example, If I have selected New York in the location, I want the By company filter to show the companies in New York only...

How can I do that... ?

Here is what I have so far:

Livewire Controller

return view('livewire.all-jobs', [
            'jobs' => Job::with(['company', 'location',  'category', 'tags'])->orderBy('updated_at', 'desc')->where('active', 1)
            ->when($this->selectedCity, function($query){
                $query->where('location_id', $this->selectedCity);
            })
            ->when($this->selectedCompany, function($query){
                $query->where('company_id', $this->selectedCompany);
            })
            ->search(trim($this->search))
            ->paginate($this->paginate),

        ]);

Laravel Model

public function scopeSearch($query, $term)
    {
        $term = "%$term%";
        $query->where(function($query) use ($term){
            $query->where('title', 'like', $term)
                  ->orWhereHas('company', function($query) use ($term){
                      $query->where('name', 'like', $term);
                  }) 
                  ->orWhereHas('location', function($query) use ($term){
                    $query->where('name', 'like', $term);
                 }) 
                 
                 ->orWhereHas('tags', function($query) use ($term){
                    $query->where('name', 'like', $term);
                 }) 
            ;
            
        });
    }

Thanks for your help

Jan
13
1 week ago
Activity icon

Replied to Eager Loading Used But I Still Get So Many Queries

Thanks to your tip on nested eager loads.... here is how I solved it:

The app requests the top 4 companies and then the latest 3 jobs from each company.... this results in requesting 12 jobs with 12 locations... so what I did is I eager loaded the Company with the job and the location for the job.... all in my composer view here is how it looks:

$featuredCompanies = Company::with(['jobs.location'])->withCount([
                'jobs',
                'jobs as active_jobs' => $closure = function(Builder $query){
                    $query->where('active', 1);
                }])->whereHas('jobs', $closure, '>=', 1)->take(4)->orderBy('active_jobs', 'desc')->get();

Many thanks again... I will mark your answer on the nested eager loading as the best one...

Activity icon

Replied to Eager Loading Used But I Still Get So Many Queries

I am using includes so there are several files serving the index... but here is the core code there without any styling:

@foreach ($jobs as $job)

{{$job -> title }}
{{$job -> company -> name }}
{{$job->location->name}}
		
@endforeach

In the navigation I have the code I shared before..

Activity icon

Replied to Eager Loading Used But I Still Get So Many Queries

Which part of the code you need to look at? I shared what I think is relevant, but I can share anything else if that will help... I mean I cannot possibly post the whole thing here...

Here is the controller:

public function index()
    {
        $jobs = Job::with(['company', 'location',  'category', 'tags'])->orderBy('updated_at', 'desc')->where('active', 1)->paginate(15);     
        return view('job.index', compact('jobs'));
    }

Here is the composer view

$featuredCompanies = Company::with(['jobs'])->withCount([
                'jobs',
                'jobs as active_jobs' => $closure = function(Builder $query){
                    $query->where('active', 1);
                }])->whereHas('jobs', $closure, '>=', 1)->take(4)->orderBy('active_jobs', 'desc')->get();

and here is the view

@foreach ($featuredCompanies as $company)
              
{{$company->name}} <span>({{$company->active_jobs}})</span> 

<?php $count = 0; ?>
@foreach ($company->jobs as $job)
	<?php if($count == 3) break; ?>
	<?php $count++; ?>
@endforeach

@endforeach

If you need to look at anything else I will be happy to share it..

Thanks

Activity icon

Replied to Eager Loading Used But I Still Get So Many Queries

I think it is the queries for that code... I checked the source and these queries come from the same section that code is serving...

I am simply choosing 4 featured companies, and I want to show the latest 3 jobs from each company. If you noticed, the queries show the same structure... 3 locations per company...

Honestly I am not sure if this is normal or not... I mean I don't know if the number of queries can be lowered or not...

Thanks

Activity icon

Replied to Eager Loading Used But I Still Get So Many Queries

Thanks... I will keep trying...

Activity icon

Replied to Eager Loading Used But I Still Get So Many Queries

I am pretty new to laravel and to programming in general.. I feel overwhelmed with all these new things coming at me.. :P ... I will read through this for sure right away... Do you have a suggestion to fix the above?

Many thanks

Activity icon

Replied to Eager Loading Used But I Still Get So Many Queries

Yes, I cleared the cache and I also have the debugbar enabled, but I still see a high number of queries....

However, I have spotted the problem in the debugbar... I can see where the problem is but I cannot solve it...

I am choosing selecting 4 companies with their top 3 jobs... the location for each job is being called separately.. is this normal?

Here is what the debugbar shows

select * from `locations` where `locations`.`id` = 2 limit 1
select * from `locations` where `locations`.`id` = 2 limit 1
select * from `locations` where `locations`.`id` = 2 limit 1
select * from `companies` where `companies`.`id` = 3 limit 1

select * from `locations` where `locations`.`id` = 2 limit 1
select * from `locations` where `locations`.`id` = 2 limit 1
select * from `locations` where `locations`.`id` = 2 limit 1
select * from `companies` where `companies`.`id` = 1 limit 1

select * from `locations` where `locations`.`id` = 4 limit 1
select * from `locations` where `locations`.`id` = 4 limit 1
select * from `locations` where `locations`.`id` = 4 limit 1
select * from `companies` where `companies`.`id` = 2 limit 1

select * from `locations` where `locations`.`id` = 2 limit 1
select * from `locations` where `locations`.`id` = 2 limit 1
select * from `locations` where `locations`.`id` = 2 limit 1
select * from `companies` where `companies`.`id` = 4 limit 1

and here is the code I am using in my blade:

@foreach ($featuredCompanies as $company)
              
{{$company->name}} <span>({{$company->active_jobs}})</span> 

<?php $count = 0; ?>
@foreach ($company->jobs as $job)
	<?php if($count == 3) break; ?>
	<?php $count++; ?>
@endforeach

@endforeach

I removed the style for clarity...

Thanks in advance...

Activity icon

Replied to Eager Loading Used But I Still Get So Many Queries

Hi @aurawindsurfing thanks dear but nothing I changed after doing that... still the same number and types of queries.

Activity icon

Started a new Conversation Eager Loading Used But I Still Get So Many Queries

Dear friends,

I have a front page with job listings. The Job model has relationships with Company, Location, Category and Tags..

I used eager loading to send less queries to the db, but I don't know if this is the best I could do... I mean I am still having 37 queries when I refresh the homepage..

Here is how my telescope looks like

select * from `companies` where `companies`.`id` = 4 limit 1	0.22ms	
select * from `locations` where `locations`.`id` = 2 limit 1	0.22ms	
select * from `locations` where `locations`.`id` = 2 limit 1	0.27ms	
select * from `locations` where `locations`.`id` = 2 limit 1	0.25ms	
select * from `jobs` where `jobs`.`company_id` = 4 and `jobs`.`company_id` is not null	0.30ms	
select * from `companies` where `companies`.`id` = 2 limit 1	0.18ms	
select * from `locations` where `locations`.`id` = 4 limit 1	0.18ms	
select * from `locations` where `locations`.`id` = 4 limit 1	0.19ms	
select * from `locations` where `locations`.`id` = 4 limit 1	0.22ms	
select * from `jobs` where `jobs`.`company_id` = 2 and `jobs`.`company_id` is not null	0.31ms	
select * from `companies` where `companies`.`id` = 1 limit 1	0.21ms	
select * from `locations` where `locations`.`id` = 2 limit 1	0.18ms	
select * from `locations` where `locations`.`id` = 2 limit 1	0.18ms	
select * from `locations` where `locations`.`id` = 2 limit 1	0.21ms	
select * from `jobs` where `jobs`.`company_id` = 1 and `jobs`.`company_id` is not null	0.34ms	
select * from `companies` where `companies`.`id` = 3 limit 1	0.20ms	
select * from `locations` where `locations`.`id` = 2 limit 1	0.24ms	
select * from `locations` where `locations`.`id` = 2 limit 1	0.25ms	
select * from `locations` where `locations`.`id` = 2 limit 1	0.27ms	
select * from `jobs` where `jobs`.`company_id` = 3 and `jobs`.`company_id` is not null	0.55ms	
select `tags`.*, `job_tag`.`job_id` as `pivot_job_id`, `job_tag`.`tag_id` as `pivot_tag_id` from `tags`...	0.31ms	
select * from `categories` where `categories`.`id` in (1, 2)	0.25ms	
select * from `locations` where `locations`.`id` in (1, 2, 3, 6, 7, 8, 9, 10, 11, 12)	0.29ms	
select * from `companies` where `companies`.`id` in (1, 2, 3, 4, 5)	0.28ms	
select * from `jobs` where `active` = 1 order by `updated_at` desc limit 15 offset 0	0.37ms	
select count(*) as aggregate from `jobs` where `active` = 1	0.41ms	
select `tags`.*, (select count(*) from `jobs` inner join `job_tag` on `jobs`.`id` = `job_tag`.`job_id`...	0.51ms	
select `categories`.*, (select count(*) from `jobs` where `categories`.`id` = `jobs`.`category_id`) as...	0.50ms	
select `companies`.*, (select count(*) from `jobs` where `companies`.`id` = `jobs`.`company_id`) as...	0.54ms	
select `locations`.*, (select count(*) from `jobs` where `locations`.`id` = `jobs`.`location_id`) as...	0.60ms	
select `tags`.*, (select count(*) from `jobs` inner join `job_tag` on `jobs`.`id` = `job_tag`.`job_id`...	0.57ms	
select `locations`.*, (select count(*) from `jobs` where `locations`.`id` = `jobs`.`location_id`) as...	0.63ms	
select `companies`.*, (select count(*) from `jobs` where `companies`.`id` = `jobs`.`company_id`) as...	0.62ms	
select `locations`.*, (select count(*) from `jobs` where `locations`.`id` = `jobs`.`location_id`) as...	0.73ms	
select * from `locations`	0.26ms	
select * from `categories`	0.27ms	
select * from `tags`	0.26ms	

and here is how my JobController looks like:

$jobs = Job::with(['company', 'location',  'category', 'tags'])->orderBy('updated_at', 'desc')->where('active', 1)->paginate(15);     
        return view('job.index', compact('jobs'));

I am also using a composer view to pass customized locations and companies to header and footer... I used different variables, but essentially they pull from the same db... right?

Is there any way to make this better?

Thanks

Jan
11
1 week ago
Activity icon

Replied to Counting The Active Jobs Only With Jobs_count From Another Table

AWESOME... You are brilliant ... I kept trying the active_jobs_count....

But please be advised that when I use active_jobs_count.. I get "SQLSTATE[42S22]: Column not found 1054 Unknown column 'active_jobs_count'"

It is working as expected now by using the following code...

$locations = Location::withCount(['jobs', 'jobs as active_jobs_count' => function ($query) {
    $query->where('active', 1);
}])->take(5)->has('jobs', '>=', 1)->orderBy('active_jobs', 'desc')->get();

Thanks a million ...

Activity icon

Replied to Counting The Active Jobs Only With Jobs_count From Another Table

thanks but this didn't work... I get the same results... I get the active jobs count right and it shows normally, but the ORDER is not right...

here is what appear in my menu exactly:

New York (48) - LA (18) - Boston (2) - Pittsburgh (9)

As you can see, Pittsburgh should come before Boston because I am ordering with "desc", however, Boston have more than 10 inactive jobs, and they are being counted in the back and that's why Boston is placed before Pittsburgh...

I need the ordering to be right... I used both your version and no change...

So, the whole idea is that I want to order the locations by "active job count"

Please help.

Thanks a lot

Activity icon

Replied to Counting The Active Jobs Only With Jobs_count From Another Table

I tried that and didn't work, but I guess the jobs_count deals with tables only... for example, if the table name was posts... this function will be posts_count. I tried to use a where query or clause in the same chain and failed.

Activity icon

Started a new Conversation Counting The Active Jobs Only With Jobs_count From Another Table

Hi friends,

I have two tables: locations & Jobs... the job listing can be active or inactive. In my menu I am showing the location with the job count. I only show the count of the active jobs.. For example:

New York (20 jobs) LA (10 jobs) Boston (5 jobs)

Now, I am ordering the locations by job count with "desc", but the problem I am having is that the count is including the Inactive jobs as well..

Here is the query I am using in my controller:

 $locations = Location::withCount([
            'jobs',
            'jobs as active_jobs' => function($query){
                $query->where('active', 1);
            }
            ])->take(5)->has('jobs', '>=', 1)->orderBy('jobs_count', 'desc')->get();

How do I only make the (jobs_count) count the active jobs only?

Thanks folks,

Jan
09
2 weeks ago
Activity icon

Replied to How To Add Filters & Search To A Listings Page

Thanks man,

I appreciate your help

Activity icon

Started a new Conversation How To Add Filters & Search To A Listings Page

Hello friends,

I have a page full of listings (Jobs). I need to build some filters at the top (By keyword, Location, and company). I read about the Spatie Query Builder and since I am a beginner I couldn't implement it right into my page.

Can you please point me to a good tutorial to show how to implement such a feature?

Thank you

Jan
06
2 weeks ago
Activity icon

Awarded Best Reply on How To Show The Next Top Categories From A Collection

Hi guys, thanks again... here is how I ended up doing it... this is the simplest and fastest way in my opinion:

$categories = Category::withCount('posts')->take(5)->has('posts', '>=', 1)->orderBy('posts_count', 'desc')->get();

$collection = Category::withCount('posts')->take(10)->has('posts', '>=', 1)->orderBy('posts_count', 'desc')->get();

$moreCategories = $collection->slice(5)->all();

The first query will give me 5 top categories, which will go in the main menu

The second query will give me the 10 top categories including the original 5 that I want to remove

The third will remove the first 5 and give me the rest, which I then placed in the dropdown menu.

I hope this helps anyone out there.

Thanks again

Activity icon

Replied to How To Show The Next Top Categories From A Collection

I agree, it was the best way for my project and for my level of experience... I am new to web development in general and very new to Laravel...

I am sure there is an optimum solution for this, but i find slice is the best for what I need now...

Activity icon

Replied to How To Show The Next Top Categories From A Collection

It is a menu with a dropdown... so yes you can click on the category once and it will go to the destination url..

Activity icon

Replied to How To Show The Next Top Categories From A Collection

Hi guys, thanks again... here is how I ended up doing it... this is the simplest and fastest way in my opinion:

$categories = Category::withCount('posts')->take(5)->has('posts', '>=', 1)->orderBy('posts_count', 'desc')->get();

$collection = Category::withCount('posts')->take(10)->has('posts', '>=', 1)->orderBy('posts_count', 'desc')->get();

$moreCategories = $collection->slice(5)->all();

The first query will give me 5 top categories, which will go in the main menu

The second query will give me the 10 top categories including the original 5 that I want to remove

The third will remove the first 5 and give me the rest, which I then placed in the dropdown menu.

I hope this helps anyone out there.

Thanks again

Activity icon

Replied to How To Show The Next Top Categories From A Collection

@sr57 and @snapey Thank you, I will try both approaches and and will come back and let you know which one worked best for me..

Much appreciated.

Activity icon

Started a new Conversation How To Show The Next Top Categories From A Collection

Hello friends,

I have several categories with some posts in each category. I am showing the top 5 categories in the main menu using this query:

$categories = Category::withCount('posts')->take(5)->has('posts', '>=', 1)->orderBy('posts_count', 'desc')->get();

Now, I have a button of "More Categories" in the same menu that when clicked I want to display a dropdown and show the remaining categories based on post count as well.

How can I show the next 5 or the remaining categories in that dropdown menu?

I appreciate your help

Many thanks