bobbybouwmann

bobbybouwmann

Developer at Enrise

Member Since 5 Years Ago

Apeldoorn, The Netherlands

Experience Points
1,893,375
Total
Experience

0 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
1710
Lessons
Completed
Best Reply Awards
2503
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.

Level 50
1,893,375 XP
Aug
15
16 hours ago
Activity icon

Replied to Missing Route Parameter Errors

@pweil Yeah, Laravel 6 got stricter on this!

Aug
14
1 day ago
Activity icon

Replied to Date For When Laravel Mix Would Official Release A Version With Webpack 5 Fully Supported?

There is already being worked on, but there is no release date set.

I also don't have a solution for you at this point.

Activity icon

Replied to Missing Route Parameter Errors

Well, it depends on the name of the route that you gave it. You get this error if your route looks like this

Route::get('projects/{project}', ShowProjectController::class)->name('auth.projects.show');

The parameter name is called project so the param in the array needs to match as well. If you don't provide an array Laravel will use the same order of parameters to match them and therefore this works.

Activity icon

Awarded Best Reply on Can You Tell Me Why You Use (redis) In Your Projects ..?

In the Laravel world, Redis is mostly used for queues and caching. It's perfect for queues because it just stores key value-based data. You don't need more than that for a queue. The same goes for caching.

Do you have a more specific question here?

Activity icon

Replied to Strange Exception With Two Parameter Bindings With Api Controller

I don't see anything strange here... Do you have more context of the error?

Activity icon

Replied to Package.json DevDependencies

If you compile your javascript assets before you deploy, you don't need the node_modules directory on production at all. Only if you refer to a path outside of your app.js file that is compiled. The only happens if you include a script in the <script> tag in your HTML.

Activity icon

Awarded Best Reply on Toggle Local Avatar And Socialite Avatar

Check, well in that case you probably need to check if path is an URL or not and based on that perform your action.

Try this

public function getAvatarPathAttribute($avatar)
{
    // Check if the value is a URL (you can also do this with a regex for a better comparison)
    if (filter_var($avatar, FILTER_VALIDATE_URL)) {
        return $avatar;
    }

    // No URL and not empty, so it's a path
    if ($avatar !== null) {
        return asset('storage/' . $avatar);
    }

    // If nothing matches, we return the default
    return 'https://www.gravatar.com/avatar/';
}
Activity icon

Replied to Package.json DevDependencies

You probably don't need any of the require-dev packages in production. However, you don't know if any of your require packages also use one of the require-dev packages. Therefore, it's probably safer to just upload everything you have.

Another solution is deleting the vendor directory locally, only install the require packages using composer --no-dev --optimize-autoload and then upload the vendor directory.

Activity icon

Replied to Toggle Local Avatar And Socialite Avatar

Check, well in that case you probably need to check if path is an URL or not and based on that perform your action.

Try this

public function getAvatarPathAttribute($avatar)
{
    // Check if the value is a URL (you can also do this with a regex for a better comparison)
    if (filter_var($avatar, FILTER_VALIDATE_URL)) {
        return $avatar;
    }

    // No URL and not empty, so it's a path
    if ($avatar !== null) {
        return asset('storage/' . $avatar);
    }

    // If nothing matches, we return the default
    return 'https://www.gravatar.com/avatar/';
}
Activity icon

Replied to How To Organize Multiple Projects Into A Single Project ?

You could make separated directories per service in your app/Http/Controllers directory. That should already be enough.

But as I understand it, you already have 4 projects. You can also combine them using an API and simply call the API on the homepage to get the service working. Otherwise, copy-pasting the controllers and models should already be enough ;)

Activity icon

Awarded Best Reply on How To Make The Value In The Array To Display All

It's also better to use mailables here. This way you have a view you can use to display your content. No need to build up your own body

Documentation: https://laravel.com/docs/7.x/mail#generating-mailables

Activity icon

Replied to Can You Tell Me Why You Use (redis) In Your Projects ..?

In the Laravel world, Redis is mostly used for queues and caching. It's perfect for queues because it just stores key value-based data. You don't need more than that for a queue. The same goes for caching.

Do you have a more specific question here?

Activity icon

Replied to Toggle Local Avatar And Socialite Avatar

Well, take another look at the "src" value. You're appending a URL behind a URL. That will never work. Instead, you need to do something like this

public function getAvatarPathAttribute($avatar)
{
    return $avatar ?? 'https://www.gravatar.com/avatar/';
}

Since $avatar is already an URL, you can simply return that ;)

Activity icon

Replied to How To Make The Value In The Array To Display All

It's also better to use mailables here. This way you have a view you can use to display your content. No need to build up your own body

