Getting ReflectionException while using a Package - laravel

I am using a Package for roles and permissions management in my laravel 5.1 application and getting error while trying to create roles by using following code.
<?php
use Bican\Roles\Models\Role;
use Illuminate\Database\Seeder;
class RoleTableSeeder extends Seeder
{
public function run()
{
$adminRole = Role::create([
'name' => 'Admin',
'slug' => 'admin',
'description' => '', // optional
'level' => 1, // optional, set to 1 by default
]);
}
}
and I am seeding it using following command on CLI.
php artisan db:seed --class=RoleTableSeeder
but unfortunately I am getting ReflectionException
"[ReflectionException] Class RoleTableSeeder does not exist"...
What might be wrong with it? Looking for your help...
Link to Package: https://github.com/romanbican/roles

Problem solved using the following command on CLI.
composer dump-autoload
Acknowledged: Package Owner

Related

Output is empty when perform a seed in nWidart Laravel

I'm using nWidart package to manager Laravel app using modules.
I perform a migrate on Settings module.
php artisan module:make-migration create_locations_table Settings
php artisan module:migrate Settings
It's ok!
When I make a seeder:
php artisan module:make-seed Locations Settings => It worked!
But: php artisan module:seed Settings
<?php
namespace Modules\Settings\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class LocationsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
Model::unguard();
// $this->call("OthersTableSeeder");
$data = [
'id' => '1',
'name' => 'Hà Nội',
'parent_id' => NULL,
'type' => '1',
'district_id' => NULL,
'province_id' => NULL,
'country_id' => '79162',
'created_at' => '2020-03-26 12:01:08',
'updated_at' => '2020-03-26 12:01:08'
];
DB::table('locations')->insert($data);
}
}
The output is empty!
I think it doesn't go to the LocationsTableSeeder file because when I try dd(1) on it, the output is empty too
Can you help me?
Thanks so much!
Since you're using laravel/framework 5.7.*, you might want to install nwidart/laravel-modules ^4.0 as it is the proper version for you laravel version. See compatibilty.
If that still doesn't work, do this for the meantime:
php artisan db:seed --class=Modules\Settings\Database\Seeders\LocationsTableSeeder
Way forward
Since your project is pretty far behind. I doubt that they will provide any support for this anymore. Upgrading your laravel to ^7.x and laravel-modules to ^7.0 may fix this since there had been an issue about this and has been fixed in the latest versions.

laravel error Call to undefined method Illuminate\Hashing\BcryptHasher::driver()

I'm trying to test my laravel application, run phpunit, but get an error:
Error: Call to undefined method Illuminate\Hashing\BcryptHasher::driver()
laravel 5.5, PHPUnit 7.0
My UserTest:
namespace Tests\Feature;
use App\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class UserTest extends TestCase
{
use RefreshDatabase;
/** #test */
function name_should_not_be_too_long()
{
$response = $this->post('/users', [
'name' => str_repeat('a', 51),
'email' => $this->user->email,
'password' => 'secret',
]);
$response->assertStatus(302);
$response->assertSessionHasErrors([
'name' => 'The name may not be greater than 50 characters.'
]);
}
}
In your CreatesApplication class change this line:
Hash::driver('bcrypt')->setRounds(4);
To this:
Hash::setRounds(4);
After that, do a composer dumpautoload
If still no luck, downgrade to phpunit 6.0.

Laravel 5.5 socialite integration shows error formatRedirectUrl() must be of the type array, null given

I am using "laravel/socialite": "^3.0", to facebook login. But it shows
an error
Type error: Argument 1 passed to Laravel\Socialite\SocialiteManager::formatRedirectUrl() must be of the type array, null given, called in /var/www/html/mas/vendor/laravel/socialite/src/SocialiteManager.php.
It happens when I am calling the below function in my login controller
public function socialLogin($social)
{
return Socialite::driver($social)->redirect();
}
Hi you are missing to give credentials of social media put that in config/services.php
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect' => env('CALLBACK_URL_FACEBOOK'),
],
'google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect' => env('CALLBACK_URL_GOOGLE'),
],
'twitter' => [
'client_id' => env('TWITTER_CLIENT_ID'),
'client_secret' => env('TWITTER_CLIENT_SECRET'),
'redirect' => env('CALLBACK_URL_TWITTER'),
],
'linkedin' => [
'client_id' => env('LINKEDIN_CLIENT_ID'),
'client_secret' => env('LINKEDIN_CLIENT_SECRET'),
'redirect' => env('CALLBACK_URL_LINKEDIN'),
],
'instagram' => [
'client_id' => env('INSTAGRAM_CLIENT_ID'),
'client_secret' => env('INSTAGRAM_CLIENT_SECRET'),
'redirect' => env('CALLBACK_URL_INSTAGRAM'),
],
You must clear the configuration cache file, how? if you use php artisan you will see the command config:clear. Run it:
php artisan config:clear
and now if you access to the $config variable inside the Laravel\Socialite\SocialiteManager::createFacebookDriver()
you will get the configuration element stored in config/services.facebook (Facebook, for example) that before was not 'visible' for Socialite.
In short: run php artisan config:clear
This happened to me just recently, fixed it after reading the following post here on StackOverflow:
Why do I have to run "composer dump-autoload" command to make migration work in laravel
The solution is basically to run the following commands:
php artisan clear-compiled
composer dump-autoload
php artisan optimize
The problem is with the parameters passed to the function socialLogin($social).
Try by manually setting the 'github' or 'facebook' string in the drvier function of Socialite.
Dont forget to mention 'github' , 'facebook, etc in the route in web.php
I had same problem.
I got this errot because of copy/paste while reading Laravel doc. In my case in loginController.php changed this:
// I copied this from Laravel doc
public function redirectToProvider()
{
return Socialite::driver('github')->redirect();
}
//What I really needed
public function redirectToProvider()
{
return Socialite::driver('google')->redirect();
}
I was having the same issue even after had set up my config/services.php file and managed to solve it by clearing my cache. In your project directory run
php artisan optimize:clear
php artisan cache:clear
php artisan config:clear
php artisan config:cache
This ensures that your entire cache is cleared.
NOTE: changing core files in Laravel most of the times require you running the above commands as Laravel tends to use caching to a greater extend to improve on application speeds
Try these
Check if you have all your social media in config/services.php
On your register or login page check the url that corresponds to facebook
a href="{{ url('/login/facebook') }}"
Go to Routes and check if you have routes properly configured
Route::get('login/{social}', 'Auth\LoginController#redirectToProvider');
Route::get('login/{social}/callback', 'Auth\LoginController#handleProviderCallback');
Open Auth/LoginController and check if have
use Socialite;
public function redirectToProvider($social)
{
Socialite::driver($social)->redirect();
}
public function handleProviderCallback($social)
{
$user = Socialite::driver($social)->user();
}
As you've mentioned you are only facing the error with facebook, im pretty sure it must be in first three steps
Open vendor\laravel\socialite\src\SocialiteManager.php
Replace to
protected function formatRedirectUrl(array $config)
{
$redirect = value($config['redirect']);
return Str::startsWith($redirect, '/')
? $this->app['url']->to($redirect)
: $redirect;
}
Open vendor\laravel\socialite\src\SocialiteManager.php and
Replace
protected function createFacebookDriver()
{
$config = $this->app['config']['services.facebook'];
return $this->buildProvider(
FacebookProvider::class, $config
);
}
To
protected function createFacebookDriver()
{
$config = $this->app['config']['services.stripe.facebook'];
return $this->buildProvider(
FacebookProvider::class, $config
);
}

