Have a fresh install of Lumen 5.2 and new install of Dingo 1.0.*#dev
I have installed the service provided in bootstrap/app.php
Also setup .env file eg
API_VERSION=v1
API_PREFIX=api
API_SUBTYPE=app
API_DEBUG=true
In the Http/routes.php I have added a test route eg
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api) {
$api->get('example', 'ExampleController#test');
});
This route is not working plus in command line if I try php artisan api:routes
I get error
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "api:routes" is not defined.
Did you mean this?
api:docs
Have I missed something? Also using HTTP Basic if it helps?
In Dingo Documentation -> Creating API Endpoints section you can find this sentence:
"If you're using Laravel 5.1 you can see the registered routes using Artisan.
$ php artisan api:routes
"
If you also run
$ php artisan list
only api:docs is available - api:routes is missing.
That means that this command do not work in Lumen.
composer requires jakubkratina/lumen-dingo-route-list
Add the following code in app/Console/Kernel.php:
protected $commands = [
\JK\Dingo\Api\Console\Commands\RouteListCommand::class
];
By default, as shown in docs, lumen don't ship with api:routes. But you can use lumen-dingo-route-list from jakubkratina. It will add route:list to your artisan.
By the way, I'd to do some adjustments to get it working:
First, include the backlash into the registration
protected $commands = [
\JK\Dingo\Api\Console\Commands\RouteListCommand::class
];
And last, edit vendor/jakubkratina/lumen-dingo-route-list/src/RouteListCommand.php and add this code:
public function handle()
{
return $this->fire();
}
Related
I've created a new service provider to observe a model (App\Providers\EloquentEventServiceProvider.php), like so:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Staff;
use App\Oberservers\StaffObserver;
class EloquentEventServiceProvider extends ServiceProvider
{
public function boot()
{
Staff::observe(StaffObserver::class);
}
}
I've also added it to the config file (config\app.php):
return [
...
'providers' => [
...
App\Providers\EloquentEventServiceProvider::class,
...
]
...
]
The observer methods aren't working though. If I move Staff::observe(StaffObserver::class); to the AppServiceProvider class, it works just fine. So clearly this is an issue with getting my service provider to boot. I've tried php artisan config:clear, php artisan clear-compiled, composer update and composer dump but none have work. Any help is greatly aprpeciated.
your Oberservers name is wrong, as mentioned in the laravel doc observers laravel doc it should be Observers which means all of your observers should be within App\Observers instead of App\Oberservers.
so here we have 2 solutions :
1- if you want to keep the namespace App\Oberservers, you should run these 2 commands below because autoloading of the files may not work properly because we created a new folder Oberservers:
# Autoloading of files
composer dump
# Configure the cache
php artisan config:cache
2- the second solution is to just rename your actual Oberservers folder to Observers, in that way the autoloading of files will work well.
When i put:
use Spatie\Analytics\Analytics;
It gives the error
'Non-static method should not be called statically'
But when I only put:
use Analytics;
I gives a white page on refresh or says
"The use statement with non-compound name 'Analytics' has no effect "
when starting.
I am using Laravel 5.5.4 and although it says the facade should be automatically setup, it wasn't working so I also added this manually to the // config/app.php:
'Analytics' => Spatie\Analytics\AnalyticsFacade::class,
But it still is not working.
from the package github. there was a solution
php artisan config:clear
but it did not work for me.
This package can be installed through Composer.
composer require spatie/laravel-analytics
In Laravel 5.5 and above the package will autoregister the service provider. In Laravel 5.4 you must install this service provider.
config/app.php
'providers' => [
...
Spatie\Analytics\AnalyticsServiceProvider::class,
...
];
In Laravel 5.5 and above the package will autoregister the facade. In Laravel 5.4 you must install the facade manually.
config/app.php
'aliases' => [
...
'Analytics' => Spatie\Analytics\AnalyticsFacade::class,
...
];
You want to use the facade to access the class, you will need to change:
use Spatie\Analytics\Analytics; to use Analytics;
Another way around just import this to your class:
use Spatie\Analytics\AnalyticsFacade as Analytics
It depends in what context you place the use statement.
In Laravel you also can use facades without having to import it with use.
The same class can be called by using \Analytics in your code call.
Example:
\Analytics::fetchMostVisitedPages(\Period::days(7));
I have an issue where the passport namespace is not available when I call passport:client. I set up a brand new Laravel project with version 5.6.34 where I installed Laravel passport according to the documentation. I also checked a similar question and followed all steps there with no sucess.
Calling php artisan passport:client --password --name="Test" from the command line works without any issues and I can see the client in the database.
However if I create a route in routes/web.php like so:
<?php
use Illuminate\Support\Facades\Route;
use \Illuminate\Support\Facades\Artisan;
Route::get('/', function () {
Artisan::call('passport:client', [
'--password' => true,
'--name' => "Test client",
'--quiet' => true,
]);
});
and use the Artisan facade to call the command I get the error below when I navigate to http://homestead.test/.
Symfony \ Component \ Console \ Exception \ CommandNotFoundException
The command "passport:client" does not exist.
I have added Laravel\Passport\PassportServiceProvider::class in the providers array in config/app.php.
How can I call the passport:client command from a web route?
We have a Laravel application that has several hundred database connections which are handled dynamically. In the admin interface you can create a new project and thus a new database where we need to generate a client.
My other option is the instantiate a ClientRepository and call the createPasswordGrantClient() method but I would like to avoid this if possible. I am curious to know why the namespace is available when called on the CLI but not via a request. I can call other commands such as migrate:fresh via a request but passport:client will fail even if it is part of the migration or inside another command.
According to this link, I ran the below commands.
composer update
php artisan config:cache
php artisan migrate
php artisan passport:install
This helped me.
I am using laravel lumen 5.2.
Target [Laravel\Socialite\Contracts\Factory] is not instantiable.
I came across this error when trying to get Laravel to login with Twitter using the Socialite package.
Work already done:
A) In config\app.php
1. Laravel\Socialite\SocialiteServiceProvider::class
2. 'Socialite' => Laravel\Socialite\Facades\Socialite::class
I followed this :
http://goodheads.io/2015/08/24/using-twitter-authentication-for-login-in-laravel-5/
You would need to add the following in config/app.php
In providers add this
Laravel\Socialite\SocialiteServiceProvider::class
In aliases add this
'Socialite' => Laravel\Socialite\Facades\Socialite::class
What helped me is writing
use Socialite;
in the controller (just the alias, not the full path). And then running
php artisan config:clear
in the terminal.
For me, it was to add $app->register( \Laravel\Socialite\SocialiteServiceProvider::class); to app.php in the bootstrap folder, using Lumen 5.6.
When I am using latest Laravel 5.2.2 and Entrust ("zizaco/entrust": "5.2.x-dev") I face this error and not sure how to solve this:
Call to undefined method Zizaco\Entrust\EntrustServiceProvider::hasRole()
I tested this code on HomeController.php
use Entrust;
class HomeController extends Controller
{
public function index()
{
if (Entrust::hasRole('admin')) {
echo "string";
}
return view('home');
}
}
This is my config/app.php service provider
Zizaco\Entrust\EntrustServiceProvider::class
config/app.php facade alias
'Entrust' => Zizaco\Entrust\EntrustFacade::class
I also already generate the model needed
Did I miss something here?
I have same issue, here are the steps I have taken to solve the issue
In your .env file change to cache array
CACHE_DRIVER=array
and dont forget to run
php artisan config:cache
It seems all the steps is correct, and I just need to clear the cache with php artisan config:cache
And if you face an error like below
BadMethodCallException in vendor\laravel\framework\src\Illuminate\Cache\Repository.php line 380:
This cache store does not support tagging.
You need to change in .env this line to array
CACHE_DRIVER=array
Try this:
Open environment file of your laravel change CACHE_DRIVER=file to CACHE_DRIVER=array and save.
Now try your CLI command.
Laravel drivers does not support tagging. To solve this, go to your .env file and change
Cache_driver=file
to
Cache_driver=array
and run
php artisan config:cache