I host a SPA with a Laravel API on AWS (EC2). When you fill out this form: http://ec2-52-59-214-55.eu-central-1.compute.amazonaws.com/register (feel free to do so), the server throws an error with a response code of 500, right at the point where a $user->can("...")
method is called. I developed the app localy and everything worked fine there.
Local environment:
Windows 10 / XAMPP - Apache 2.4.41
PHP 7.4.4
Laravel 7.5.2
Server environment:
Ubuntu 18.04 / Apache 2.4.29
PHP 7.4.6
Laravel 7.5.2
It uses spatie/laravel-permission for role management, which also affects the can
method provided by the Laravel framework.
Here is the code causing the error:
echo "Before store<br>";
if($user->can("store files")) { echo "Inner store";
// Store avatar
if(isset($data["avatar"])) {
if(!$data["avatar"]->isValid()) {
return reponse(null, 422);
}
// Check if avatar is new
$current_avatar = $user->getAvatarAttribute();
$store_images = get_new_files([$data["avatar"]], [$current_avatar]);
if(isset($store_images[0])) {
// Create asset for avatar
$new_avatar = create_asset([
"file" => $store_images[0],
"user_id" => $user->id,
"type" => "avatar"
]);
$new_avatar->save();
}
}
}
echo "After store<br>";
And here the error which I guess means, that the script failed as soon as if($user->can("...))
got called.
Do you have any idea how to fix that?