I'm trying to use Cartalyst Sentinel for my scripts. I've downloaded the files from github. (https://github.com/cartalyst/sentinel). I've put it on my wamp, and I am trying to follow the instructions here (https://cartalyst.com/manual/sentinel/2.0#native).
This is what I have so far:
<?php
// Import the Sentinel Classes
use sentinel\src\Native\Facades\Sentinel;
use Illuminate\Database\Capsule\Manager as Capsule;
require 'vendor/autoload.php';
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'sentinel',
'username' => '',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
]);
$capsule->bootEloquent();
?> code here
I've followed the instructions but I have changed the directory from the first use... I cannot seem to find vendor/autoload.php. I get the cannot find stream error.
and when I remove that, I get this error.
( ! ) Fatal error: Class 'Illuminate\Database\Capsule\Manager' not found in C:\wamp\www\lab\login.php on line 10
So I'm kind of confused since the manual isn't really providing ways to solve problems and what we need.
Any help would be greatly appreciated!
It seems you have not updated later with the implementation for the Illuminate Database component.
To use it run:
composer require illuminate/database illuminate/events symfony/http-foundation
This will install Illuminate\Database\Capsule hope this works.
I am 4 years late to answer this but believe that this might help someone struggling.
Related
I'm following the codecourse video series Authentication with Slim 3, which is about 3 years old.
I've hit a snag when it comes to using eloquent to access a mysql database.
(the relevant video: https://www.youtube.com/watch?v=70IkLMkPyPs )
the code wasn't quite the same as that currently recommended on the instructions on illuminate/database's docs, so I've modified the code slightly to follow that standard, but regardless of whether I follow Alex's code oon the vid or the following, a parse error results.
$app = new \Slim\App([
'settings' => [
'displayErrorDetails' => true,
'db' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'opium3',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
]
],
]);
$container = $app->getContainer();
/*set up eloquent to use outside laravel*/
use \Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection($container['settings']['db']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
Running the app produced this error:
Parse error: syntax error, unexpected '=' in /var/www/public/opium3/vendor/illuminate/database/DatabaseManager.php on line 65
I'm running this locally on a scotchbox vagrant set up, if that's relevant.
There's a similar question at
Parse error when run illuminate/database/capsule with bootEloquent() in PHP
but this answer doesn't resolve my issue, since the server is running php7.
I have also tried installing packages recommended by illuminate/database, installing php-mbstring, and editing the php.ini file, on the server, but the error persists.
Am I missing something obvious?
Make sure you're using at least PHP 7.1.
/illuminate/database/DatabaseManager.php is using a short hand version of the list()-construct which wasn't available until PHP 7.1.
The "old" way is to:
list($var1, $var2) = someFunction();
while you, since PHP 7.1, can also do:
[$var1, $var2] = someFunction();
The row the error is thrown in is this:
[$database, $type] = $this->parseConnectionName($name);
Note:
If you can't upgrade your PHP version from 7.0 to 7.1.3+, you need to use an older version of the Illuminate/Database-package. Use version 5.5 for PHP 7.0 and then 5.6+ on PHP 7.1.3+
I'm trying to get started with Laravel + PostgreSQL and been following the database tutorial.
Unfortunately, after updating the database configuration file and running php artisan migrate, the following error appears:
[InvalidArgumentException]
Database [postgres] not configured.
What puzzles me is that I didn't specify the "postgres" database in the configuration, but another database I set through cPanel, say "example_database".
Here's some relevant parts of my /config/database.php configuration:
'default' => env('DB_CONNECTION', 'postgres')
And inside the connections array of the same file:
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'example_database'), // This seems to be ignored
'username' => env('DB_USERNAME', 'example_username'),
'password' => env('DB_PASSWORD', 'example_password'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public'
],
The actual database credentials I'm using are working perfectly on my SQL Workbench client, so this seems to be a Laravel config problem. Any ideas? I have searched around for at least an hour to no avail.
You have to enter your configuration in the .env file.
The configuration you made will only be loaded if they are not already defined in .env
You need to use pgsql instead of postgres.
DB_CONNECTION=pgsql
DB_HOST=localhost
DB_DATABASE=DB_NAME
DB_USERNAME=USER
DB_PASSWORD=PW
Laravel sometimes caches your configurations. If you run into this problem while everything looks alright try running
php artisan config:cache
I know this is an old question and it already has an answer; however, here is an small explanation why:
If you check your database.php in the config directory, you will see that you have few connections types, including pgsql. So, the key have to match to the DB_CONNECTION in .env file. You can definitely replace pqsql connection key with postgres, and it will work on the same way.
However, I would recommend replacing the value DB_CONNECTION, instead of modifying the config.
DB_CONNECTION=pgsql
I am trying to make a new Facebook app and got hosting from Asmallorange. The app works perfectly in my local environment that is running PHP 5.5.14.
The app consists of packages that were imported by Composer and autoloaded in my app.
The app in itself is a Slim app and consists of Laravel's Eloquent ORM. I followed tutorials online to integrate those two, and it works perfectly in my local environment.
The code is as follows.
require 'vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'test',
'username' => 'test',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
));
$capsule->bootEloquent();
It works perfectly in my local environment. Just not on the server and fails with this:
PHP Fatal error: Class 'Illuminate\Database\Capsule\Manager' not found in /home/moz/public_html/app/index.php
Referring to line 2 above. I have looked everywhere and couldn't find a solution yet.
Check that your deployment tool has uploaded the autoload_classmap.php file found in the vendors/composer directory. Uploading this should fix the problem.
Alternatively you could get composer to rebuild the autoload_classmap.php file on the server by running the following in the command line from same directory as composer...
php composer dump-autoload
I have an unusual problem with my Laravel 4.2 project connecting to MySQL database. This is my database.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database_name',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
I use XAMPP for Ubuntu.
First, I've created a database in phpMyAdmin. When I tried to run php artisan migrate, it gave me an error of unknown database 'database_name'. I thought it was silly since I've just created a database in phpMyAdmin. Then I tried creating a database through the command line and tried running the migration again. It worked. Tables were created under the database I specified when I run show tables in the command line. It seems to me that the Laravel project is connected to a different mysql server than the phpMyAdmin. Is that even possible? How can I solve this problem?
I've been trying to solve this for hours but still, no luck. Hope someone can help me with my problem.
I solved the problem by following the solution in the link provided by Bulk. I just have to run sudo /opt/lampp/bin/php artisan migrate instead of the plain php artisan migrate. With this, artisan will use the MySQL version provided by XAMPP.
I started learning Laravel just an hour ago and following tutorials.
My settings for database are as follow (File: app/config/database.php):
'default' => 'mysql',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/production.sqlite',
'prefix' => '',
),
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'laraveltest',
'username' => 'root',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
In mySQL on homestead, I already created laraveltest database. I also created migration file in database/migration directory with following code:
public function up()
{
Schema::create('users', function($table)
{
$table->increments('id');
$table->string('email')->unique();
$table->string('name');
$table->timestamps();
});
}
and migration commands were:
vagrant#homestead:~/Code/Laravel$ php artisan migrate
Migration table created successfully.
Migrated: 2014_08_14_195103_create_users_table
As displayed, table users created but in homestead database, not in laraveltest database. Can someone please tell where I went wrong and how to force laravel to use laraveltest database?
Edit after first comment
File: bootstrap/start.php
$env = $app->detectEnvironment(array(
'local' => array('homestead'),
));
It is most likely an issue with environments. Check that you have a database configuration file in app/config/local/, and check that it has the proper settings.
If anyone finds this looking for the answer for Laravel 5 or later: It's the same as #camroncade says, but in this case it's your .env file in the project root you want to look at.
I am currently dealing with this issue as well. Changed the .env file numerous times as well as the config.php file. Nothing seemed to work.
After having done some deep digging into the framework I have found an acceptable temporary workaround to the problem that does not conflict with ANY of Laravel 5.0.2's Exceptions.
NOTE: I'm currently using Ampps 3.4 with php 7.0.2 phpmyadmin 4.4.15.1 on a Windows 8.1 OS.
Inside of the file "ConnectionFactory.php" (located at "laravel\vendor\laravel\framework\src\Illuminate\Database\Connectors"),
scroll down to the public function make located at line 41.
Within this function you can do the following after this statement $config = $this->parseConfig($config, $name); which should be on line 43:
$config['database'] = 'Insert the name of your database here';
This change will allow Laravel to continue with its normal process having no negative effect anywhere with the framework or your project. That is until this bug is fixed by the makers of Laravel or the community.
Till then happy coding! =)