bobbybouwmann

Developer at Enrise

Experience

815,995

986 Best Reply Awards

  • Member Since 2 Years Ago
  • 864 Lessons Completed
  • 12 Favorites

18th January, 2017

bobbybouwmann left a reply on Getting Count From A Array • 4 hours ago

Not really sure what you mean, but I think it's something like this

@foreach ($cust as $invoice)
    <p>Count: {{ count($invoice->array_field) }}</p>
@endforeach
});

bobbybouwmann left a reply on What's The Point For Pipe() Method? • 4 hours ago

this was you can do whatever you want in the callback of a pipe. You can for example use your own method in the callback, which is not supported by the collection class.

See: https://murze.be/2016/05/getting-package-statistics-packagist-redux/

bobbybouwmann left a reply on Getting Count From A Array • 4 hours ago

What do you mean with count? What do you want to count?

17th January, 2017

bobbybouwmann left a reply on How To OrderBy Using Related Column • 1 day ago

You can't right now. The only way is a join

16th January, 2017

bobbybouwmann left a reply on PHP Extensions Ie. Php7.0-xml Or Php-xml • 1 day ago

I believe the PHP repository for apt-get was changed and requires now to prepend the php version for installing packages. For example:

php5.6-xml
php7.0-xml
php7.1-xml

So you need to get the correct version based on your php version. The regular php-xml package for example is not suitable anymore.

bobbybouwmann left a reply on Laravel Auth In 5.3 Version , New Change ! • 1 day ago

It should work just fine. I currently have this setup on one of my projects.

// app/Http/Controllers/Controller.php

abstract class Controller extends BaseController
{
    protected $user;

    public function __construct()
    {
        $this->middleware(function ($request, $next) {
            $this->user = auth()->user();

            return $next($request);
        });
    }
}

// app/Http/Controllers/PostsController.php

class PostsController extends Controller
{
    public function index()
    {
        $posts = $this->user->posts;    

        return view('posts.index', compact('posts'));
    }
}

Also have you tried to update to a higher version? To the latest 5.3 for example?

bobbybouwmann left a reply on Database (model) Inheritence • 1 day ago

Great!

bobbybouwmann left a reply on Database (model) Inheritence • 2 days ago

I think polymorphic relations are the best option here. It's a deep dive, but if you understand how it works it really easy to work with.

If you find it hard to get started with polymorphic relations I would recommend you to take a documentation example and then slightly convert it to your code base and see how that works for you.

bobbybouwmann left a reply on Mailables - Defining/specifying Queue Name • 2 days ago

You need to define the queue on the message it self. Here is an example from the docs

$message = (new OrderShipped($order))
    ->onConnection('sqs')
    ->onQueue('emails');

Mail::to($request->user())
    ->cc($moreUsers)
    ->bcc($evenMoreUsers)
    ->queue($message);

bobbybouwmann left a reply on With A HasMany Relationship, How To Get Only The Parents Without The Children? • 2 days ago

Do you maybe have the property $with set on your Parent model?

class Parent extends Model
{
    /**
     * The relations to eager load on every query.
     *
     * @var array
     */
    protected $with = [
        'children',
    ];
}

If so you should remove it and only call it when you need it ;)

bobbybouwmann left a reply on How To Manually Provide Smtp Information For Mailable • 2 days ago

If you want to queue your emails you should change the settings in your Mailable class, otherwise it will use the default config.

When you use Config::set() it will only set it for that request, so when you queue the mail it will be in a new request.

bobbybouwmann left a reply on How To Manually Provide Smtp Information For Mailable • 2 days ago

You can set the config on runtime.

Config::set('mail.port', 587); // default

You can simply replace the values with values from the database ;)

Note that this can give issues when users give in incorrect details and the mails won't send

bobbybouwmann left a reply on Updating An Extra Pivot Value • 2 days ago

Something like this should work fine

