bobbybouwmann

bobbybouwmann

Member Since 4 Years Ago

Apeldoorn, The Netherlands

Developer at Enrise

Experience Points 1,360,235
Experience Level 50

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 1486
Lessons
Completed
Best Reply Awards 1675
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

25 Jun
10 hours ago

bobbybouwmann left a reply on Display Pdf File In Blade

The current code you have wll return a download response for the PDF or in modern browsers it will open it in a new tab. I don't think you really want that at this point. 'Content-Disposition' => 'inline; this part will make it open in a new tab rather than downloading the file.

If you really want to show the PDF in a view you should probably use an iframe for that: https://medium.com/@flipbook/3-steps-to-embed-pdf-documents-in-html-website-56f14b904174

bobbybouwmann left a reply on Best Practice For Test Cases For CURL Testing?

This might help: https://stackoverflow.com/questions/7911535/how-to-unit-test-curl-call-in-php

Another solution is using Guzzle, which you can easily mock!

bobbybouwmann left a reply on Vuejs With Laravel Is Not Working On Android/iphone

What browser are you using? It should work on the chrome browser by default on your phone!

bobbybouwmann left a reply on Toggle Navigation On Page Load/change

Well then you can catch this in your vue router right? Whenever you change route you simply call the mobileNavToggle method.

Documentation: https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards

You might need to keep the state of the navigation in a different variable. Like a separated component or in localStorage or maybe even vuex. This way you can easily toggle it from different locations. I think the easiest way for you at this point is adding a method for closing the navigation and call that on each route

const router = new VueRouter({ ... })

router.beforeEach((to, from, next) => {
    this.closeNavigation(); 
    
    next();
});

bobbybouwmann left a reply on Npm Run Watch Displays Error After Compiling Then Stops Watching

Most of the time this error means that you have to wrong file permissions on your assets. Make sure they all have the correct rights and belong to the correct user.

bobbybouwmann left a reply on CRON Job On Production Server

You shouldn't be running php artisan schedule:run once a day. It should basically run every minute. This way your application knows when to fire off which job. That's why we have the Kernel class ;)

If you run it every minute it will pick it up sometime at least a day.

Timezones are hard in general. In general it's recommended to either have everything in UTC or everything on another timezone, in your case Asia/Kolkata.

bobbybouwmann left a reply on Toggle Navigation On Page Load/change

Are you using the vue router to handle your page changes? Or are you using another approach? It depends on that basically!

24 Jun
1 day ago

bobbybouwmann left a reply on Trying To Get Property 'title' Of Non-object

It seems that your activity has a subject, but that the subject doesn't have a thread.

In this case you can eager load them and check on it

// Controller

$activities = $user->activity()->latest()->with('subject.thread')->get();

// View
@if ($activity->subject->thread)
    <h6 class="tt-title">
        <a href="/threads/{{ $activity->subject->channel->slug }}/{{ $activity->subject->thread_id }}" class="font-weight-bold">
            {{ $activity->subject->thread->title }} <!-- ERROR HERE -->
        </a>
    </h6>
@endif

Alternatively you can only select the activities that actually have a thread

// Controller

$activities = $user->activity()->latest()->whereHas('subject.thread')->with('subject.thread')->get();

bobbybouwmann left a reply on Where Clause On Nested Relationships In Eloquent

What is not working on the query? I see a huge query here, but what is going wrong? What part is not working for you?

bobbybouwmann left a reply on Unicode Problem, Output Strange Words When In Chinese

What kind of data do you put into the editor? Just regular chinese text and images?

bobbybouwmann left a reply on Handling Image Uploads For A Model That Has Not Been Created Yet

Well you have two options here. Either upload the images and attach them later to the event whenever it's created or create the event before you go to the create form.

So for the first option you can store the path to the event in the session for example and then later reference that session to attach the images. However when images are still in session and the user click away the browser you probably have some images on your server that have never been attached to the event. You can for example store the images in a different location when creating and still save the reference in the session. You can then have a cronjob running everyday to clear out the images in that directory. Once the user saves the form you move the images to the correct directory and they will never be deleted.

For the other solution you kinda have the same problem. You can create the event beforehand and show that to the user, this way you already have an id. However this also means that if the user never finishes creating the event you have an empty event hanging around. This makes it easier for the image upload part, but you're still stuck with dangling events. You can for example set a flag on if it's been created by the user or by the system so you know which one you can delete, including the connected images.

Personally I would go for option one since you need to find a solution for the images and not for the event itself

bobbybouwmann left a reply on Using Doctrine With Third Party Packages

@veleous Yeah that will definitely happen! Anyway good luck ;)

22 Jun
3 days ago

bobbybouwmann left a reply on MorphOne And Model Events

Well in this case you shouldn't be using updateOrCreate, but just create.

