bobbybouwmann

Developer at Enrise

Experience

832,095

1002 Best Reply Awards

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

21st February, 2017

bobbybouwmann left a reply on REST API With Login Included • 2 hours ago

What you can do is something like this in your controller, since you only have access to the current user in the request!

public function SomeController 
{
    /**
     * User $user
     */
    protected $user;

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

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

    public function getTeams()
    {
        $this->user; // Returns the logged in user
    }   
}

Note: If you are not logged in $this->user will return null!

bobbybouwmann left a reply on How I Can Send Email With 'from()' In Laravel 5.3 • 2 hours ago

I believe your ->from() should look like this

$this->from('email@email.com', 'Some name');

bobbybouwmann left a reply on REST API With Login Included • 2 hours ago

You can only get the user from the request object in your middleware

public function handle(Request $request)
{
    $user = $request->user();
}

bobbybouwmann left a reply on How Can I Define A Custom Guard To Socialite Facebook Auth? • 8 hours ago

What do you mean with custom guard?

bobbybouwmann left a reply on Php Artisan Serve • 9 hours ago

Did you create a .env file in your root directory?

bobbybouwmann left a reply on Laravel 5.4 Error Or Forge • 10 hours ago

Mmh could be a lot of things. Not sure, but I think you have an outdated package somewhere?

bobbybouwmann left a reply on How Do You Get An Auto Updating Notification To A Table With A Count? • 10 hours ago

What have you tried so far?

The concept of notifications is the same as a blog right? You have some data in the database, you only display the latest 5 ordered by date (like a home page) and you have a load more button (show all notifications)

20th February, 2017

bobbybouwmann left a reply on Migrations - Nullable() Is Not Setting • 20 hours ago

Nullable is a method, not a property ;)

$table->string('comments', 60)->nullable();

bobbybouwmann left a reply on How To Install Mlti Tenant In Laravel 5.4 • 1 day ago

Did you read the readme of the package?

I bet you didn't....

NOTE: THIS PACKAGE HAS MOVED

This package is now Laravel 5.2+ only, and has moved to https://github.com/HipsterJazzbo/Landlord. This version will no longer be maintained, but will stay here for legacy compatibility.

bobbybouwmann left a reply on Latest In Related Models Without Grouping • 1 day ago

The only thing I can think of is doing a foreach loop or a join on the tables. You can't do this with one relation rule.

bobbybouwmann left a reply on How To Install Mlti Tenant In Laravel 5.4 • 1 day ago

This package is only compatible with Laravel 4 and 5.1 (as the error shows)

You have two options here:

  1. Fork the repo and update the package to be compatible with 5.4 and include that in your project
  2. Create an issue on the repo with a request to update it to 5.4.

However the package hasn't been update to 5.2 or 5.3 so I think you should find another solution for your problem!

19th February, 2017

bobbybouwmann left a reply on Laravel Hasmanythrough But With Manytomany • 1 day ago

If you want to pass the item to the closure you need to tell that to the closure like so:

$allArticles = collect();

foreach ($cats as $item){
    $articles = Article::with(['categories' => function ($query) use ($item) {
        $query->categoryID = $item->id;
    }]);

    $allArticles->merge($articles);
}

dd($articles);

bobbybouwmann left a reply on Does Laravel Require Mcrypt? • 2 days ago

@RichGraham Googleing the error works most of the time ;)

bobbybouwmann left a reply on Show/Hide Not Working.. • 2 days ago

It looks like everything is dynamically loaded, but the DOM isn't. To get around this you need to update your calls to this

$("#vendor-"+i).on('click', function(){
    $("#vendor-"+i+"-content").show();
});

$("#vendor-"+i+"-close").on('click', function(){
    $("#vendor-"+i+"-content").hide();
}); 

bobbybouwmann left a reply on Laravel Relationship, Database Table Design • 2 days ago

You're basically asking to design your complete application here...

What have you tried so far? It's easier for us if you show what you already have in mind so we can give you tips on how to improve.

Laravel uses a really nice way for describing relationships. So for example a Blog HasMany Comments and a Comment BelongsTo a Blog. Now you know you need a One-To-Many relation.

See the docs for more relationship types: https://laravel.com/docs/master/eloquent-relationships

bobbybouwmann left a reply on Handling Passwords With Vue And Axios • 2 days ago

I have seen applications where everything was encrypted in the frontend-app and decrypted in the backend-app but I don't recommend to do that at all! Just make sure you only send the username and password only once to the backend and then work with a session or token to communicate ;)

And of course use HTTPS so all data that is send over the line is encrypted ;)

bobbybouwmann left a reply on Access The 3rd Table In Many To Many • 2 days ago

You need to use a closure for that

$articles = Article::with(['category' => function ($query) {
    $query->category_id = 1
}])->paginate(10);

See: https://laravel.com/docs/5.4/eloquent-relationships#querying-relations

bobbybouwmann left a reply on Handling Passwords With Vue And Axios • 2 days ago

This error has nothing to do with the register action.

It looks like the email you are trying to send isn't working. I can see that you use the SMTP transport layer and that is the one that gives you this exception. Please check your email settings for sending an email!

