0👍
TL;DR: Mixed content behind a load balancer / CDN and missing role_id in query
If you setup Laravel in a load balanced environment the https session terminates before it hits the web server so Laravel was serving for a http request, thus generating mixed content issues.
Hence the actual script does not get imported and the app itself does not throw any errors.
So you need to make sure that imported scripts and endpoints are served over a secure connection (https).
(You will see the mixed content error by checking the app in your browser’s console.)
Solving routing to insecure endpoints
Edit your routing in:
app/Providers/AppServiceProvider.php
from
public function boot()
{
...
}
to
public function boot()
{
// if (!\App::environment('local')) {
\URL::forceScheme('https');
// }
}
The commented part is reflecting Mladen Janjetovic’s approach if you like to differentiate between a local environment and production environment on a server.
However consider it a good practice to test locally as close as possible mimicking your production environment.
Optional: Solving mixed content for script imports (CSS & JS)
You want to make sure that scripts will be called from a secure source (https).
Edit your asset calling in:
resources/views/layouts/app.blade.php
from
asset( ... )
to
secure_asset( ... )
Solving missing default value when creating User
As soon as you have solved mixed contents, you might see, that the User::create query fails. If that happens you probably want to do the following changes.
Edit your User model in:
app/User.php
from
protected $fillable = [
'name', 'email', 'password',
];
to
protected $fillable = [
'name', 'email', 'password', 'role_id'
];
Edit your query in:
app/Http/Controllers/Auth/RegisterController.php
from
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
to
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'role_id' => $data['role_id'] ?? 'user'
]);
}