No Application Encryption Key Has Been Specified
From Encryption - Laravel - The PHP Framework For Web Artisans:
"Before using Laravel's encrypter, you must set a key option in your
config/app.php configuration file. You should use thephp artisan key:generate
command to generate this key"
I found that using this complex internet query in google.com:
"laravel add encrption key" (Yes, it worked even with the typo!)
Note that if the .env file contains the key but you are still getting an application key error, then run php artisan config:cache
to clear and reset the config.
php artisan key:generate gives a No application encryption key has been specified. error
php artisan key:generate
needs an existing key to work. Fill the APP_KEY with 32 characters and rerun the command to make it work.
Edit: A newly created app via laravel new with a deleted APP_KEY can run php artisan key:generate without issue for some reason.
Edit a year later:
The real problems lays in 2 added provider services. The boot() functions are badly written which causes the problem. Still not exactly sure why it doesn't work but I'll try and figure it out for somebody who may have the same problem later.
The two files in question
<?php
namespace App\Providers;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Routing\ResponseFactory;
class ResponseServiceProvider extends ServiceProvider
{
public function boot(ResponseFactory $factory){
parent::boot();
$factory->macro('api', function ($data=null, $code=null, $message=null) use ($factory) {
$customFormat = [
'status' => 'ok',
'code' => $code ? $code : 200,
'message' => $message ? $message : null,
'data' => $data
];
if ($data instanceof LengthAwarePaginator){
$paginationData = $data->toArray();
$pagination = isset($paginationData['current_page']) ? [
"total" => $paginationData['total'],
"per_page" => (int) $paginationData['per_page'],
"current_page" => $paginationData['current_page'],
"last_page" => $paginationData['last_page'],
"next_page_url" => $paginationData['next_page_url'],
"prev_page_url" => $paginationData['prev_page_url'],
"from" => $paginationData['from'],
"to" => $paginationData['to']
] : null;
if ($pagination){
$customFormat['pagination'] = $pagination;
$customFormat['data'] = $paginationData['data'];
}
}
return $factory->make($customFormat);
});
}
public function register(){
//
}
}
<?php
namespace App\Providers;
use App\Http\Controllers\Auth\SocialTokenGrant;
use Laravel\Passport\Bridge\RefreshTokenRepository;
use Laravel\Passport\Bridge\UserRepository;
use Laravel\Passport\Passport;
use Laravel\Passport\PassportServiceProvider;
use League\OAuth2\Server\AuthorizationServer;
/**
* Class CustomQueueServiceProvider
*
* @package App\Providers
*/
class SocialGrantProvider extends PassportServiceProvider{
/**
// * Bootstrap any application services.
// *
// * @return void
// */
public function boot(){
parent::boot();
app(AuthorizationServer::class)->enableGrantType($this->makeSocialRequestGrant(), Passport::tokensExpireIn());
}
/**
* Register the service provider.
*
* @return void
*/
public function register(){
}
/**
* Create and configure a SocialTokenGrant based on Password grant instance.
*
* @return SocialTokenGrant
*/
protected function makeSocialRequestGrant(){
$grant = new SocialTokenGrant(
$this->app->make(UserRepository::class),
$this->app->make(RefreshTokenRepository::class)
);
$grant->setRefreshTokenTTL(Passport::refreshTokensExpireIn());
return $grant;
}
}
Related Topics
What Does This Symbol Mean in PHP <=
How to Add All of My Array Values Together in PHP
Difference Between Array_Map, Array_Walk and Array_Filter
Deleting All Files from a Folder Using PHP
Call Laravel Controller via Command Line
How to Get the Client's Ip Address in a PHP Webservice
Cloudflare and Logging Visitor Ip Addresses via in PHP
Custom Pagination View in Laravel 5
.Htaccess Issues: No Input File Specified
Get Week Number (In the Year) from a Date PHP
PHP Check Whether Property Exists in Object or Class
Php7.1 JSON_Encode() Float Issue
How to Include PHP Files That Require an Absolute Path
Detect Main Colors in an Image with PHP