bobbybouwmann left a reply on Laravel 5.4 Error Or Forge • 2 days ago

You need to check the scripts part of your composer.json file. It holds as array with scripts/commands that needs to be run. You might have an error in one of your scripts!

bobbybouwmann left a reply on MySQL JSON Column Querying Using Eloquent Or Query Builder • 2 days ago

Yeah Laravel has support for a json column in the database. So when the column has the type json you can get json values from it.

You can find more details here:

Note: This only works if you have MySQl 5.7 or higher

bobbybouwmann left a reply on Why After Signup I Receive 404 Error. • 2 days ago

What is the error you get? Can you see something in the logs?

bobbybouwmann left a reply on Not Even Sure What To Name What I Want To Do... • 2 days ago

If you want an accessor you need to follow a certain convention. That convention is getXAttriubte(). So in your case your method needs to be called getSubscriptionPaidAttribute().

You can now access this property like so

$club->getSubscriptionPaidAttribute(); // returns boolean

17th February, 2017

bobbybouwmann left a reply on Is This A Bug With Mail? • 4 days ago

Take a look at your code:

// You have this
Mail::to('$recipient')->send($email);

// While you expect this
Mail::to($recipient)->send($email);

Not sure if this is the issue though

bobbybouwmann left a reply on Laravel 5.3 Auth - Possibility To Register And Log In But Also To Continue As Gu... • 4 days ago

I would probably use a session for this. When the users click on a certain link for logging in as a guest you set a session for them. So you can check if they are logged in as a quest. When they register you can simply remove the session. If they have the session set they simply can't save anything.

You can probably create a middleware for that or use modal events to make sure nothing is saved

16th February, 2017

bobbybouwmann left a reply on How To Better Way To Manage Modal Window • 5 days ago

It completely depends on how much data needs to be changed in your modal. I have for example a helper method that adds a delete modal for a record. So I have a HTML helper method which I give a route and a button for the text and that will generate the Modal + form etc. So instead of loading it with ajax I already have it on the page.

So on other pages where I need a lot of modals I simply do it with some javascript. So when you click button x it reads the data- attributes from the element and based on that the modal + form is generated. However these modals are pretty simple and almost always hold the same content.

If you have more complex modals it's wise to generate the html on your server and append it later on.

14th February, 2017

bobbybouwmann left a reply on Php Artisan Migrate Not Working In Laravel 5.4 • 1 week ago

I think you didn't completely follow the upgrade guide. However there is a fix for your problem!

See: https://laravel-news.com/laravel-5-4-key-too-long-error

bobbybouwmann left a reply on Many To Many Relationships • 1 week ago

You can probably do something like this

$userId = 1;

$groups = Group::whereHas('users', function ($query) use ($userId) {
    $query->where('user_id', $userId);
})->get();

bobbybouwmann left a reply on Fatal Error: Class 'Illuminate\Foundation\Application' Not Found In /bootstrap/app.php On Line 14 From Php Artisan Serve • 1 week ago

BTW: The project is working fine for me! I did the following steps

  • git clone git@github.com:imranshuvo/quiz.git
  • cd quiz
  • composer install
  • php artisan serve

The project works fine, however it has some bugs in it anyway.... You are better off building it yourself

bobbybouwmann left a reply on Fatal Error: Class 'Illuminate\Foundation\Application' Not Found In /bootstrap/app.php On Line 14 From Php Artisan Serve • 1 week ago

It looks like you are downloading an old version of Laravel (v5.0.9). Also I'm not sure if this project is PHP 7 compatible.

Anyway you can install mcrypt for php7 on mac like so

brew install php70-mcrypt

13th February, 2017

bobbybouwmann left a reply on Passport::actingAs Undefined • 1 week ago

It's actually added 10 days ago. See (https://github.com/laravel/passport/commit/7f950fe4c77571fc46a6c15885b6a27c71975ed9)[here] the original commit ;)

bobbybouwmann left a reply on Passport::actingAs Undefined • 1 week ago

I think you need to update the passport package to a newer version. The actingAs() method is added in a later stage.

bobbybouwmann left a reply on Order And Order Lines. Polymorphic? • 1 week ago

Yeah a polymorphic relation should be fine here ;)

In this case the OrderLine would be the polymorphic model. So your table looks like this for example

- orders 
        - id
        - created_at
        - updated_at

- order_lines
    - id
    - order_lineable_id
    - order_lineable_type
    - created_at
    - updated_at

You might even have every model that can be in the order_lines table extend the same class or interface, because you will propably have some common methods like calculatePrice($amount) and so on

bobbybouwmann left a reply on Sending And Receiving Email With Gmail API • 1 week ago

Hi,

This package should do: https://packagist.org/packages/pulkitjalan/google-apiclient

However the google api client is pretty big and complicated. If you only want to send emails I can recommend you to keep using the SMTP settings instead.

bobbybouwmann left a reply on Updating Laravel 5.3 To 5.4, Help • 1 week ago

@imohammad Look at the error message... It's saying that you do.

However it's possible that one of your packages is not compatible with the Laravel version, maybe you need to update those first!

