bobbybouwmann

Laravel Evangelist at Enrise

Member Since 6 Years Ago

Apeldoorn

Experience Points
2,034,215
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
1876
Lessons
Completed
Best Reply Awards
2649
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 50
2,034,215 XP
Jun
12
1 day ago
Activity icon

Awarded Best Reply on Use Timezone In Date Range Scope

Well, in this case, the getCreatedAtAttribute accessor is only applied whenever you retrieve a model from the database. In the scopeByPeriod method you're still working on database level where the timezone is still used based on what is stored in the database.

The best solution here is to convert the $start and $end dates from Europe/Moscow to UTC when comparing them in the query.

public function scopeByPeriod(Builder $query, $start, $end)
{
	$start = Carbon::parse($start)->setTimezone('UTC');
	$end = Carbon::parse($end)->setTimezone('UTC');

	return $query
		->whereDate('created_at', '>=', $start)
		->whereDate('created_at', '<=', $end);
}

Another solution is using convert_tz in a raw query but that also makes it more complicated.

The general idea when working with timezones is that you should stick to the default (UTC) and convert everything to UTC when working with data. Only convert it back to the correct timezone when displaying the value. This way you have the least headaches with timezones ;)

Jun
11
2 days ago
Activity icon

Replied to Softdelete Query Get Results In Join Query

Yeah, Eloquent takes care of this, but with a join, you connect based on the database table and not based on the model. So in this case Eloquent doesn't know it needs to exclude the soft-deleted records.

Note that Eloquent is here for 90% of the most common cases. This is an edge case. You should just add the extra whereNull('files.deleted_at') in this case to make it work ;)

There are alternatives using relationships, but that is something different than using a join of course.

Activity icon

Replied to Laravel & Redis : Connect Redis To Remote Server

You can only connect to that other Redis server if it's already running and being exposed by your other computer. If there is no (local network) IP address or domain name you can connect to it won't work at all.

Activity icon

Replied to Use Timezone In Date Range Scope

Well, in this case, the getCreatedAtAttribute accessor is only applied whenever you retrieve a model from the database. In the scopeByPeriod method you're still working on database level where the timezone is still used based on what is stored in the database.

The best solution here is to convert the $start and $end dates from Europe/Moscow to UTC when comparing them in the query.

public function scopeByPeriod(Builder $query, $start, $end)
{
	$start = Carbon::parse($start)->setTimezone('UTC');
	$end = Carbon::parse($end)->setTimezone('UTC');

	return $query
		->whereDate('created_at', '>=', $start)
		->whereDate('created_at', '<=', $end);
}

Another solution is using convert_tz in a raw query but that also makes it more complicated.

The general idea when working with timezones is that you should stick to the default (UTC) and convert everything to UTC when working with data. Only convert it back to the correct timezone when displaying the value. This way you have the least headaches with timezones ;)

Activity icon

Replied to Is It Possible To Use Laravel Vapor UI Without Session?

Looking at the latest version of the layout.blade.php file from the package, I don't see any reference to any session. Also no reference to the session in the rest of the codebase. It's a full VUE frontend webpage, so there shouldn't be a session involved at all.

The only thing I can think of is that the authorization step is not working correctly. Maybe you need to change this to work with your token somehow? If you're working with the token you probably need to pass it to the VUE application as well. Otherwise, it can't know about it: https://docs.vapor.build/1.0/introduction.html#installing-the-vapor-ui-dashboard

It's probably also good to check if you're on the latest version or not.

May
25
2 weeks ago
Activity icon

Replied to E Challan

What have you tried so far?

Activity icon

Replied to User Will Be Logged Out After Deployment Made

The storage directory is perfectly fine to store them. That directory shouldn't be accessible for your users, since only the public directory is.

You can change the path to the keys inside a ServiceProvider by adding the following line

Passport::loadKeysFrom('/var/http/path/to/files');

I would however recommend sticking to the default unless it's a big deal-breaker for you.

Activity icon

Replied to User Will Be Logged Out After Deployment Made

@crazylife Well, yeah you don't have to reset the public and private key on every deployment. You only need to change them if you think they are compromised.

It could also have something to do with clearing the session, if you save the session in the database for example.m

Activity icon

Replied to OrderBy With A Value From Many To Many Relationship

You can't order the parent data with a child relationship using the whereHas or with method. If you want to do this in one query you need to use a join instead. You can also still combine ``withtogether with ajoin`.

Another option is to sort the collection before returning it. This is a bit harder with pagination, since you need to build up the pagination object yourself after sorting the collection

May
24
2 weeks ago
Activity icon

Awarded Best Reply on Advice: Jetstream With Bulma Instead Of Tailwind

