Laravel 5.3 upgrade - BroadcastServiceProvider error - laravel

I have tried to upgrade laravel 5.3 from 5.2 and I am getting following error while php artisan clear-compiled
Class App\Providers\BroadcastServiceProvider contains 1 abstract
method and must therefore be declared abstract or implement the
remaining methods (Illuminate\Support\ServiceProvider::register)
However, I had not facing such an issue while upgrade in my local environment.
The config/broadcasting.php is as:
<?php
return [
'default' => env('BROADCAST_DRIVER', 'log'),
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
],
];
The app/Providers/BroadcastServiceProvider.php is as:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;
class BroadcastServiceProvider extends ServiceProvider
{
public function boot()
{
Broadcast::routes();
Broadcast::channel('App.User.{userId}', function ($user, $userId) {
return (int) $user->id === (int) $userId;
});
}
}
And .env is as:
CACHE_DRIVER=file
SESSION_DRIVER=file
#BROADCAST_DRIVER=pusher
PUSHER_KEY=someKey
PUSHER_SECRET=SomeSecrete
PUSHER_APP_ID=SomeId
I tried setting default broadcasting driver to log, but seems not working.
Any command I am running like:
php artisan cache:clear Or php artisan config:clear Or php artisan view:clear Or php artisan clear-compiled, I am facing the same error.
I also tried using composer dump-autoload, it works fine but after that if I run php artisan clear-compiled again then also facing the same error.
Please help me.

Looks like you didn't realy update the framework, because Illuminate\Support\ServiceProvider::register method is present in 5.2 and not in 5.3
Double check your update

I have fixed this error by running following artisan commands before updating the composer to upgrade to laravel 5.3.
The commands are:
php artisan config:clear
php artisan cache:clear
php artisan view:clear
php artisan clear-compiled
and then do
composer update
It will solve the said error while upgrading to laravel 5.3.

Related

Laravel Passport POST oauth/token resulted in a '404 Not Found'

I'm using an apache virtualhost: 'gradez.loc', each time I try to access the /oauth/token route with cURL or Postman it returns a 404.
When I use php artisan serve and try to access to route via http://localhost:8000 there is no problem and I get back the access and refesh token.
What I have done already:
ran php artisan route:list I can see it returns all the passport routes correctly,
ran php artisan route:cache and php artisan route:clear
ran php artisan optimize
None of these seem to fix the problem unfortunately. I see a lot of people struggling with the same problem, but there's no good answer to this.
AuthServiceProvider
public function boot()
{
$this->registerPolicies();
Passport::routes();
}
requestAccessToken method:
$response = $http->post(url('/oauth/token'), [
'form_params' => [
'grant_type' => 'password',
'client_id' => config('services.passport.client_id'),
'client_secret' => config('services.passport.client_secret'),
'username' => $userData->username,
'password' => $userData->password,
],
]);
.env:
APP_URL=http://gradez.loc // <- oauth/token results in a 404
running php artisan serve
APP_URL=http://127.0.0.1:8000 // <- oauth/token works as expected!
Turned out my apache routes weren't setup correctly. I was using dnsmasq. I removed it then configured the vhosts myself and then it worked like a charm!

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 loading helper not automatically

I tried to load my helper without composer autoload
For controllers I use:
use \App\Helper;
Works good, But for blade's view how can I load it?
in blade view you can use as \App\Helper::call();
#php
$var = \App\Helper::call();
#endphp
You can do it 2 ways
Solution 1: make aliases
In config\app.php change aliases to
'aliases' => [
'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
...................
'Helper' => App\Helper::class,
]
in blade use
#php
$result = Helper::staticFunction();
// or
$helper = app(Helper::class);
$helper->functionName();
#endphp
Solution 2:
#php
$result = \App\Helper::staticFunction();
// ot
$helper = app(\App\Helper::class);
$helper->functionName();
#endphp
try to clear caches
php artisan cache:clear
php artisan config:clear
php artisan route:clear

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
);
}

Laravel 5.1.4 Entrust set up

I have problems with setting up entrust with L5..1.4
this is what i do:
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Zizaco\Entrust\EntrustServiceProvider::class,
and this: ....
'Storage' => Illuminate\Support\Facades\Storage::class,
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'Entrust' => Zizaco\Entrust\EntrustFacade::class,
And its not working ... crashes my whole php artisan (when i run php artisan):
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined method Illuminate\Foundation\Application::bindShared()
i used this to install entrust:
"zizaco/entrust": "dev-laravel-5"
and then composer update. Now EntrustServiceProvider is under vendor/zizaco/entrust/src/entrust/ ...
any ideas?
After adding
"zizaco/entrust": "dev-laravel-5"
to your composer.json file run:
composer install
Next in the config\app.php add to the providers array:
'Zizaco\Entrust\EntrustServiceProvider',
and under the aliases array add:
'Entrust' => 'Zizaco\Entrust\EntrustFacade',
next run:
php artisan entrust:migration
this will generate the Entrust migration and finally run the migrations:
php artisan migrate
you should now be on your way! For more information check out:
https://github.com/Zizaco/entrust

Resources