$player = Tournament::players()->findOrFail($playerId);
$player->pivot->paid = $data['paid'];
$player->save():

Make sure that you add the pivot field to the relation as well

// Tournament.php
public function players()
{
    return $this->belongsToMany(Tournament::class)->withPivot([
        'paid',
    ]);
}

// Player.php
public function tournaments() {
    return $this->belongsToMany(Tournament::class)->withPivot([
        'paid',
    ]);
}

bobbybouwmann left a reply on Laravel Mix Without Laravel And Vue? • 2 days ago

Laravel mix already works out of the box for none Laravel projects...

See the readme: https://github.com/JeffreyWay/laravel-mix/blob/master/docs/installation.md

13th January, 2017

bobbybouwmann left a reply on Php Artisan Migrate Not Working • 4 days ago

Did you already migrate other tabels? Did you try to completely drop the database and run the migrations again?

bobbybouwmann left a reply on Is Session::save() Required Each Time I Write To Session? • 4 days ago

The best way to work with sessions is simply passing them to the request.

See this example in the docs: https://laravel.com/docs/5.3/session#using-the-session

bobbybouwmann left a reply on Is There A General Course Of How To Set Up Our Workflow? • 4 days ago

No problem ;) If you have more questions just ask away :D

bobbybouwmann left a reply on How To Test A Feature Which Contains Relationships • 5 days ago

No problem ;)

bobbybouwmann left a reply on Is There A General Course Of How To Set Up Our Workflow? • 5 days ago

This series might help:

Forge is a paid service that can setup a server for you. You simply connect your github to and than you can deploy stuff to the world!

bobbybouwmann left a reply on How To Test A Feature Which Contains Relationships • 5 days ago

You don't need to have a unit test to test your feature. The test I showed you are more integration tests, they test more then just a functionality, since they also check the database and insert in the database.

You can for example write a unit test for an example, but your feature is also covering that if you associate the models and check that in the database.

I would probably write tests like this

public function it_tests_if_an_address_can_be_added_to_a_user()
{
    $this->visit('users/create')
        ->fillField('username', 'username');
        ->fillField('password', 'password');
        ->fillField('address[street]', 'Randomstreet');
        ->fillField('address[number]', '123');
        ->fillField('address[city]', 'Randomtown');
        ->click('Submit');

    $this->seeInDatabase('users', ['username' => 'username']);

    // This might be a custom helper
    $user = $this->grabUserByUsername('username');

    $this->seeInDatabase('address', [
        'street' => 'Randomstreet'
        'user_id' => $user->id,
    ]);
}

This is a really basic example for an integration tests, but you still need to do some stuff in your controllers to get it to green. Additionally you can create extra unit tests. Something like this might work for you

public function can_assign_address_to_user()
{
    $user = factory(User::class)->create();

    $address = [
        'street' => 'Randomstreet',
        'number' => 123,
        'city' => 'Randomtown',
    ];
    
    // This might be a method on your user model that you call in your controller. 
    // In your controller $address would be request('address');
    $user->assignAddress($address);

    $this->assertNotNull($user->address);
    $this->assertEquals('Randomstreet', $user->address->street);
}

bobbybouwmann left a reply on Cannot Download Excel Files... (maatwebsite) Even Though They Generate Fine. • 5 days ago

Not completely sure but seems you can either save or download the file: http://www.maatwebsite.nl/laravel-excel/docs/export#export

So indeed the best option is to store the file locally and then use a download response to download the file. For downloading this the file you can either use this

// Opens the file in the browser by simply returning the file.

return response()->file($path);

Or this

// Returns a download response using the correct headers.

return response()->download($path, $filename);

bobbybouwmann left a reply on Password Hashing Problem • 5 days ago

@paschal Thanks for your sharing your experience ;) It might be useful for someone :D

bobbybouwmann left a reply on How To Test A Feature Which Contains Relationships • 5 days ago