Documentation: https://laravel.com/docs/7.x/mail#generating-mailables

Activity icon

Replied to How To Make The Value In The Array To Display All

That is because you create a new $body attribute every time. Instead, you need to append to the string.

Try this instead

$body = '';

foreach($productDetails as $product){
    $productBody = 'build up your string here';

    $body .= $productBody;
}

Using .= you append to the current string instead of overwriting it.

Activity icon

Replied to Package.json DevDependencies

That depends how you deploy to your shared hosting and if you have command line access. If you have command line access you can simply use the command line to install the dependencies. If you don't it's recommended to only upload the files you really need to run production. Like PHPUnit is something you don't need there.

Aug
13
2 days ago
Activity icon

Replied to I Want To Authenticate With The Web Guard And If This Fails, Automatically Switch To The Secondary Guard

Well, I think you can easily do this with the current LoginController and the methods you already have available through the included traits. Basically you want something like this

if ($this->attemptLogin($request)) {
    return $this->sendLoginResponse($request);
} elseif (Auth::guard('web2')->attempt($this->credentials($request), $request->filled('remember'))
    return $this->sendLoginResponse($request);    
}

You can find it in this trait: https://github.com/laravel/ui/blob/2.x/auth-backend/AuthenticatesUsers.php#L32

You can override the login method in your LoginController if you're using the default Laravel authentication system. If you're not using this, it should still push you in the right direction.

Activity icon

Awarded Best Reply on Sanctum Login Route Missing

Are you sure you're sending the correct headers in your request to sanctum? Since it's an API request you need to specify the correct headers

"Accept" => "application/json"

Without the header, it returns the regular login screen, which is HTML

Activity icon

Replied to Command From My Code

@michaloravec Well, we could answer that on every question ;)

Activity icon

Replied to Sanctum Login Route Missing

Are you sure you're sending the correct headers in your request to sanctum? Since it's an API request you need to specify the correct headers

"Accept" => "application/json"

Without the header, it returns the regular login screen, which is HTML

Activity icon

Awarded Best Reply on Command From My Code

You can call any command using the Artisan facade in your controller

