I started with a fresh installation of Laravel and then did the following...
I filled in the config/workbench.php file with my info: -
return array('name' => 'My Name', 'email' => 'fullysick#email.com');
I ran the artisan command: -
php artisan workbench dicksmith/curl --resources
Everything reported success. It installed dependencies etc.
I populated the app.php file with the necessary service provider and alias information. My code can be seen here -> http://paste.laravel.com/wFj
I'm struggling to think why it may not be loading through the Facade accessor.
Any ideas?
Problem solved.
I just needed to have the Facades directory located inside the package.
A stupid, stupid, stupid, stupid mistake on my behalf. 2 days lost... I feel sheepish.
Related
I have discovered some wired behavior, I have that one CI4 project i am working on since a couple of weeks. everything is working just fine, but until now i have just been working with the project on my local machine. When i wanted to run the project on my Laptop in ran into an error when i tried to run the migrations with php spark migrate -all
CodeIgniter CLI Tool - Version 4.0.4 - Server-Time: 2020-07-20 06:16:02am
Running all new migrations...
An uncaught Exception was encountered
Type: CodeIgniter\Database\Exceptions\DatabaseException
Message: Unable to connect to the database.
Filename: /opt/lampp/htdocs/sms/vendor/codeigniter4/framework/system/Database/BaseConnection.php
Line Number: 425
The project includes Myth/auth, so i tried just to run "my" migration with php spark migrate . That just worked fine, no problem at all, the tables are there, no errors. Just for fun, i moved my Math/auth migrations from the vendor folder to the "normal" Database/Migrations folder and was able to migrate them that way.
That's very wired, especially since everything is working just fine on the PC I have been using before. There I am able to run the migrations using php spark migrate -all without any errors, when is set up a fresh MySQL/MariahDB database. But somehow only there.
I was able to reproduce the error on my laptop on my Manjaro partition, my Windows 10 partition and on my iMac.
So if you want to reproduce the error do the following:
composer create-project codeigniter4/appstarter whatever
rename the env to .env
set CI_ENVIRONMENT = development and obviously uncomment that line
configure and uncomment your database setting in the .env
create a sample migration like the one from the docs using > php spark migrate:create AddBlog
add the following content to the new migration and save the file:
forge->addField([
'blog_id' => [
'type' => 'INT',
'constraint' => 5,
'unsigned' => true,
'auto_increment' => true,
],
'blog_title' => [
'type' => 'VARCHAR',
'constraint' => '100',
],
'blog_description' => [
'type' => 'TEXT',
'null' => true,
],
]);
$this->forge->addKey('blog_id', true);
$this->forge->createTable('blog');
}
public function down()
{
$this->forge->dropTable('blog');
}
}
run > composer require myth/auth
Edit app/Config/Email.php and verify that a fromName and fromEmail are set as that is used when sending emails for password reset, etc.
Edit app/Config/Validation.php and add the following value to the ruleSets array: \Myth\Auth\Authentication\Passwords\ValidationRules::class
Ensure your database is setup correctly, then run the Auth migrations: php spark migrate -all
As a result you will also have the above error. I was not able to
get around that error, except for the system in was working with at
first.
If you just use php spark migrate it will migrate the sample migration without any errors
I am running CI 4.04 on Kubuntu 18.04 LTS, running apache2.4.29 and PHP 7.4.9
The short answer is...
Using php spark migrate -all searches everywhere it knows about for Database/Migrations Folders and files.
There just so happens to be a such folder/file under
tests/_support/Database/Migrations/2020-02-22-222222_example_migration.php
The bits added to make the short answer longer
So the Database error we are seeing is due to not having set up Database credentials for $tests in /app/Config/Database.php
All it's doing is looking to connect to the DB set up under $tests, but appears not to actually run as we don't want it to.
That appears to be enabled when ENVIRONMENT is set to "testing".
So 3 options for the time being...
Ignore the error. But that always leaves you wondering what's really happening.
Setup the credentials for the $tests Database. (Not really warranted.) OR
Delete/Rename the tests folder if you are not using it. (Stop it finding it.)
Would be to use the -n switch/option and specify the namespace to use (but not sure that's working.)
Changing DB hostname to '127.0.0.1' from localhost in your .env file usually solves the problem of running any migrations from the command line.
Open your PHP.ini file, find this :
;extension=sqlite3
and remove the semicolon to activate sqlite3. You need this library in Codeigniter 4 in order to use FORGE.
This is a fresh copy of Laravel 5.6.
using spatie laravel permissions.
I have maybe altered something while dealing with permissions that could have altered the guard. I have no idea what since I can't see any git changes, maybe via the DB?
At first I tried to tinker and give a specific user admin privileges with:
$role = Spatie\Permission\Models\Role::where('name', 'admin')->get()->first();
When that returned undefined, I checked Auth::guard('admin'), that returns undefined, so I understand that the issue has nothing to do with Spatie package.
After looking in a few questions/answers here on stackoverflow, one of them being config:clear and config:cache, which didn't work and still getting undefined for Auth guard admin.
Any other options I could take to get Auth admin?
thanks
In case you edited your config/auth.php, e.g. to add another guard and your config is cached, your guards may not be reloaded. If you experience this problem, clearing the config will fix it.
https://github.com/laravel/laravel/blob/v5.2.0/config/auth.php
php artisan config:clear OR php artisan config:cache
I'm using Laravel 5.4.
Add admin or administrator to the auth guards. After this php artisan config:clear can be run to remove the previous cached configurations. It should match your roles->name in the database.
\config\auth.php (file)
'guards' => [
...
'administrator' => [
'driver' => 'session',
'provider' => 'users',
],
],
An old question, but stil valid from Laravel 5 to 7
i am trying to install php-tmdb/laravel on my laravel 5.5 but getting error on basic test
Invalid API key: You must be granted a valid key
i try with google and found this link https://github.com/php-tmdb/laravel/issues/38
but its not working or can't understand
help me
auto discovery in this package is not working correctly
just add this on providers
config/app.php
Tmdb\Laravel\TmdbServiceProvider::class,
everything is working fine now
According to the github README.md https://github.com/php-tmdb/laravel
After you install the package, run this command to publish the configuration file:
php artisan vendor:publish --provider="Tmdb\Laravel\TmdbServiceProviderLaravel5"
then edit this file: config/tmdb.php in your application with your api key.
The configuration file should look like this:
https://github.com/php-tmdb/laravel/blob/master/src/config/tmdb.php
Notice 'api_key' => '', fill this in and then re-run your code/test.
Here's where you get your API key from: https://developers.themoviedb.org/3/getting-started
After changing the config, for good measure; clear your config cache with this command:
php artisan config:clear
edit /vendor/php-tmdb/laravel/src/config/tmdb.php
find 'api_key' => '', and add your key here.
In mail.php I have changed from fields but I still get mails with demo values. There is no reference to hello#example.com in project, yet I still get this in mail.
'from' => [
'address' => 'do-not-reply#mysite.net',
'name' => 'MySite.net',
],
Does anyone have an idea what might be wrong?
Clear the config cache by running the following Artisan command:
php artisan config:clear
If you are using supervisor, ensure you set the right user in the conf file, otherwise you will see the emails are being sent as hello#example.com.
In my case the user is www-data - I set it up as root before and was getting this issue.
I'm going crazy about this error.
I've got a vagrant VM with Debian 7, generated with Puphpet, installation was fine.
1. Redis is installed and working
redis-server is running :
I can use the server on 127.0.0.1:6379 :
2. php5-redis is installed
php5-redis is actually installed :
3. Laravel Redis config is set
Here is my redis config file in app/local/database.php :
'redis' => [
'cluster' => false,
'default' => [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
],
],
4. The call to Redis is simple :
// Get redis
$redis = Redis::connection();
5. I tried a lot of things
sudo service nginx reload
sudo service redis-server force-reload
composer dumpautoload
But nothing solved the error.
I'm still having :
ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined method Redis::connection()' in /var/www/fd/app/menus/admin.menu.php:16
(line 16 is where I do the connection $redis = Redis::connection();)
Where am I wrong ?
Btw, I hate mondays >.>
I came across this after encountering this issue and wanted to add another answer in case it helps someone else.
In my case there was an alias collision because my php configuration has the PHP-Redis module/extension enabled -- both the PHP module and Laravel seem to have a conflicting object named Redis. I was able to resolve this simply by using the entire namespaced identifier:
//$r = Redis::connection()
$r = Illuminate\Support\Facades\Redis::connection();
The problem isn't with your redis server setup -- there's something mis-configured or changed in your system.
The error you're seeing
Call to undefined method Redis::connection()
Is PHP telling you it can't find a method named connection on the class Redis. It's a PHP error, and PHP never gets around to trying to talk to the redis server.
Normally, in a Laravel 4.2 system, there is no class named Redis. Instead, an alias is setup in app/config/app.php
#File: app/config/app.php
'Redis' => 'Illuminate\Support\Facades\Redis',
which turns Redis into a facade. This is what enables you to make calls like Redis::connection.
So, there's something wrong with your system. Either you
Have a custom class named Redis somewhere that's loaded before the aliases are setup
Have Redis aliased to something other than a the Illuminate\Support\Facades\Redis facade class
You Redis facade class has been modified to return a service identifier other than redis
You've rebound the redis service as some other class
Per the comments below, you have the Redis PHP extension installed and the global extension class "wins"
To find out where PHP thinks the Redis class is, try
$r = new ReflectionClass('Redis');
var_dump($r->getClassFile());
To see if #4 is the problem, try calling the service directly
$app = app();
$app['redis']->connection();
Good luck!
That error is because you have installed and enabled the module php5-redis, it became with the class Redis. To avoid that error and use the Laravel Redis Facade, you have to change the alias in app/config/app.php (or whatever is your environment).
'Redis' => 'Illuminate\Support\Facades\Redis'
'RedisFacade' => 'Illuminate\Support\Facades\Redis' //whatever you like
or just configure your cache.php to use Redis and use only the Cache class. :)
Install Redis extension on your PC.
Download the CORRECT version the DDL from the following link:
https://pecl.php.net/package/redis/4.1.0/windows
Put the dll in the correct folder
Wamp -> C:\wamp\bin\php\php-XXXX\ext
Laragon -> C:\laragon\bin\php\php-XXX\ext
Edit the php.ini file adding
extension=php_redis.dll
Restart server and check phpinfo();. Now Redis should be there!