So you basically need to try to get your test passing with the minimum work required and later refactor. So you just need to start adding stuff to do the user to make your tests pass

12th January, 2017

bobbybouwmann left a reply on How To Test A Feature Which Contains Relationships • 6 days ago

It depends on how you want to test this. If you want to test the form you can check if the relation is created on that user object and check if the relation is created in the database

$id = $newUser->id;

$this->seeInDatabase('users', ['id' => $id]);
$this->seeInDatabase('addresses', ['user_id' => $id]);
$this->seeInDatabase('review_user', ['user_id' => $id]);

Now you can run your test and see that the database is not filled with data. You can assign all the info the user when submitting the form and so on.

11th January, 2017

bobbybouwmann left a reply on HELP: Forge, Quick Deploy & Composer.lock • 6 days ago

The recommended way is to push your local composer.lock file to your version control (git). So when you want to deploy your site, Forge will just pull your code from git including the composer.lock file. During your deployment you should run composer install so it will install the dependencies based on the composer.lock file.

Can you show your current deployment script?

bobbybouwmann left a reply on Update Slug For Big Number Of Rows • 6 days ago

Have you tried chuncking it by 200? That is the recommended size.

bobbybouwmann left a reply on Password Hashing Problem • 6 days ago

Instead of deleting the post it's wiser to post your solution here so others can benefit from it as well :)

bobbybouwmann left a reply on Memcached And Valet 2.0.3 • 6 days ago

Have you tried to reinstall valet? I think that's your only option right now.

See: https://laravel.com/docs/5.3/valet#other-valet-commands

bobbybouwmann left a reply on Storage Link Not Working • 6 days ago

Yeah indeed, you need to create the symlink in your homestead box.

bobbybouwmann left a reply on Storage Link Not Working • 1 week ago

The asset helper starts at the root of your project. However the files in the storage directory are not accessible publicly by default. You need to create your own file response for that like @saurabh said.

9th January, 2017

bobbybouwmann left a reply on Migration Error • 1 week ago

Did you delete the table migrations?

I've never seen this error before, but I think you can add the migrations table using this command: php artisan migrate:install

8th January, 2017

bobbybouwmann left a reply on Request Caption • 1 week ago

This feature requests has been asked before, however it takes a lot of time to create these videos, but to also add captions to each video is a lot of extra time!

If you don't understand the words, try to Google them. If you make a spelling mistake, Google will most of the time help you with the correct spelling.

bobbybouwmann left a reply on Proper App Structure For Importers • 1 week ago

Well in your case you can get away with probably 4 classes, since you already know what the fetching methods are and what needs to happen after that.

So foreach warehouse you have a method to fetch the data and then a method to normalize it. So each warehouse get's it's own class

6th January, 2017

bobbybouwmann left a reply on Proper App Structure For Importers • 1 week ago

The best thing you can do here is put stuff in classes. In this case it's possible to have a separate class for each warehouse since each warehouse has one data type.

5th January, 2017

bobbybouwmann left a reply on Check If Model Exists For Use In Custom Method • 1 week ago

Aah my bad! It's not a method but a property

if ($campaign->exists) {
    // saved 
} else {
    // not saved
}

See: https://laravel.com/api/5.3/Illuminate/Database/Eloquent/Model.html

However I do agree with @pmall

4th January, 2017

bobbybouwmann left a reply on How To SQL_CALC_FOUND_ROWS In A DB::select('') Statement? • 1 week ago

I think the best approach here is to use a raw query.

Documentation: https://laravel.com/docs/5.3/database#running-queries

bobbybouwmann left a reply on Check If Model Exists For Use In Custom Method • 1 week ago

There is an exists method on model

if ($campaign->exists()) {
    // saved 
} else {
    // not saved
}

3rd January, 2017

bobbybouwmann left a reply on Composer • 2 weeks ago

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

See: https://getcomposer.org/doc/00-intro.md