Symfony2 like database creation command in laravel console?

I have used symfony2 console to create database. If I want to create a database named "symfony" I usually mentioned that name in parameters.yml file and run the below command in console
php app/console doctrine:database:create
But when came to laravel, I don't find similar command to create database in laravel. Can anyone help me to find out those command to create database directly from Laravel Console.
You can do that but you will have to create your own command.
First, run php artisan command:make CreateDatabase --command=database:create to generate app/commands/CreateDatabase.php
Then open that file and change it to this: (I left out all comments, but you can obviously keep them in there)
class CreateDatabase extends Command {
protected $name = 'database:create';
protected $description = 'Command description.';
public function fire()
{
DB::statement('CREATE DATABASE '.$this->argument('name'));
}
protected function getArguments()
{
return array(
array('name', InputArgument::REQUIRED, 'Database name'),
);
}
}
Now you only have to register the command in app/start/artisan.php:
Artisan::add(new CreateDatabase);
and you're good to go.
That's how you call it:
php artisan database:create your-desired-database-name
Alternative: artisan tinker
You can always use php artisan tinker to run PHP code (with Laravel bootstrapped):
php artisan tinker
> DB::statement('CREATE DATABASE your-desired-database-name');
As far as I know, you can use php artisan migrate to make migrations including creating tables from Laravel Console. However, you need to create and modify migration files first, where you can create or drop tables.
So if you want to create a table directly from Laravel Console using something like php artisan create database table ***, it is not possible.
I think you can not create database through command so go to app/config/database.php and set your database configuration. details here
'mysql' => array(
'read' => array(
'host' => '192.168.1.1',
),
'write' => array(
'host' => '196.168.1.2'
),
'driver' => 'mysql',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
after setting you can create table through command
php artisan migrate:make create_user_table --table=users
it will generate a file to app/database/migrations name create_users_table. . . . . then you create your table following this link
and finally run this command php artisan migrate

DB:seed file for Laravel 4 working fine on local host, not working on Mediatemple gridserver?

I have a Laravel 4 db:seed file that I am trying to use on mediatemple gridserver. I was able to run a migration with artisan fine (php artisan migrate), and make the tables, but I am not able to seed the tables. This database seeding worked fine on local host. It is only now on a live server that I am experiencing any issues with it. Here is the seed file:
ArtistsTableSeeder.php:
class ArtistsTableSeeder extends Seeder {
public function run()
{
// Uncomment the below to wipe the table clean before populating
// DB::table('artists')->delete();
$artists = array(
);
$Artists = [
['stage_name' => 'Blah', 'city' => 'Blah', 'state' => 'blah', 'video_path' => 'youtube.com', 'image_path' => 'filepickerimage', 'soundcloud_profile' => 'https://soundcloud.com/', 'description' => '', 'created_at' => new DateTime, 'updated_at' => new DateTime]
];
// Uncomment the below to run the seeder
DB::table('artists')->insert($Artists);
}
}
It is spitting out this error:
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"syntax error, unexpected '['","file":"\/nfs\/c09\/h04\/mnt\/139243\/domains\/crowdsets.com\/html\/app\/database\/seeds\/ArtistsTableSeeder.php","linemichaelsutyak.com#n26:/home/139243/domains/crowdsets.com/html$ php artisan db:seed
It is complaining about the line that starts the array:
$Artists = [
I have no idea why this is happening. A little help would be appreciated. Thank you!
That syntax error you get is probably caused by a feature that has been added in PHP 5.4 (short array syntax), so I'd guess your hoster still runs 5.3.x.
You should check the PHP version on the mediatemple grid server and update it if necessary.

Resources