bobbybouwmann

Developer at Enrise

Hire Me

Experience

1,137,225

1364 Best Reply Awards

  • Member Since 3 Years Ago
  • 1265 Lessons Completed
  • 14 Favorites

20th August, 2018

bobbybouwmann left a reply on What • 8 hours ago

???

bobbybouwmann left a reply on Error When Installing Package Using Composer • 8 hours ago

You should be using composer require benwilkins/laravel-fcm-notification:dev-master It seems that the @ is wrong there!

bobbybouwmann left a reply on Custom Request Class Not Found On VPS • 8 hours ago

How do you use your Request class in your controller? What is the namespace of the Request class? And is the Request in the same directory as the namespace?

This file should be in the `app/Http/Requests/Dashboard/Employees directory.

// GetEmployeesTableRequest.php

namespace App\Http\Requests\Dashboard\Employees;

class GetEmployeesTableRequest extends Request 
{

}

In your controller you will have something like this

// Controller
use App\Http\Requests\Dashboard\Employees\GetEmployeesTableRequest;

public function store(GetEmployeesTableRequest $request)
{

}

bobbybouwmann left a reply on How To Load A Different React App In Each Laravel View • 9 hours ago

You should be able to fid the compiled assets in the public/js directory of your project. Just like your css file you need to include that in your view and you should be good to go!

19th August, 2018

bobbybouwmann left a reply on When Mass Assignment Is Happening? • 18 hours ago

This error is happening on the model level. So only on the create or update call of a model. It only happens when you send in a field that is not part of the guarded or fillable arrays.

bobbybouwmann left a reply on Form Binding For Select Input (not Working For Edit) • 18 hours ago

@RushVan You can also initiate an empty array or collection so you don't have to check if it's isset or not. It will always be empty ;)

17th August, 2018

bobbybouwmann left a reply on L 5.6 : Unable To Deploy • 3 days ago

I dont' see an error in here? Can you post the real error here instead of some file from the framework?

bobbybouwmann left a reply on Best Way To Close Laravel Directories Except /public Folder • 3 days ago

The best way should be only putting your index.php in your public_html directory and the rest should be in a directory above that. This way your document root is pointing to the public directory which in your case is public_html. All items in public_html are accessible via the browser unless you have something like htaccess in front of it that is blocking this. So to be save you should only put your assets and index.php file in there.

bobbybouwmann left a reply on How To Check Multiple Permission Condition In If Statement Using Laravel Spatie Package? • 3 days ago

Your where statement is already incorrect. It should be something like this

->whereIn('categoryid', [1, 2, 3])

Also your if statement seems to be incorrect. In the first call you use the can method, but in the other calls you don't? You should fix that first!

bobbybouwmann left a reply on How Can I Create Query About Relations And Non Relations Tables ? • 3 days ago

Well there is a concept called "Polymorphic relationship". This is exactly what you're looking for! You can find more about in the documentation ;)

Documentation: https://laravel.com/docs/5.6/eloquent-relationships#polymorphic-relations

bobbybouwmann left a reply on Javascript • 3 days ago

????

bobbybouwmann left a reply on Laravel ReflectionException (-1) Class Country Does Not Exist • 3 days ago

You can for example use this package or look into the code for a good solution: https://github.com/mcamara/laravel-localization

Another option is using this package: https://github.com/keevitaja/linguist

16th August, 2018

bobbybouwmann left a reply on How To Create Console Command In Lumen • 4 days ago

Here you go: https://www.codementor.io/seyiadeleke42/creating-your-first-artisan-command-in-lumen-5-5-cvi59gmgl#commands

The blog explains it pretty good for Lumen. There is no command for it, but it's still not that much work ;)

bobbybouwmann left a reply on Laravel ReflectionException (-1) Class Country Does Not Exist • 4 days ago

You need to handle localization using a middleware instead of the URL. In your middleware you can set a session or cookie with the language for the user. Whenever you want to change you just update the session or cookie.

If you do it in the url you need to pass it to every route like you need to do now!

bobbybouwmann left a reply on How Can I Use JSON API Resource In A Lumen Project? • 4 days ago

Well that's true! I think if you include the illuminate/http in your composer.json you should be good to go. That package contains the resource files ;)

However I see that Lumen is already including this dependency. So it should be available. Note that I only looked at the latest Lumen ;)

bobbybouwmann left a reply on L5.6 - Php Artisan Down --allow=... Not Working • 4 days ago

Mmh it's working fine for me

$ php artisan down --allow=127.0.0.1 --allow=192.168.0.0/16
Application is now in maintenance mode.
$ php artisan up
Application is now live.

Are you sure you used this syntax? Also are you using the latest artisan file? If you upgraded in the past you might have missed something there!

15th August, 2018

bobbybouwmann left a reply on UpdateOrCreate Will Create But Not Update • 4 days ago

Your code looks correct to me. However it seems like the columns are not being passed correctly. The correct code should look like this:

 ItemUser::updateOrCreate([
    'user_id' => auth()->user()->id, 
    'item_id' => request('item_id'),
], [
    'selling_currency' => request('sellingcurrency'),
    'selling_price' => request('sellingprice'),
    'selling_quantity' => request('sellingqty'),
    'buying_currency' =>request('buyingcurrency'),
    'buying_price' => request('buyingprice'), 
    'buying_quantity' => request('buyingqty'),
]);

I think it's going wrong here because either the user_id is empty or the request doesn't have a item_id? Can you check that first?

Documentation: https://laravel.com/docs/5.6/eloquent#other-creation-methods

14th August, 2018

bobbybouwmann left a reply on How Can I Get List Out All User That Request The Project That Created On This Admin • 6 days ago

$admin = auth()->user();

$admin->load([
    'projects'
    'projects.apply' => function ($query) {
        $query->where('apply_type', 2);
    }),
    'projects.apply.user',
])->get();

After that you can probably loop over it.

// Example in a view
@foreach ($admin->projects as $project)
    <h2>{{ $project->project_title }}</h2>

    <ul>
        @foreach ($project->apply as $apply) 
            <li>{{ $apply->user->name }}</li>
        @endforeach 
    </ul>
@endforeach

Something like this. Note that I didn't test this ;)

bobbybouwmann left a reply on Laravel ReflectionException (-1) Class Country Does Not Exist • 6 days ago

You use a prefix on all your routes, but Laravel can't guess what that prefix is! So instead you need to pass that prefix to every route now

route('login', ['country' => 'en'])

Maybe this is not what you're looking for!

12th August, 2018

bobbybouwmann left a reply on JSON API Format And Laravel • 1 week ago

@PatrickL You probably can. If it's in the header you can check for it ;)

bobbybouwmann left a reply on Laravel ReflectionException (-1) Class Country Does Not Exist • 1 week ago

Did you register the middleware class in your Kernel.php file?

protected $routeMiddleware = [
    // Other middleware routes

    'country' => \App\Middleware\CountryMiddleware::class,
];

Also make sure that your class is in the same directory as the namespace suggests because PSR-4 you're required to do so! So for example a class with the namespace App\Models should be in the directory app/Models (note the uppercase).

bobbybouwmann left a reply on Wrong Id From Authenticate • 1 week ago

It seems that the cookie is not deserialized! Do you use some custom cookie? Or anything else custom within the authentication part? I've never seen this before in a default Laravel setup!

bobbybouwmann left a reply on Avored E Commerce • 1 week ago

Glad you found out what the problem was ;)

11th August, 2018

bobbybouwmann left a reply on Override "setAttribute" And "getAttribute" In Eloquent Model • 1 week ago

Instead of using setAttribute you can for example use the model events to apply the correct data to your model

// In your trait that you include in your model
public static function bootEnumFields()
{
    static::saving(function ($model) {
        $model->setEnumFields();
    });
}

protected function setEnumFields()
{
    $enumFields = null;

        if (is_array($this->enums) && count($this->enums) > 0) {
        $enumFields = array_intersect_key($attributes, array_flip($this->enums));
    }

    if (is_array($enumFields)) {
        foreach ($enumFields as $key => $value) {
            // Do your stuff here
            $this->attributes[$key] = 'SomeValueHere';
        }
    }
}

Note: This is not tested, but you probably get the idea ;)

I'm not sure about how to handle getAttribute. Maybe you can use a custom attribute custom as an example. Not really sure.

Documentation: https://laravel.com/docs/5.6/eloquent-mutators#attribute-casting

Overriding the methods is fine as well in the end. However if you have multiple traits it's not gonna work of course!

bobbybouwmann left a reply on How Does Everyone Sync Their MorphToMany Relationships? • 1 week ago

Morphing and a many-to-many are complete different relationships. As far as I know you don't even need a sync method for morph relationship.

Maybe you can give us an example?

bobbybouwmann left a reply on PHP Object Lifecycle • 1 week ago

It's sounds like you need the singleton pattern!

Example: https://stackoverflow.com/questions/203336/creating-the-singleton-design-pattern-in-php5

bobbybouwmann left a reply on Entrust @role And @permission Directives Not Rendering In Blade, Laravel 5.6 • 1 week ago

Entrust only works with one guard which is defaulted to the web guard. You can change guard, but you can't use both of them. It's just not supported by the package.

You either need to look for another page or implement your own functionality for this ;)

bobbybouwmann left a reply on Specific Post Permissions • 1 week ago

@click That's what I meant indeed by setting a flag on the post. This way you can determine what role/permission you should check for!

bobbybouwmann left a reply on Mix At Production • 1 week ago

  1. Well you develop your application locally but everytime you compile your assets they will be written to your public directory so you can use them in your application. Now the thing is that you will commit these changes as well everytime you push your application. This means that when you work together with someone for example the assets will already be compiled and the other won't have to compile them to have a working product. However if that other person makes a change assets will be compiled again and you have a new commit with multiple changes. The assets itself and the compiled assets. Now when you don't commit these compiled files, you will never have merge conflicts or a lot of files to commit, because you only commit the real assets and not the compiled onces. Your server should than compile your assets. This compiling should be done during the deployment for example. Now if you work alone on a project you're fine, but if you work with others this can improve the project a lot. Is that clear?

  2. Fair enough.

  3. Well the mix thing itself isn't that hard at all. However when you want custom stuff it will get interesting and indeed you have a huge learning curve! I'm not an expert to be honest but I would still recommend to use Laravel Mix in the end ;)

bobbybouwmann left a reply on JSON API Format And Laravel • 1 week ago

Well the first one can be pretty easily checked for by fetching all the headers from the request and checking on it

// Inside your middleware
$headers = request()->headers->all();

if (isset($headers['content-type']) && $headers['content-type'] === 'vnd.api+json') {
    return response()->json(['message' => 'Unsupported Media Type'], 415);
}

Note: You can make this code more readable using collections and stuff, but I think you get the idea this way ;)

For your second question you need some kind of abstraction right. So you can for example create your own response class that always has some kind of headers. I would personally build a class around the response->json() helper and just pass in your own extra details you need ;)

You might find this series interesting for that: https://laracasts.com/series/incremental-api-development

Let me know if that is clear for you!

bobbybouwmann left a reply on Avored E Commerce • 1 week ago

bobbybouwmann left a reply on Mix At Production • 1 week ago

So Laravel mix will automatically minify everything you when you run in production mode, however you are not using that anymore so you don't get that extra stuff! So yes you need to minify it yourself now!

However I hear you say something about screwing Git up. The process with assets like this should be development locally and compiling on the server. This way you don't have everything in your repository and you won't have merge conflicts with all the compiled files all the time. This also means you need to run node and npm on your server of course.

If you don't do this you will always need to compile your edits in production mode, push that and deploy.

Any reason why Laravel Mix is nothing for you?

Note that you can still use Laravel Elixir if you wish: https://laravel.com/docs/5.3/elixir

bobbybouwmann left a reply on Upload Excel Into Vuejs • 1 week ago

Well the process is pretty simple. You just need to send the correct data and handle it in your controller ;)

// VueJS
<template>
    <input class="input" type="text" name="name" placeholder="File name" v-model="fileName" required>
    <input class="file-input" type="file" ref="file" name="file">
</template>

<script>
data() {
    fileName: '',
        attachment: '',
},

submitForm() {
    this.formData = new FormData();
    this.formData.append('name', this.fileName);
    this.formData.append('file', this.$refs.file.files[0];);

    axios.post('files/add', this.formData, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    }).then(response => {
            // handle success response
    }).catch(error => {
        // handle failed response
    });
},

</script>

I hope you get the idea ;)

// Controller

public function store(Request $request)
{
    $file = $request->file('file');
    $ext = $file->getClientOriginalExtension();
    $type = $this->getType($ext);
    $fileName = $request['name'] . '.' . $ext;

        if (Storage::putFileAs('/storage/uploads', $file, fileName)) {
        // Make sure you storage the location of the file somewhere. For example in your database
    }
    
    // Return a proper response
    return response()->json([
        'success' => true,
    ]);
}

Documentation: https://laravel.com/docs/5.6/filesystem#file-uploads

bobbybouwmann left a reply on How Does Everyone Sync Their MorphToMany Relationships? • 1 week ago

I'm curious about your use case here, because I never needed a sync method for that. Maybe you can explain your challenge and we can help you with a solid solution?

10th August, 2018

bobbybouwmann left a reply on Location Tracking Android With Laravel • 1 week ago

Well, the REST Api should be enough ;)

bobbybouwmann left a reply on Location Tracking Android With Laravel • 1 week ago

Well Android works the same way right. So your phone will register the location and that data can then be retrieved in the android app. When you want to store it in your Laravel database for example you just need to push it from android to your app. This can be done using a REST API or using Pusher as well :)

Not really sure what you're looking for, but this might help: https://pusher.com/docs/android_quick_start

9th August, 2018

bobbybouwmann left a reply on How To Use Other Font Awesome Version In Jeroennoten/Laravel-AdminLTE Package? • 1 week ago

You can't just upgrade to Font-Awesome 5 because icon names might have changed and the update also requires you to make some changes to the HTML!

So if you really want this, you can do this pretty easily by just loading in the new font-awesome CDN for example and use the correct classes in your icons and you shpuld be good to go!

Documentation: https://fontawesome.com/how-to-use/on-the-web/setup/upgrading-from-version-4

bobbybouwmann left a reply on Performance Increase Of Route::cache • 1 week ago

Well it will give you a small improvement. It depends a bit on how many routes you have in the end. php artisan route:cache will create a mapping of your routes in a single file and then use that during runtime. This mapping contains the correct path to the controller and so on. So no extra lookup is needed!

If you don't use route caching it will just read your routes file which is a bit slower because it needs to determine which controller and action etc.

8th August, 2018

bobbybouwmann left a reply on Set Brackets After From With Eloquent • 1 week ago

Why don't you just use a raw query?

7th August, 2018

bobbybouwmann left a reply on Using Factories For Non-Eloquent Entities • 1 week ago

It's probably possible will non Eloquent classes, but you can't use Currency for that because it's an abstract class. Instead you need to create a factory for USD. That should work as far as I know!

Proof of Concept :D

<?php

class Currency
{
    /**
     * @var string
    */
    public $symbol;

    public function __construct(array $data)
    {
        $this->symbol = $data['symbol'];
    }
}

Factory

$factory->define(\Currency::class, function (Faker\Generator $faker) {
    return [
        'symbol' => '$',
    ];
});

Working example in tinker

$ php artisan tinker

>>> factory(\Currency::class)->make();
=> App\Currency {#1090
    +symbol: "$",
  }
>>>

bobbybouwmann left a reply on Dusk Integration In PhpStorm • 1 week ago

Not really sure if that's possible because Dusk needs to launch a browser to perform the tests. So I think it's possible using the normal command line tools, but not for a single test.

PHPUnit provides an option called filter which is useful for that, however Dusk doesn't support that as far as I know!

Also running a browser test on every save of a file is really really slow and resource extensive! I would just run those things in your CI or at the end of the day ;)

bobbybouwmann left a reply on New User Does't Get Registered • 1 week ago

You probably have a view where you access f_name of a user. This object is probably null. This happens for example when you're not logged in.

bobbybouwmann left a reply on Validation Rules And Modal Dialog • 1 week ago

@rohitcp They thread is over 2 years old....

bobbybouwmann left a reply on Trying To Create Custom Log Channel Laravel 5.6 • 1 week ago

So it seems your logger can be found and that monolog is actually trying to insert the data. However it seems that the given data is incorrect. It looks like your application is sending in json as a string, but it wants an array of object.

Your code looks good to me, so that shouldn't be the issue! Not really sure what it could be right now!

bobbybouwmann left a reply on Specific Post Permissions • 1 week ago

Well I would probably create one permissions that will do this. So a post_show_admin and post_show_regular permissions for example. This permission should then be connected to the admin role or regular role. That should be it right? You only need a flag on your post to determine to what role/permission the post belongs ;)

bobbybouwmann left a reply on Trying To Create Custom Log Channel Laravel 5.6 • 1 week ago

What is the full stack trace? Where is the $document coming from?

bobbybouwmann left a reply on New User Does't Get Registered • 1 week ago

Well, what did you change? Do you get any errors? Any info in the storage/logs/laravel.log file?

bobbybouwmann left a reply on Pivot Table With Timesamps Returning Null After Running The Seeder Class • 1 week ago

When you use insert you need to be specific about your created_at and updated_at fields.

When you use a model, Laravel understands that it needs to set those dates. However with insert they will default to null.

You can get around this by either using the model for creating data. Or you can provide the dates keys with timestamps

DB::table('emailtemplates')->insert([
    // Other fields

    'created_at' => \Carbon\Carbon::now()->format('Y-m-d H:i:s'),
    'updated_at' => \Carbon\Carbon::now()->format('Y-m-d H:i:s'),
]);

Or let the database handle a default value by doing something custom in your migration.

$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP'));

bobbybouwmann left a reply on Is There Anyway To Have Vue Reload A Page? • 1 week ago

Have you tried using location.reload();. That should just reload the current page based on the url in your browser :D

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.