After rebuilding a CentOS 7 system with a Laravel app on it, every time the app attempted to mail a notification using MailTrap, the above error got fired.
SELinux. Again. It’s always flipping SE LINUX! The SELinux policy can block in and outbound ports and all sorts of things. It’s a git. A clever useful git.
Running `sudo sealert -a /var/log/audit/audit.log` showed the problem. If sealert isn’t possible, then tailing the audit log with `sudo tail -f /var/log/audit/audit.log` goes some way to finding the problem.
In this case a solution (being Linux there are probably 74 equally effective and largely contested solutions) was to allow Apache to use port 2525 like so:
sudo semanage port -a -t http_port_t -p tcp 2525
Problem: I’m retro-fitting ‘scopes’ to an existing Laravel Passport API to allow some different levels of client access. After adding the available scopes with Passport::tokensCan, and default scopes with Passport::setDefaultScope, and attempting to specify a scope on a route like so:
'write-access' => 'Read-write access',
'read-access' => 'Read-only access',
'other-access' => 'Other access'
Route::get('endpoint/count', 'API\EndpointController@count')->middleware(['auth:api', 'scope:read-access']);
And an attempt to query the route gives this error:
ReflectionException: Class scope does not exist in file /path/to/webroot/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 790
Solution: READ THE DOCS. Again, I didn’t read the docs FULLY. In order to use token scopes, the docs say…
To get started, add the following middleware to the $routeMiddleware property of your app/Http/Kernel.php file:
'scopes' => \Laravel\Passport\Http\Middleware\CheckScopes::class,
'scope' => \Laravel\Passport\Http\Middleware\CheckForAnyScope::class,
🤦🏻♂️ 🤦🏻♂️ 🤦🏻♂️ 🤦🏻♂️ 🤦🏻♂️ 🤦🏻♂️
Laravel 5.7 ships with bundled Email Verification. This is great if you want to make sure a user’s email address is valid (or at least that the user can access it) before allowing them access.
What if you want to manually verify a user without sending them an email address? For example you might want to add or import a load of existing ‘known-good’ users to a migrated app. Or you might be creating Admin or System users that don’t really have accessible email addresses. There could be many reasons.
At present as soon you register a user, the
sendEmailVerificationNotification method is called. There’s a good breakdown of how this works in this Stack Overflow answer. If a user is manually created, then when they try to log in they’ll still see the “Verify your email address” message:
Whether a user has verified their email address or not is indicated by a timestamp in the
email_verified_at column of the User table¹. If this column is set to a valid timestamp upon user creation, the user will be ‘validated’ and no email will be sent. So… how can we set that timestamp? Continue reading “Manually verifying created users when using Laravel Email Verification”
Problem: This morning I wanted to quickly move a little Laravel test project onto my live server. The default file structure of Laravel stores all the framework resources in a vertical tree of files and directories, and then the ‘public’ directory is adjacent to these. Like so:
- [public] etc
To host it on my CentOS box running cPanel I want to adhere to the following (standardish) structure:
- [public_html] etc etc varies depending on server
I could just upload everything in my Laravel project to the ‘public_html’ directory… but then to run the app I’d need to browse to http://example.com/public/. Worse still, my whole framework file-structure will be visible if I browse to http://example.com
Solution: With a little path remapping in two files, this can be easily achieved. Here’s what I did:
1) Create a new directory called ‘laravel4’ adjacent to ‘public_html’ so that your remote file structure now looks like this: Continue reading “Uploading / Configuring a Laravel 4 app on cPanel type hosting ( public_html )”