updateOrCreate takes two arrays. The first array are the fields you want to select the status for. if something is returned it will perform an update otherwise a create. The second array are the fields you want to use when updating or creating a record.

Because you don't pass a second array Laravel doesn't know how to create the status model. If we dive into the code you can see that here

public function updateOrCreate(array $attributes, array $values = [])
{
    return tap($this->firstOrNew($attributes), function ($instance) use ($values) {
        $instance->fill($values)->save();
    });
}

Anyway, the created event should only ever be fired once for the Call model. So in that case you're save to use create here instead.

$model->status()->create([
    'code' => 1,
]);

If you really must use updateOrCreate you can do this, which is not that nice ;)

$model->status()->updateOrCreate([
    'code' => 1,
], [
    'code' => 1,
]);

bobbybouwmann left a reply on Best Way To Add Custom MessageSent Event To Mailer

In this case you don't have to customize the even. You can just get the subject from the Swift_Message that is being passed to the event right?

// SomeListener

public function handle(MessageSent $event) 
{
    $subject = $event->getSubject();
}

Or am I maybe missing something here?

bobbybouwmann left a reply on Using Doctrine With Third Party Packages

Well this is a very good question! As far as I know most packages do you Eloquent if they use models at all! However there are also a lot of packages that don't use a database at all, they only use caches as an example. S

So basically you would block yourself for all packages that use a database. Think about role/permissions packages, admin panels, extensions on users, activity log.

So in general you would have to rebuild a lot of packages to make most things work.

May I ask why you want to switch to doctrine?

21 Jun
4 days ago

bobbybouwmann left a reply on Disable Touches On FirstOrCreate (laravel 5.5)

To save a model without touching pass false to save method:

$model = new Model;

$model->save(['touch' => false]);

Of course setTouchedRelations will work as well:

$model = new Model;
... // do what you need

$model->setTouchedRelations([]);
$model->save();

However you seem to want to use the current available values in the database, you could do something like this

$model->firstOrCreate(
    [
        'id' => 1
    ],
    [
        'updated' => DB::raw('updated_at'),
    ]
)

This basically selects the same previous value and inserts that value again.

I would personally go for the first option which is more readable and understandable ;)

bobbybouwmann left a reply on Sort And Filter Posts With Ajax

Well the sorting part is what you add at the end right? In your case you add everything to some variable and work from there. You can simply at the sorting after that.

Also I saw that you added pagination and latest to basically all queries, so you probably can add that at the end as well :)

$query = $user->posts()->with('comments', 'tags')->whereIn('privacy', [1, 2])->where('status', 1)->where('archived', 0);

if (request()->has('image')) {
    $query->where('type', 4);
} elseif (request()->has('video')) {
    $query->where('type', 5);
}

if ($request()->has('sortBy') &&$request()->has('sortDirection')) {
    $query->orderBy(request('sortBy'), request('sortDirection'));
}

$postall = $query->latest()->paginate(15);

Something like this should put you in the right direction?

20 Jun
5 days ago

bobbybouwmann left a reply on Relationship From Query?

@dermanomann Which one works for you? :P

bobbybouwmann left a reply on Define Broadcaster Per Events

At this point it's not possible because it's not in the core of Laravel, however you can easily add this ;) Could be your contribution to the framework ;)

But thinking about it, it doesn't make much sense to have multiple broadcasters on the other hand we can have multiple queue connections so in that matter it makes sense

bobbybouwmann left a reply on Append Object To LocalStorage.

@nanadjei2 It doesn't really matter as long as you double check the data when sending it to the backend. So for example double check stock, only send ids to the backend and let the backend determine the price for the order and so on.

It can be useful because it's a lot faster than talking to the backend all the time, but in the end you need to go to the backend to double check everything, or read it from some other storage

bobbybouwmann left a reply on How To Validate Both The Key And Value Of A Request Array

I think you can do something like this

$rules = [
    'sell.*' => 'required|sell|exists:stock,id',
    'sell.*.*' => 'required|sell|exists:exchange,id',
]);

Note: I didn't tested this at all!

Another solution would be structuring the data a bit differently.

{
    "sell": {
        "111":[
            {"id": 1},
            {"id": 2},
            {"id": 3}
        ]
    }
 }

I believe you can then do this in your validation

$rules = [
    'sell.*' => 'required|sell|exists:stock,id',
    'sell.*.id' => 'required|sell|exists:exchange,id',
]);

Documentation: https://laravel.com/docs/5.8/validation#validating-arrays

If this isn't working I would probably make my own custom validation rule to validate this really specific case!

bobbybouwmann left a reply on Returning The Distinct Results Of Polymorphic Relationship

To be honest this is quite hard to do with the regular relationships! Instead I would probably write a raw query for this, that will probably be faster as well!

