Maybe it is just me but im not sure what this do and why they need to do this?
in the providers that are loaded in laravel they did this
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
...
same for alias
'aliases' => [
'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
...
What does the ::class do and why can't they just leave it off like this?
'aliases' => [
'App' => Illuminate\Support\Facades\App,
'Artisan' => Illuminate\Support\Facades\Artisan,
It just return class name with namespace !
Since PHP 5.5, the class keyword is also used for class name resolution.
You can get a string containing the fully qualified name of the ClassName class by using ClassName::class.
This is particularly useful with namespaced classes.
namespace NS {
class ClassName {
}
echo ClassName::class;
}
The above example will output:
NS\ClassName
Source 1
Php manual
Related
I tried to make a validator for API in laravel
But this error appears
Class 'App\Http\Controllers\Api\Validator' not found
How can I solve this?
Import the facade at the top of your class
use Illuminate\Support\Facades\Validator;
You can also call the Facade alias like so
\Validator::make.....
Anywhere in your code if you have the alias set in config/app.php (it is by default)
'aliases' => [
// Other aliases omitted for brevity
'Validator' => Illuminate\Support\Facades\Validator::class, // <--- Here
'View' => Illuminate\Support\Facades\View::class,
],
Hope this helps
Just use your controller
use Validator;
I want to integrated smartystreets with my laravel project but am not able to do so.
I have tried this link , but it throw me error "Undefined constant 'FireEngineRed\SmartyStreetsLaravel\SmartyStreetsServiceProvider'" when i run "$ php artisan vendor:publish".
Any help would be appreciated.`
Change in step 2 of the above link worked for me:
change this:
'providers' => array(
...
'FireEngineRed\SmartyStreetsLaravel\SmartyStreetsServiceProvider',
)
'aliases' => array(
...
'SmartyStreets' => 'FireEngineRed\SmartyStreetsLaravel\SmartyStreetsFacade',
)
to this:
'providers' => [
...
FireEngineRed\SmartyStreetsLaravel\SmartyStreetsServiceProvider::class,
],
'aliases' => [
...
'SmartyStreets' = > FireEngineRed\SmartyStreetsLaravel\SmartyStreetsFacade::class,
],
Note:Add the SmartyStreets providers and aliases element at the end of the both array.
I have installed payum for laravel 5 but my providers are not updating correctly.
I added 'Payum\LaravelPackage\PayumServiceProvider' to app/config/app.php file.
'providers' => [
...
//All my providers
'Payum\LaravelPackage\PayumServiceProvider',
],
also tried as
'providers' => [
...
//All my providers
Payum\LaravelPackage\PayumServiceProvider::class,
],
anyway the error message i get whenever i try to use artisan to make a controller or any other thing is:
am i missing any configuration for the service provider? any help will be apreciated.
EDIT: i have created a new provider and stopped using the default provider.
i ran php artisan make:provider PayumServiceProvider
and into its register method pasted:
...
public function register()
{
$this->app->resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
$payumBuilder
// this method registers filesystem storages, consider to change them to something more
// sophisticated, like eloquent storage
->addDefaultStorages()
->addGateway('paypal_ec', [
'factory' => 'paypal_express_checkout',
'username' => 'EDIT ME',
'password' => 'EDIT ME',
'signature' => 'EDIT ME',
'sandbox' => true
]);
});
}
...
Still not working
In Laravel 5.2 form class in app.php is:
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
But this code not work in Laravel 5.3.
How to add class Form in Laravel 5.3 ?
Its called the Laravel Collective package and It has been removed from laravel defaults.
You can still integrate and use it.
here is the documentation
Laravel Collective
How to Install
composer require "laravelcollective/html":"^5.3.0"
Next, add your new provider to the providers array of config/app.php:
'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class,
// ...
],
Finally, add two class aliases to the aliases array of config/app.php:
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
1st step install this via composer
composer require "laravelcollective/html":"^5.3.0"
Laravel Collective here
2nd step add this line in config/app.php under providers
'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class,
// ...
],
3rd step
add this 2 line in config/app.php under aliases array
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
final step then link your html and css this way
{{ Html::style('css/demo.css') }}
{{ Html::script('js/demo.js') }}
Yes, I know, there is an exact same question there but the "solution" is not approved nor specified as it should.
So:
1) I installed the stripe library v.3.0 by php composer.phar require stripe/etc
and it installed ok, (otherwise I wouldn't have actually received that error)
2) I have the public test key in the blade Form in the Head section alright
3) Then at the controller I included inside the public function that receives the data from the Form the following: (no problem not my real secret key)
$token = Input::get('stripeToken');
Stripe::setApiKey("sk_test_1VJeJsdfsdgdgVbJODDDD");
3) I also put it in the .env file as
STRIPE_API_SECRET='sk_test_1VJeJsvj7l2ft2eXXsevDD'
and made a call from the config/services.php as
'stripe' => [
'model' => App\User::class,
'key' => '',
'secret' => env('STRIPE_API_SECRET'),
],
but I keep getting that error.
The other same question at SO says that it has "solved" it by:
the solution was to put the stripe api key into AppServiceProvider, into register() class.
That is completely vague, inaccurate and don't know what he is talking about.
Anyone knows? thank you very much
If you look at the Billable code:
/**
* Get the Stripe API key.
*
* #return string
*/
public static function getStripeKey()
{
return static::$stripeKey ?: getenv('STRIPE_SECRET');
}
/**
* Set the Stripe API key.
*
* #param string $key
* #return void
*/
public static function setStripeKey($key)
{
static::$stripeKey = $key;
}
It wants either the static variable or the STRIPE_SECRET environment variable to be defined.
The other answer is a bit vague, but offers a solution. In your AppServiceProvider:
public function register()
{
\App\Models\User::setStripeKey(\Config::get('services.stripe.secret'));
}
I ran into the same issue, and worked around it by setting the key manually in my controller constructor like so:
class SubscriptionController extends Controller {
public function __construct() {
Stripe::setApiKey(env('STRIPE_SECRET'));
}
public function getPlans() {
dd(Plan::all());
}
}
Try to clear cache
php artisan config:cache
https://laravel.com/docs/7.x/configuration#configuration-caching
I had a similar problem and it was because 'stripe' was configured twice in config/services/php. Are you really sure that config/services.php only has one instance of 'stripe' in there?
Here's my example config/services.php, that's working with Stripe, for reference:
<?php
return [
'mandrill' => [
'secret' => env('MANDRILL_SECRET'),
],
'ses' => [
'key' => env('SES_KEY'),
'secret' => env('SES_SECRET'),
'region' => 'us-east-1',
],
'stripe' => [
'model' => 'App\Models\User',
'key' => env('STRIPE_API_PUBLIC'),
'secret' => env('STRIPE_API_SECRET'),
],
];
Set public static $apiKey='sk_test_your api key'; from stripe.php
Comprehensive answer, solving it for the entire application:
.env file:
STRIPE_KEY=pk_live_exampleexampleexampleexampleexampleexampleexample
STRIPE_SECRET=sk_live_exampleexampleexampleexampleexampleexampleexample
config\services.php file:
'stripe' => [
[...]
'key' => env('STRIPE_KEY'),
'secret' => env('STRIPE_SECRET'),
],
app\Providers\AppServiceProvider.php file:
public function boot()
{
[...]
Stripe::setApiKey(config('services.stripe.secret'));
[...]
}
Afterwards, you can also run, on command line:
php artisan config:clear
Explanation:
I use the boot() method instead of register() suggested in other answers for reasons explained here.
php artisan config:clear is not always necessary, but makes sure you're not using cached configuration, preventing the app picking up the changes added above.