3rd February, 2017

bobbybouwmann left a reply on Where To Find Definitive Return Values Or Documentation Of Laravel Methods? • 2 weeks ago

Yeah there is an API documentation. You can find it here: https://laravel.com/api/5.4/

2nd February, 2017

bobbybouwmann left a reply on Lumen Has Any Future? • 2 weeks ago

A year ago that would be my advice! However Laravel itself is growing so fast now and Lumen is not updated (some open issues as well).

I want to advice you to start your next project in Laravel. You can still create two separate projects for the back and frontend. Also Laravel is still really fast, so you won't have a big difference in performance.

bobbybouwmann left a reply on Will BrowserKit Testing Be Supported In Laravel 5.5? • 2 weeks ago

It depends on how much the package is used. If the same number of users use this package as the dusk package, it should be supported in future versions.

For now nothing is sure yet.. It would be a good idea to upgrade your tests at some point to work with the new syntax.

bobbybouwmann left a reply on Updating Laravel 5.3 To 5.4, Help • 2 weeks ago

@imohammad What do you mean?

29th January, 2017

bobbybouwmann left a reply on Roles Permissions - AuthServiceProvider - Auth User Null • 3 weeks ago

I think your getPermissions method should be responsible for only getting the permissions of the given user.

I currently have a middleware in place which is checking if the user is allowed to enter a certain route. So the permission name is the same as the route name.

<?php

namespace App\Http\Middleware;

use Closure;

class IsAuthorized
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (hasPermission($request->route()->getName())) {
            return $next($request);
        }

        // TODO: Replace with API response
        abort(403, 'Unauthorized action.');
    }
}

The hasPermission looks like this, which is stored in a helpers.php file so I can call the method everywhere. The method is really fast because it uses caching for the permissions.

// helpers.php

function hasPermission($route)
{
    $key = 'permissions' . auth()->user()->id;

    $permissions = Cache::remember($key, config('feestgemak.cache_minutes'), function () {
        $collection = collect();

        auth()->user()->load('roles.permissions');

        foreach (auth()->user()->roles as $role) {
            foreach ($role->permissions as $permission) {
                $collection->push($permission->name);
            }
        }

        return $collection;
    });

    return $permissions->contains($route);
}

However this setup is a bit different from yours. I have roles and permissions separate. A user has one or many roles and each role has one or many permissions.

bobbybouwmann left a reply on Set Up Laravel 5.4 With Dusk Using Phpunit.xml, .env.dusk.local, And An Sqlite In-memory Database • 3 weeks ago

Mmmh the sqlite database isn't working me either. It looks like it's not migrating properly. I tried to migrate the database first before starting the tests and that worked fine. However the DatabaseMigrations trait should do that for us anyway..

Not sure what's going on

28th January, 2017

bobbybouwmann left a reply on Set Up Laravel 5.4 With Dusk Using Phpunit.xml, .env.dusk.local, And An Sqlite In-memory Database • 3 weeks ago

I have a demo project with Laravel Dusk here: https://github.com/bobbybouwmann/dusk-demo

I think you only need to copy the .env.example file and simply replace the database credentials with the sqlite credentials and it should work out of the box.

The approach that I used is to migrate the database for each test.

If you have more questions, just let me know :)

26th January, 2017

bobbybouwmann left a reply on Updating Laravel 5.3 To 5.4, Help • 3 weeks ago

@imohammad Did you read the upgrade guide? I bet you didn't...

The share method has been removed from the container. This was a legacy method that has not been documented in several years. If you are using this method, you should begin using the singleton method instead:

$container->singleton('foo', function () {
    return 'foo';
});

bobbybouwmann left a reply on Getting The Not-null Constraint On An Existing Migration • 3 weeks ago

As far as I know not. Their might be some methods that can fetch database information or table information, but I haven't used or needed them before.

bobbybouwmann left a reply on Using Redis For Queue And Cache • 3 weeks ago

It should work fine if you use it for both. You only have to adjust your config for caching and queuing and make sure that Redis is running on your server of course ;)

bobbybouwmann left a reply on No Gulpfile.js In Laravel 5.4 • 3 weeks ago

Laravel is using Laravel Mix now! So basically you have a webpack file now. Take a look at the documentation and some videos:

Documentation: https://laravel.com/docs/5.4/mix

Video: https://laracasts.com/series/whats-new-in-laravel-5-4/episodes/3

bobbybouwmann left a reply on Some Ideas For Route Wildcard? • 3 weeks ago

In my opinion this is a big mess! Throw it all out and start defining your routes. Can you tell what your routes are doing right now? Can some other develop do that for you? I bet it's really hard to tell what's going on here!

So of course you will have problems with your backend routes. The following routes will all listen to your slug route

http://example.com/admin/something
http://example.com/admin
http://example.com/admin/posts
http://example.com/posts
http://example.com/login

To fix this you can simply put your frontend route at the last route in your routes file. This was it will first try to match any route and after that it will use your "catch" all route.

But like I said above! Don't ever ever ever do this. Your routes should be the documentation of your application and tell you what url is connected to what action!

Edit Your Profile
Update

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