There shouldn't be any issues using Bulma with jetstream. The idea behind jetstream is that you generate it once and then you own that part. You can do with it whatever you want.

You don't update jetstream at a later stage since you already build your app around it.

It might be a lot of work to rewrite all the CSS, but if that works for you go for it!

May
23
3 weeks ago
Activity icon

Replied to Laravel External POST Requests

it sounds to me you're looking for a solution to test the incoming request, right? You can always use a tool like postman or CURL and simply post to the URL and see what is available inside the $request

May
22
3 weeks ago
Activity icon

Replied to New Project Idea - Laravel Code Refactoring

You can turn this into an exercise thing. So you get a random snippet that you can refactor. If you're done you go to the next one and so on. You could skip snippets as well.

Maybe it would be nice to categorize snippets as well, for example Eloquent, Collections, Controller etc.

Activity icon

Replied to Laravel External POST Requests

Well, in general, you would just have a route that would handle the request. That can be a simple controller depending on what you need.

It's also common to use a queue in combination with such a construction. Especially when it's a webhook, for example, the other party doesn't want to wait too long until they get a response. So instead, you push the action to the queue and handle it from there.

But like I said, it depends on the case. A simple route should work fine here.

Activity icon

Replied to Routing Secure Access To Phpdoc Files For Auth Users Only

Well, anything inside the public directory is accessible, hence the "public".

Your current solution to use File::get is a solid solution here. However, as you mentioned the assets are not working as expected. I think there are two solutions here that you could try.

  • Update the generator (or make your own command) and convert the HTML file to a view which you can access from a controller. Then you can simply restrict access using a middleware.
  • Use the current FIle::get approach, but update the paths inside the file to the correct location.

I don't think you can work around this without doing something with the file.

Activity icon

Replied to Laravel Sail Curl Command Is Asking For Uri

Curl is meant for UNIX-based systems, not Windows.

I think you need to use an alternative for windows or install CURL on windows.

This might help (since you use PowerShell): https://www.educative.io/edpresso/curl-in-powershell

There are options to install CURL on windows, you can find those solutions easily by googling around :)

Activity icon

Replied to Advice: Jetstream With Bulma Instead Of Tailwind

There shouldn't be any issues using Bulma with jetstream. The idea behind jetstream is that you generate it once and then you own that part. You can do with it whatever you want.

You don't update jetstream at a later stage since you already build your app around it.

It might be a lot of work to rewrite all the CSS, but if that works for you go for it!

Activity icon

Replied to Model Create Method Overriding Doesn't Work When Called Through A Relationship

You can't override the create method since the create method is not being called on the model. If you want to do something extra with the data on create you should hook into the model events and perform your action.

You can read more about it here: https://laravel.com/docs/8.x/eloquent#events

Let me know if anything is unclear.

Activity icon

Replied to Components: Passing Arrays/Objecs And Using Props

I think the only way to do this is to set the default data in the constructor indeed. I also think this is cleanest way to do it ;)

May
05
1 month ago
Activity icon

Awarded Best Reply on Schema:dump Test Sqlite

The only thing you can do is run your migrations and make a copy of the .sqlite file. You should then before running your test, move your .sqlite file to the correct directory and you're good to go. You can also just keep this file in your test directory, but you need to run your migrations at least once.

The schema:dump command won't work for sqlite at this point.

Apr
29
1 month ago
Activity icon

Replied to Laravel 8 Sail Redis Not Assuming The Default Cache Driver

How are you connecting to the redis-cli? Are you sure you're connecting to the Redis container and not a local instance of Redis?

Activity icon

Replied to Laravel Nova Actions

From the docs:

If you have an action that does not require any resources / models to run, you may register it as a "standalone" action by chaining the standalone method when registering the action. This action always receives an empty collection of models in its handle method:

So the collection should be empty in this case. I would either expect that your query to retrieve the models is returning nothing or some error is thrown somewhere.

You can inspect the network requests in your browser and see if the ajax request for the action is working or not.

Activity icon

Replied to Application Design Question Vue/Redis/Pusher

Yeah, if you don't want your users to wait until the next ping comes in with new data you need to store it somewhere. The database or Redis are both good options for this.

When broadcasting the data through pusher you can also store it somewhere and create an endpoint to retrieve the latest data.

Apr
27
1 month ago
Activity icon

Replied to Authentication On AJAX Endpoint

Well, ajax requests don't have a session set by default, unless they are fired from the same domain where you logged in using a session.

So my best bet is that you fire these calls from the subdomain, but the session is only set on the main domain. You can fix this in Laravel by setting the domain value in your config/sessions.php

'domain' => '.example.com',