public function index()
{
    $exitCode = Artisan::call('migrate:fresh', ['--seed'']);
}
Activity icon

Replied to Command From My Code

You can call any command using the Artisan facade in your controller

public function index()
{
    $exitCode = Artisan::call('migrate:fresh', ['--seed'']);
}
Activity icon

Replied to Laravel Accessing A Relationship Table

Yeah, this is how SQL works. You always need to group by all selected columns. In your case, it might be better to do a join query instead of using the relationships.

Activity icon

Replied to JWTAuth::attempt Problem

Did you add the correct middleware to the route? You can find examples in the documentation: https://jwt-auth.readthedocs.io/en/develop/quick-start/

Activity icon

Replied to Remove Items From $request->validated()

unset should work as well.

I think I like the macro solution from @tykus the most here :D

Activity icon

Replied to Get All Orders Related To City In Another Table

@ethar It would have helped if you shared your full query before ;)

Activity icon

Replied to Upgrade Forge Server From Nginx 1.15.8

Very odd that you needed to deleted the config file... Anyway, glad you fixed it!

Activity icon

Replied to Get All Orders Related To City In Another Table

You can do something like this

$orders = Order::whereHas('address' => function ($query) {
    $query->whereHas('city', function ($query) {
        $query->where('name', 'Amsterdam');
    });
});->get();

Note that it's not possible to keep changing with whereHas, so that's why you need the double-level here.

Documentation: https://laravel.com/docs/7.x/eloquent-relationships#querying-relationship-existence

Another solution is using a join, which makes a simpler query but might be harder to read

Activity icon

Replied to Remove Items From $request->validated()

There is no one simple way to achieve what you want here because validated returns an array.

I would probably do it the other way around and only select the fields you need from the request

$item->update($request->only(['field1', 'field2']));

Or the other way around

$item->update($request->except(['agree']));
Activity icon

Replied to Laravel Accessing A Relationship Table

Sometimes it's also better to just use the collection methods to calculate the sum of a certain relationship

$invoices. = Invoice::with(['items' => function ($query) {
    $query->whereNotIn('name', ['Consultation','Appointment', 'Laboratory', 'HIV Counselling'])
         ->groupBy(DB::raw('name'));
})->get();

foreach ($invoices as $invoice) {
    $sum = $invoice->items->sum('total_amount');
}
Activity icon

Replied to Laravel Accessing A Relationship Table

If you do a select of a relationship, you always need to include the primary key as well. Otherwise, Laravel won't be able to connect both queries together. When using with Laravel performs two queries.

Try this,

$query->select([
    'invoice_id',
    DB::raw("SUM(total_amount) as lab_count"),
    DB::raw('name')
]) ->whereNotIn('name', ['Consultation','Appointment', 'Laboratory', 'HIV Counselling'])
    ->groupBy(DB::raw('name'));
Activity icon

Replied to Package.json DevDependencies

@chron Composer works a bit differently. Composer doesn't compile to one file, right? So things like Laravel are actually required to run your application. All those PHP files are needed.

Things like phpunit are not needed in production. Therefore, you put them in the dev dependencies so you don't install them on your production server. Only on your local environment.

Activity icon

Awarded Best Reply on Laravel Add Relationship Constraints And Get Count

You're not using a join here. whereHas will just check if the result exists and based on the select items, but it won't add any data or records to the original query. You also can't use get in the callback for the query in the whereHas method.

Aug
12
3 days ago
Activity icon

Replied to Super Weird Laravel Migration Deadlock Problem

A deadlock only happens if something is still using the table from another place. So make sure no connections are established for the database.

It might even work to just throw away the database at all or even create a new one with another name and try to migrate on that.

Activity icon

Replied to Laravel Geolocation

Most of the time you need the IP from the user to make this work. Luckily you can get the IP of the user from the request. Then there are several packages you can use to make this work.

Here is a good tutorial: https://www.codechief.org/article/how-to-get-current-user-location-in-laravel#gsc.tab=0

Activity icon

Replied to Ubuntu Nginx Guzzle Connection Timed Out

It seems that the API request has a timeout. This has nothing to do with Nginx because you can still perform the API call.

Are you sure your production server has access to the API? Maybe it has some IP-whitelisting or something else because that makes sense for the timeout. The server doesn't seem to be able to connect to the API.

Activity icon

Replied to Sequel Pro Uses DB Index, But Eloquent Doesn't

So there seems to be a difference in the type of the value and the column as well. You say it's faster with a string than with a number. Have you tried converting it to a different type (int vs string) to see if that affects the results?

Activity icon

Replied to Package.json DevDependencies

Well, since you compile them before deployment you basically only use them for development purposes. Therefore they are all dev dependencies.

Activity icon

Replied to Help With Filtering Users In Vue.

The problem is probably in your check. You use triple === which means it also checks on type. I think the radio button shows the number as a string and active of the employee as integer or boolean. If you convert them both to the same type it should work.

Activity icon

Replied to Route Problem Returns 403 - Not Executing Controller Either

What is the URL you're actually using? I would expect something like example.com/crm/1/address

Also, have you tried putting the route as / just to make sure it's not an empty string?

Activity icon

Replied to Help With Filtering Users In Vue.

What is your question? What is not working for you?

Activity icon

Replied to Upgrade Forge Server From Nginx 1.15.8

It might not update because of an older OS version. However, 18.04 should be good enough and should be supported until the latest version.

Just run it and see what happens ;)

Activity icon

Replied to Laravel Add Relationship Constraints And Get Count

You're not using a join here. whereHas will just check if the result exists and based on the select items, but it won't add any data or records to the original query. You also can't use get in the callback for the query in the whereHas method.

Activity icon

Awarded Best Reply on Laravel 7.x Encrypt, CryptoJS Decrypt?

There is a suggestion in the comments on the gist to change line 23. You probably need to do that to make it work with Base64

Activity icon

Replied to Sequel Pro Uses DB Index, But Eloquent Doesn't

I don't see anything strange in your code at this point.

Does the query take 4 seconds or the request itself? Are you sure they are both connected to the same database?

Activity icon

Replied to Upgrade Forge Server From Nginx 1.15.8

In general, upgrading nginx can be done like so

sudo apt-get install --only-upgrade nginx

So the reason it might not update anything is because you're running on an older server as well since you use PHP 5.6. So what ubuntu version do you run?

It's recommended to update to a newer ubuntu version as well. In most cases, it's easier to spin up a new server. Deploy your application to the new server and switch your DNS to the new server.

Activity icon

Replied to Too Few Arguments To Function ...__construct(), 1 Passed

Laravel can only inject it if the container itself resolved the class. If you call a job with a dependency you're calling it yourself and not the container. That's why you need the app helper here, so the container is used to retrieve the dependency.

Also, the automatic dependency injection only works if you do it for all dependencies and not just for one. In your case, you can't because you don't have a fixed User object

Activity icon

Awarded Best Reply on Send Notification To Multiple Roles

Both work fine and should work in your case. The problem here is that you only select person that have both roles named admin and author. Try this query instead

$admins = User::whereHas('roles', function ($q) {
    return $q->whereIn('name', ['admin', 'author']); // If the user has one of the roles
})->get();