bobbybouwmann left a reply on How Can I Capture First Segment Of Url As Second Parameter Of Callable Type ? • 2 weeks ago

@mrabbani As of Laravel 5.3, this is done automatically based on the id. Only if you need something other then the ID you need to register it yourself ;)

2nd January, 2017

bobbybouwmann left a reply on How Can I Capture First Segment Of Url As Second Parameter Callable Type ? • 2 weeks ago

Just give them both a default value

public function category($slug = null, $id = null)
{
    // Do your thing
}

bobbybouwmann left a reply on Batch Start-up Commands • 2 weeks ago

I think the easiest way of doing is just a single command like php artisan migrate and so on. So just put them all on one file.

You can use bash to run a script on start up, but that only works on linux and mac and you might not need to do anything with the project when starting your pc.

1st January, 2017

bobbybouwmann left a reply on Uploading File From Laravel Application Using POST Method Causing Internal Server Error • 2 weeks ago

Well your route is different then your action... '/products/import/csv' and '/products'

bobbybouwmann left a reply on Proper App Structure For Importers • 2 weeks ago

So this is a hard problem, but the best thing you can do is abstract most of this. So instead of creating a class for each type you can instead writer a wrapper around each format that needs to be serialised.

So I images such a structure

public function __construct()
{
    $this->serializer = new App/Services/Serialiser();
}

public function importCsv(Request $request)
{
    $content = $this->getFileContentFromRequest($request); 

    $data = $this->serialized->csv($content);

    $this->handleData($data):
}

public function importJson(Request $request)
{
    $content = $this->getFileContentFromRequest($request); 

    $data = $this->serialized->json($content);

    $this->handleData($data):
}

protected function handleData(array $data = [])
{
    // Save the data to the database
}

So basically the serializer is the one that converts the content to some array or a collection that can be used for saving later on. This way so you keep the saving on one place, so you don't have to update it for each type of data

bobbybouwmann left a reply on How To Get Total Count Of Table By Using Two Value Of Column • 2 weeks ago

Aah ok, I think I misunderstood your question. I thought you had multiple columns for which you needed the summed count for.

bobbybouwmann left a reply on Ideal Amount Of Columns To Have In A Single Table? • 2 weeks ago

In general around 20 columns in a table is not that bad.

It's better to try to use relations. So let's say you have a users table which has a lot of columns. You can create an extra one-to-one relationship called profile for example to transfer some column to that table. Since you need the user subject on every request you keep the most important stuff there and stuff like phone number or address or birthday and so on.

30th December, 2016

bobbybouwmann left a reply on Different Controllers' Method In Another Controller • 2 weeks ago

It depends on what kind of application you have. Does your controller return a view or does it return json for an API?

If it returns a view, the best way to go is using a separate controller. This way you can simply return one view using multiple data.

public function dashboard()
{
    $tasks = Task::latest()->limit(5);
    $tutorials = Tutorial::latest()->limit(5);

    return view('dashboard', compact('tasks', 'tutorials'));
}

If you use an API you can simply return the data in each controller and do two requests on your frontend.

If you find yourself duplicating a lot of code to use it in multiple places you might want to take a look at query scopes or the repository pattern.

If you need more information, let me know ;)

bobbybouwmann left a reply on Calling View From Controller? • 2 weeks ago

What are you trying to achieve?

It looks to me that you are mixing VueJs with Blade right now.

29th December, 2016

bobbybouwmann left a reply on Windows Undefined Constant MCRYPT_RIJNDAEL_128 • 2 weeks ago

Well the problem is probably that you run commands on the command line outside of your box. If you run them in your box you will have the correct PHP version.

Another option would be installing mcrypt for php, not sure how on Windows though

28th December, 2016

bobbybouwmann left a reply on Attaching To All Models And Keeping In Sync • 3 weeks ago

I think all_categories is fine.

Edit Your Profile
Update

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