19 Jun
6 days ago

bobbybouwmann left a reply on Relationship From Query?

Yes you can, however you need to have a specific factor to select on

public function offer()
{
return $this->hasOne(App\Offer)->where('paid', 1);
}

Source: https://stackoverflow.com/questions/41673611/laravel-having-a-hasmany-as-well-as-a-hasone-relationship-on-the-same-mode

bobbybouwmann left a reply on Dynamic Class Name: On $(document).on('chang','.className', Function(){})

Why not give both elements an extra class that is the same. For example .radio-group > input

I haven't tried this, but I think you can do something like this as well

$(document).on('change', "[class^='radio-group'] input", function(e) {})

Note: I'm not sure if this works :see_no_evil:

bobbybouwmann left a reply on How To Redirect User Into Its Default Homepage

What is not working? What did you change?

bobbybouwmann left a reply on Append Object To LocalStorage.

storeInLocalStorage(item, keyAndvalue) {
    var data = localStorage.getItem('item);

    data = data ? JSON.parse(data) : [];

    data.push(keyAndValue);

    localStorage.setItem(item, JSON.stringify(data));
}

Note that keyAndvalue should be an array as well and not already a json string. Otherwise you need to parse that first to an array before you can push it to the array of data.

In your case you might want to do this instead

storeInLocalStorage(item, key, value) {
    var data = localStorage.getItem('item);

    data = data ? JSON.parse(data) : {};

    data[key] = value;

    localStorage.setItem(item, JSON.stringify(data));
}

storeInLocalStorage('new_order', 'value1', 'value2');

Source: https://gomakethings.com/how-to-update-localstorage-with-vanilla-javascript/#add-to-an-object

bobbybouwmann left a reply on Voayger

Your question is a bit vague, but I think you're using Laravel Voyager right?

Did you check the docs on roles and permissions?

Documentation: https://docs.laravelvoyager.com/core-concepts/roles-and-permissions

bobbybouwmann left a reply on Laravel Nova Custom User Model

You need to make sure that you have a custom driver setup for that model

// config/auth.php

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'admin' => [
        'driver' => 'session',
        'provider' => 'admin',
        'passwords' => 'admin',
    ],
],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],

    'admin' => [
        'driver' => 'eloquent',
        'model' => App\Admin::class,
    ],
],

'passwords' => [
    'users' => [
        'provider' => 'users',
        'table' => 'password_resets',
        'expire' => 60,
        ],
    'admin' => [
        'provider' => 'admin',
        'table' => 'password_resets',
        'expire' => 60,
    ],
],

Let me know if that works for you!

18 Jun
1 week ago

bobbybouwmann left a reply on V-menu Is Not Working

I'm not sure where it's going wrong at this point. I just checked the docs for you, can't do much more for you at this point!

bobbybouwmann left a reply on How To Create Send Code Again?

@mvd Your patience is amazing!

bobbybouwmann left a reply on Laravel Passport - Store Token In Cookies

So far no problems. If authentication works fine than the only thing that remains are the api routes ;)

bobbybouwmann left a reply on Using JQuery And Ajax To Populate A Table

I think it's better to use a foreach loop here

$.each(data, function(key, value) {
    var html = '<tr>'+
        '<td>' + value.hotel_id + '</td>' +
        '<td>' + value.available_date + '</td>' +
    '</tr>';   

    $('#datatable tr').first().after(html);
});

Something like this.

Also you can just dump the data object using console.log and seeing it in your console. This way you might get a clue on how you can loop over it ;)

bobbybouwmann left a reply on V-menu Is Not Working

Your @click"" is empty...

I did mention this in my reply

@click="" // Put your url in here

bobbybouwmann left a reply on How To Create Send Code Again?

It seems to be that some model you're trying to retrieve is missing or the url doesn't exist. Without more information I can't really help you!

bobbybouwmann left a reply on How Do I Improve Bulk Mailing Performance With Redis Queues?

@thebigk Well Laravel can only send one email at the time right. So I think you have two options here. Either run more workers so you can process more jobs from the queue at the same time. I would probably run those workers on separated servers.

Option two is using a third party mail delivery services where you can just send an array of email addresses and they will then figure out how to send the emails as fast as possible with their own internal queue. This way you don't have to think about it and it also doesn't impact the performance on your own webserver ;)

bobbybouwmann left a reply on V-menu Is Not Working

@nafeeur10 Seriously? "Not working"... Can you be more specific. What is not working? How does your code look right now? Did you look at the code examples in the documentation?

bobbybouwmann left a reply on Laravel Passport - Store Token In Cookies

@tomspeak No problem ;) I've been in this situation as well hehe

bobbybouwmann left a reply on How To Create A Record From JSON Params?

You can do something like this