Notice the . before the domain name. This makes the session available to the main and all subdomains. To make this work you need to log in again to set the session correctly.

Activity icon

Replied to Array Of Json To Array In PHP

Yeah, this happens a lot. At this point, I just accepted that this happens.

I'm 100% here to help others in any way I can :)

Apr
21
1 month ago
Activity icon

Awarded Best Reply on How Do You Create An Admin User Or User With Additional Authorization?

Yeah, the basic idea is that you either add a method to model or you add a column to the table which you use to determine if the user is an admin or not.

In this case, Laravel uses isAdmin which can refer to the is_admin column on your users' table.

Apr
20
1 month ago
Activity icon

Replied to How Do You Create An Admin User Or User With Additional Authorization?

Yeah, the basic idea is that you either add a method to model or you add a column to the table which you use to determine if the user is an admin or not.

In this case, Laravel uses isAdmin which can refer to the is_admin column on your users' table.

Activity icon

Replied to Updated_at Changed But Model Field Not Changed

Did you set a fillable or guarded property on the member model?

Also, the updated_at is only updated whenever there is a change on the model. If there is no change, the datetime is not updated.

Apr
09
2 months ago
Activity icon

Replied to Maatwebsite/Excel : I Need Some Help With The Map Function

Sure you can run an if-else statement. However, the map function doesn't know anything about the previous item you mapped over. So in this case $lastcar will always be null.

You can however get around this by doing the looping yourself. You return any collection here yourself. This also means you need to retrieve the data yourself.

Documentation: https://docs.laravel-excel.com/3.1/exports/collection.html#using-custom-structures

Activity icon

Replied to Algolia Scout

To make that work you need to associate the data from your relationship to the post you store in Algolio.

Documentation: https://www.algolia.com/doc/framework-integration/laravel/indexing/configure-searchable-data/?client=php

Activity icon

Replied to Laravel Websockets - Multi-Tenancy With Private Channels

I'm not 100% sure, but I think you have to create your own AppProvider to make sure it can determine what app is what. I can imagine that it by default always assumes the same backend.

You can override this behaviour but that requires some work on your side.

Documentation: https://beyondco.de/docs/laravel-websockets/advanced-usage/app-providers

Activity icon

Replied to Allow User To Update A Specific Field With ACL Laravel 6

Well, you should probably create separate permissions or roles for viewing and updating content. This way you can assign the correct permission/role to the correct user.

Apr
08
2 months ago
Activity icon

Replied to Laravel Queue With One Email ID In TO Address

Your job should look like this

public function __construct($email)
{
    $this->email = $email;
}

public function handle()
{ 
    Mail::to($this->email)->send(new SendEmailCircular());
}
Activity icon

Replied to What To Use With Multiple Api Calls Inside A Request

@senty Well, relying on internet is a bad thing in general at all.

I think the web-socket approach is pretty good here. The alternative is a long waiting screen until you collected all the data.

Apr
04
2 months ago
Activity icon

Replied to What To Use With Multiple Api Calls Inside A Request

Well, it depends on the data. Let's say the rates are only updated every hour? Well, in that case, you might be able to cache the results and use a cronjob to retrieve and cache the data again. That way you will have the fastest responses.

If the data changes every minute that a queue and broadcasting sounds like the best solution for this. Especially if you want to make this scale automatically.

Also, the async package should work perfectly fine here. You can use dependency injection inside your class or use the app helper to resolve any dependencies. Check this part of the documentation

Documentation: https://github.com/spatie/async#working-with-tasks

Activity icon

Replied to Unable To Update Per Page Count From The Frontend (Laravel, InertiaJS, VueJS)

Right now your controllers expect an URL that looks like this

example.com/users?per_page=3

It seems that the problem is that you're setting the value of the per_page on the paginated object, but the paginated object is a result of the query. Instead, you need to make sure the code in the backend (laravel) receives the per_page data in some way. This can be updating the URL from your frontend or settings some kind of session instead of using a query value from the URL.

Mar
30
2 months ago
Activity icon

Replied to Laravel Sail On Windows

Did you install Docker? Laravel sail runs on Docker, to make it work you need to have Docker installed and running in the background

Activity icon

Replied to Laravel Queue With One Email ID In TO Address

Well, it seems you're using a User model here but you used a value that doesn't exist in the database. Without more code I can' really help you.

Mar
28
2 months ago
Activity icon

Replied to Laravel Queue With One Email ID In TO Address

Well, in this case you pass in an array of emails. At least, it seems it happens like that.

Instead, you should send an email for each item in the list.

public function handle()
{
	$mailable = new SendEmailCircular();

	foreach ($this->details['email'] as $email) {
		Mail::to($email)->send($mailable);
	}
}

