pdc

pdc

Member Since 1 Year Ago

Experience Points 240
Experience
Level
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Answer
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.

19 Oct
1 month ago

pdc left a reply on Eloquent Query Picking Wrong Database For The User Model

Excuse me. I've put the table variable into my model and now my query indeed looks like it should. Thanks for the suggestion, it appears to be working now.

Why isn't it enough to define the $connection? It actually includes the database name...

18 Oct
1 month ago

pdc left a reply on Eloquent Query Picking Wrong Database For The User Model

That does not explain why Laravel is looking for the users table in the wrong database... It's the essence of the issue

pdc started a new conversation Eloquent Query Picking Wrong Database For The User Model

I'm currently setting up my own role-based access-control-system on my website.

You can add Entities (eg. an Artist). | permissions | You can add Roles (eg. Administrator, Blogger, Developer). | role_user | The users are located within another database (the Internal database) in order to reuse the authentication

I'm able to assign a role to a user (eazy peazy), to assign a permission for an entity to a role (eazy peazy).

But when I'm trying to check the permission for a user, odd things happen.

config/database.php mysql -> MusicDemons mysql_auth -> Internal (contains the users-table)

User-model protected $connection = 'mysql_auth';

Code to check if the current user has permission to do something with the Entity

$result = 
    Entity::where('model_name','=',$model_name)
        ->whereHas('permissions', function($query) use ($action) {
            $query->where($action,'=',true);
            $query->whereHas('allowed_users',function($query){
                return $query->where('id','=',Auth::user()->id);
            });
        });

dd($result->toSql());

This code is being called through a webroute, for testing purposes

Route::get('test',function() {
    $perm = App\Helpers\RbacPermission::has_permission('App\Entities\MusicDemons\Artist','create');
    dd($perm);
});

You can see the result of this query in action at https://musicdemons.com/test

The raw SQL query is: select * from entities where model_name = "App\Entities\MusicDemons\Artist" and exists (select * from roles inner join MusicDemons.permissions on roles.id = MusicDemons.permissions.role_id where entities.id = MusicDemons.permissions.entity_id and create = '1' and exists (select * from users inner join MusicDemons.role_user on users.id = MusicDemons.role_user.user_id where roles.id = MusicDemons.role_user.role_id and id = '1') and roles.deleted_at is null) and entities.deleted_at is null

For some reason the eloquent query is picking the wrong database for the User-model (read: users.id doesn't have the database prefix and should actually be Internal.users.id). The odd thing is that the User-model has the $connection explicitly defined, and anyway picks the wrong database to select the data from!

How do I solve this problem? In my opinion this is a bug in Laravel... but is there a way around this bug?

The entire project is hosted at https://github.com/PieterjanDeClippel/LaravelProjects .

The Internal project is just to manage the database containing the users and password_resets. The MusicDemons project contains the main project.

10 Aug
4 months ago

pdc started a new conversation How Do I Send An E-mail Through SMTP

I'm trying to send mails through the mailhub of my Internet Service Provider (Telenet). Previously, I've done the same using the simple-smtp linux package.

The configuration was as follows:

[email protected] mailhub=smtp.telenet.be:587 rewriteDomain=example.com hostname=example.com UseTLS=YES UseSTARTTLS=Yes [email protected] AuthPass=your_password AuthMethod=LOGIN FromLineOverride=YES

To make this successful, I also had to set up following reverse aliases in sSMTP. For each Linux user who wants to send emails - let's say www-data since that's the user that runs the webserver.

root:[email protected]:smtp.telenet.be:587 pi:[email protected]:smtp.telenet.be:587 no-reply:[email protected]:smtp.telenet.be:587 www-data:[email protected]:smtp.telenet.be:587

I've already set up my environment file with the credentials to connect to the Telenet mailhub. This works as expected. However, PHP complains about missing reverse aliases.

Expected response code 250 but got code "550", with message "550 5.1.0 [email protected] is not an alias of [email protected]"

Where can I set up these reverse aliases to allow the www-data user to send emails on behalf of [email protected]

16 Jan
10 months ago

pdc started a new conversation Laravel Localization For Long Strings

I have a Laravel website with views containing long, static strings. From the documentation (https://laravel.com/docs/5.2/localization) I understand you can use App::setLocale($locale) and App::getLocale() to change the locale. However, since my views contain long strings (mainly parameterless), I don't see how it would be handy to paste all these texts into /resources/lang/{locale}/messages.php-file. I assume this would get very confusing very fast. How do you deal with this?

Site I want to localize: https://arromanchesbnb.pieterjan.pro/

25 Nov
1 year ago

pdc left a reply on Sync Pivot-table With Additional Columns

Well never mind. I've arrived on this page: https://laracasts.com/discuss/channels/laravel/sync-with-array-data-and-pivot And I was able to implement it successfully.

pdc started a new conversation Sync Pivot-table With Additional Columns

I'm trying to update additional columns on a pivot-table. I have a model "Person" and "Artist". There's a many-to-many relationship between them. The pivot-table contains a column named "active". This is the one i'm trying to set, and determines whether or not a person is still in the band.

class Artist extends Model { public function members() { return $this->belongsToMany('App\Entities\Person')->withPivot('active'); } } class Person extends Model { public function artist() { return $this->belongsToMany('App\Entities\Artist')->withPivot('active'); } }

Storing the members and quit_members works like a charm

$artist->members()->attach($artistData->members, array('active' => TRUE)); $artist->members()->attach($artistData->past_members, array('active' => FALSE));

To update the members I'd expected below code to work:

// One would expect this to work (sync m2m, for members set active=TRUE, for past_members set active=FALSE) // first detach existing pivots which are not in the members-list, and attach (if necessary) the remaining members. set all "actives" to TRUE $artist->members()->sync($artistData->members, array('active' => TRUE)); // keep the above set pivots, and attach (if necessary) the past_members, setting all "actives" to FALSE $artist->members()->syncWithoutDetaching($artistData->past_members, array('active' => FALSE));

But somehow this code still detaches the existing entities. How can I deal with this. I don't want to add another pivot-table for this so that's why i use the active-column.

GitHub reference (line 45) https://github.com/PieterjanDeClippel/LyricDB/blob/master/app/Services/ArtistService.php