$json = request()->operations;

$data = json_decode($json, true);

// Map the data to new objects
foreach ($data as $item) {
    $operation = new Operation();
    $operation->collaborator_id = $item['collaborator_id'];
    $operation->building_id = $item['building_id'];
    $operation->vehicle_plate = $item['vehicle_plate'];
    // And more fields, well you get the idea
    $operation->save();
}

Another solution is mapping the data 1:1 to the model, but then you need to make sure all fields are fillable. If that is the case you can do something like this

$json = request()->operations;

$data = json_decode($json, true);

// Map the data to new objects
foreach ($data as $item) {
    $operation = Operation::create($item):
}

This should put you in the right direction! Let me know if everything worked out for you :D

bobbybouwmann left a reply on V-menu Is Not Working

You're missing the click action for each item.

<v-list>
    <v-list-tile
        v-for="(item, index) in items"
        :key="index"
        @click="" // Put your url in here
    >
        <v-list-tile-title>{{ item.title }}</v-list-tile-title>
    </v-list-tile>
</v-list>

You can see that in the code examples here as well: https://vuetifyjs.com/en/components/menus#examples

bobbybouwmann left a reply on How To Create Send Code Again?

What is your question? What is not working? Do you get an error?

We can't really help you if we don't know what is wrong here!

17 Jun
1 week ago

bobbybouwmann left a reply on Htaccess And My Own 404 Page

Yes this would normally work if you would go to some url that doesn't exist at all!. However you're talking to a PHP application. It can only throw a 404 whenever PHP has run, you can't do it before that. Also the current rewrite rule always points to index.php which will handle the routing for you!

So you have two options here: You need to whitelist all your routes in the htaccess file as well so you can then decide if you want to go to PHP or if you want to go to your custom html page.

Or you do the custom 404 page handling part by Laravel. If you create the resources/views/errors/404.blade.php file you can put anything you want in there ;)

Documentation: https://laravel.com/docs/5.8/errors#http-exceptions

bobbybouwmann left a reply on Laravel Passport - Store Token In Cookies

Laravel comes by default with the Authenticate middleware. In there you should be able to check on the cookie and perform some check on the user if it's authenticated or not.

Or simply convert the cookie to a header in your middleware

// app\Http\Middleware\Authenticate.php

public function handle($request, Closure $next, ...$guards)
{
    if ($request->cookie('cookie-name')) {
        $request->headers->set('Authorization', 'Bearer ' . $request->cookie('cookie-name'));

    }

    $this->authenticate($request, $guards);

    return $next($request);
}

Note: I didn't test this but it should point you in the right direction!

bobbybouwmann left a reply on How To Change The Category Translation On The Fly?

Well it's your code right? I'm not sure how I can help you in any way. Apparently you have to be specific with whereTranslation for the PostCategory relationship, maybe you also need to do that for the specific category model?

We need much more information to actually understand your system and help you!

bobbybouwmann left a reply on Horizon 403 In Public, Gate Problem

Do you have an authenticated user in any of the other middlewares? I don't have any issues with Horizon at this point so it's hard to help you with this!

bobbybouwmann left a reply on Recursive Tags

Here is a package for that: https://github.com/staudenmeir/laravel-adjacency-list

If you want to set this up yourself you can use something like this: https://stackoverflow.com/questions/26652611/laravel-recursive-relationships#answer-52338716

In the end you need to loop over it recursively. If you have a lot of tags this might give you a performance issue, but that just depends on the data!

bobbybouwmann left a reply on Laravel Passport - Store Token In Cookies

As far as I know your cookie should only be there for reading purposes and not for something else. You need to extract the value to send it along as the header.

An alternative option is overriding the auth:api middleware with your own check on the cookie instead of the header.

Here is also an tutorial on how to properly set up an API with passport being very secure: http://esbenp.github.io/2017/03/19/modern-rest-api-laravel-part-4/

bobbybouwmann left a reply on SQLSTATE[HY000] [2002] No Such File Or Directory

So how did you test the database at this point? From the application or from some third party tool?

bobbybouwmann left a reply on Does Queue:work Only Process The 'default' Queue?

  1. Yes you need to be specific here, otherwise Laravel doesn't know what kind of queue to start. Can be anything database, redis, sqs and so on
$ art queue:work --help

Usage:
  queue:work [options] [--] [<connection>]

Arguments:
  connection               The name of the queue connection to work
  1. You shouldn't be really worried here, that's why you use SQS right ;) The only thing you need to keep in my min is that 300.000 jobs is a lot so you need a big or multiple servers to handle this load. SQS is only a queue, the actual job will be performed on the server where your Laravel application runs. Laravel will just ask SQS to see if there is a job and then pick it up.

  2. I don't have much experience with SQS, but just to be sure I would create the queue ;)