Here you look over all the emails.

If you have a lot of emails, it might be better to schedule a job for each email. This scales better if you have a database or redis queue.

$emails = User::select('email')->get();

foreach ($emails as $email) {
	dispatch(new SendEmailCircularJob($email));
}

You job will then only send the email to the given email.

Activity icon

Replied to [AskJS] Is It A Problem That JQuery Terminal Use JQuery?

Well, if you're trying to sell something then indeed jQuery is not a hot topic anymore. Then it might be better to use a different name. But if you're building it with jQuery you should at least mention it inside the description.

In general, jQuery is not that bad as a technology. It still has its place in the development community and still serves its purpose.

Mar
26
2 months ago
Activity icon

Replied to Associate Multiple Models To Items

A polymorphic relationship is perfect for this use case!

Documentation: https://laravel.com/docs/8.x/eloquent-relationships#polymorphic-relationships

Here is a tutorial with a great example: https://www.youtube.com/watch?v=rx1DQBE01b0

Mar
25
2 months ago
Activity icon

Replied to Error With DigitalOcean Spaces Database Backup

Well, the digital ocean storage system is built on the same protocol as S3. So basically they work the same, but they have a different URL and authentication method behind them.

Make sure to double-check the authentication part of your setup. It seems it's missing some keys here or you're using the wrong keys.

Activity icon

Replied to Create New Project Inside Homestead

Mmh, the idea behind Homestead (or Vagrant) is that it syncs your local machine to the other environment. In general, you work from your main machine and that's it.

I don't really understand why you create a new project inside homestead and then start moving directories. I never done that before and all my projects run perfectly fine...

These are the steps I follow

// Go to my code directory
cd ~/Code

composer create-project laravel/laravel my-project

Now I already have a project with composer and everything you need from Laravel. Now I just edit my homestead file, add the the new site and done.

folders:
    - map: ~/Code
      to: /home/vagrant/Code

sites:
    - map: project.local
      to: /home/vagrant/Code/my-project/public
      php: "7.3"

databases:
    - my-project

The final step is reloading Homestead with provision and you're done.

Activity icon

Replied to Laravel 5.7 419 Status Code In Ajax Request

So the problem here is that you post to a route that requires a CSRF-token. This token is used to protect your forms from being submitted from another website.

In your case, the token is probably expired. On every request, Laravel generates a new CSRF-token to make sure it's unique. Since you do a new request using the ajax call a new token is generated as well. I think this only happens for you if you do multiple ajax calls in a row on the same page.

This page might help you in how to handle this correctly: https://stackoverflow.com/questions/45668337/how-can-i-get-new-csrf-token-in-laravel-by-using-ajax Another solution is actually using an API endpoint and using a token for the authentication. The routes defined inroutes/api.php by default don't check for the CSRF-token. Its up to you to add authentication to it.

Activity icon

Replied to Eager Loading For Authenticated User ?

Instead of using with, you can use load to eager load the data on an existing model. We call this lazy eager loading

$user = Auth::user():

$user->load (['posts', 'likes', 'comments.parent']);

Documentation: https://laravel.com/docs/8.x/eloquent-relationships#lazy-eager-loading

Mar
23
2 months ago
Activity icon

Replied to SSH'ing Into Forge Server Timing Out After 20 Seconds

@kyleshepherd I had this once as well with Forge. The support told me to delete the server and create a new server instead. Probably something went wrong during the deployment of the server.

Activity icon

Replied to Create New Project Inside Homestead

So the idea behind Homestead and its configuration is that you have a single file to setup the syncing between your local system and homestead in one place. In general, you can configure a directory (or multiple) with all you projects. Then you only need to map a domain name to the directory and you're done. That is the basic idea behind Homestead.

Anyway, can you show your Homestead.yaml file?

Activity icon

Replied to SQLSTATE[HY000]: General Error: 1364 Field 'username' Doesn't Have A Default Value

The reason you get this error is because you can the $this->follows()->save($user). The save method tries to create a new user and connect it to the followers table.

Instead, you need to use attach here because it's a many-to-many relationship.

public function follow(User $user)
{
	return $this->follows()->attach($user);
}
Activity icon

Replied to Why Using A REST API For Fetching Data From Database ?

Well, it depends on how you need to access the data. If you only have a Laravel project with controllers and blade files there is no need for a REST-API since you can query the database directly.

If you have a frontend app/website and you need to fetch data then it makes sense to create a REST-API. The API itself is also just controllers that query the database directly.

Also if you need to use the same backend for different frontend systems it makes sense to create one API which you can use to collect the data on a single place

Community Pillar

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