Clarity on the use of pragmarx/firewall package for Laravel 5.2 - php

so I've just completed the install of antonioribeiro/firewall package for laravel, which essentially allows blacklisting and whitelist of IP address and countries.
I'm working through the section on Artisan Commands, but when i try to run 'php artisan firewall:whitelist country:za' I get the following error:
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "firewall:whitelist" is not defined.
Did you mean one of these?
firewall:list
firewall:tables
I have done all the necessary installation steps outlined in the documentation.
What am i doing wrong ? should I be using this command elsewhere ?
I am aware that these can be manually entered into the DB, but this functionality would be great to have.

I managed to fix the problem:
SOLUTION: When you run 'php artisan vendor:publish' it creates a new file called 'firewall.php' in the config directory. This is where you set default options. Simply change 'use_database' to true and the Database specific commands will work.
firewall:blacklist
firewall:clear
firewall:remove
firewall:whitelist

Related

trying to run php artisan tinker returns error "file_exists(): Unable to find the wrapper "hoa" "

I'm trying to open tinker in a Laravel project, but when I run php artisan tinker I get this error:
ErrorException
file_exists(): Unable to find the wrapper "hoa" - did you forget to enable it when you configured PHP?
I can't find everything similar error online, I found only similar errors but with 'wrapper http' .
Does anyone have any suggestions? Thanks
Could this be due to custom code or a library you've imported?
I often find that if I add things to the ServiceProvider or Kernel, they run before many of the artisan commands, and if I've failed to perform the proper "if" checks first, it fails.
I suppose the question I would have in return would be; Is this a fresh Laravel install or have you got custom code and libraries running? I would check there, try removing libraries you've added, HOA from my searching doesn't appear to default to Laravel.
— Happy to revise my answer should more detail be provided
Solved with this command founded on github:
composer require psy/psysh:0.11.2 --dev

Php artisan not working (laravel 5.1)

Suddenly when i type php artisan or any artisan command
i seen this message
[ErrorException]
Trying to get property of non-object
I tried the following
1- php artisan clear-compiled
2- To delete vendor directory and use composer install Or composer update
3- clone a standard Laravel app and put my files app dir and my config
and use composer commands but with step the error has changed to be
[ErrorException]
Trying to get property of non-object
Script php artisan clear-compiled handling the post-install-cmd event returned with an error
[RuntimeException]
Error Output:
Any Suggestions ?
Thanks
If I understand well, you have this issue when you use your app files. It probably means that you have some problem in constructor - you try to run function and the object is not initialized. You should not set up things in constructors (look for example at your controllers) or you will get some "strange" errors and your artisan won't work
After navigation on my app i found the issue in my ServiceProviderClass boot() method in particular when comment one method get data according to subDomain name artisan worked well
Laravel Doc hint for this method
This method is called after all other service providers have been registered, meaning you have access to all other services that have been registered by the framework
for more read Laravel service provider

Creating a new ServiceProvider / Facade as a package in Laravel 5

Introduction
I've never worked with a framework before (Zend, CakePHP, etc) and finally decided to sit down and learn one. I'm starting with Laravel because the code looks pretty and unlike some other frameworks I tried to install, the "Hello, World!" example worked on the first try.
The Goal
For the time being, I want my app to do something very simple:
User submits a request in the form of: GET /dist/lat,lng
The app uses the remote IP address and MaxMind to determine $latitude1 and $longitude1
This request path is parsed for $latitude2 and $longitude2
Using these two positions, we calculate the distance between them. To do this I'm using Rafael Fragoso's WorldDistance PHP class
Since I plan to re-use this function in later projects, it didn't seem right to throw all of the code into the /app directory. The two reusable parts of the application were:
A service provider that connects to MaxMind and returns a latitude and longitude
A service provider that takes two points on a globe and returns the distance
If I build facades correctly then instead of my routes.php file being a mess of closures within closures, I can simply write:
Route::get('dist/{input}', function($input){
$input = explode( "," , $input );
return Distance::getDistance( GeoIP::getLocation(), $input );
});
What I've tried
Initial Attempt
For the first service provider, I found Daniel Stainback's Laravel 5 GeoIP service provider. It didn't install as easily as it should have (I had to manually copy geoip.php to the /config directory, update /config/app.php by hand, and run composer update and php artisan optimize) however it worked: A request to GET /test returned all of my information.
For the second service provider, I started by trying to mimic the directory structure and file naming convention of the GeoIP service provider. I figured that if I had the same naming convention, the autoloader would be able to locate my class. So I created /vendor/stevendesu/worlddistance/src/Stevendesu/WorldDistance\WorldDistanceServiceProvider.php:
<?php namespace Stevendesu\WorldDistance;
use Illuminate\Support\ServiceProvider;
class WorldDistanceServiceProvider extends ServiceProvider {
protected $defer = false;
public function register()
{
// Register providers.
$this->app['distance'] = $this->app->share(function($app)
{
return new WorldDistance();
});
}
public function provides()
{
return ['distance'];
}
}
I then added this to my /config/app.php:
'Stevendesu\WorldDistance\WorldDistanceServiceProvider',
This fails with a fatal error:
FatalErrorException in ProviderRepository.php line 150:
Class 'Stevendesu\WorldDistance\WorldDistanceServiceProvider' not found
Using WorkBench
Since this utterly failed I figured that there must be some other file dependency: maybe without composer.json or without a README it gives up. I don't know. So I started to look into package creation. Several Google searches for "create package laravel 5" proved fruitless. Either:
They were using Laravel 4.2, in which case the advice was "run php artisan workbench vendor/package --resources"
Or
They were using Laravel 5, in which case the docs were completely useless
The official Laravel 5 docs give you plenty of sample code, saying things like:
All you need to do is tell Laravel where the views for a given namespace are located. For example, if your package is named "courier", you might add the following to your service provider's boot method:
public function boot()
{
$this->loadViewsFrom(__DIR__.'/path/to/views', 'courier');
}
This makes the assumption that you have a service provider to put a boot method in
Nothing in the docs says how to create a service provider in such a way that it will actually be loaded by Laravel.
I also found several different resources all of which assume you have a repository and you just want to include it in your app, or assume you have "workbench". Nothing about creating a new package entirely from scratch.
PHP Artisan did not even have a "workbench" command, and there was no "workbench.php" file in /config, so anything I found related to workbench was worthless. I started doing some research on Workbench and found several different questions on StackOverflow.
After a long time and some experimentation, I managed to get laravel/workbench into my composer.json, composer update, composer install, manually build a workbench.php config file, and finally use the PHP Artisan Workbench command to make a new package:
php artisan workbench Stevendesu/WorldDistance --resources
This created a directory: /workbench/stevendesu/world-distance with a number of sub-directories and only one file: /workbench/stevendesu/world-distance/src/Stevendesu/WorldDistance/WorldDistanceServiceProvider.php
This service provider class looked essentially identical to the file I created before, except that it was in the /workbench directory instead of the /vendor directory. I tried reloading the page and I still got the fatal error:
FatalErrorException in ProviderRepository.php line 150:
Class 'Stevendesu\WorldDistance\WorldDistanceServiceProvider' not found
I also tried php artisan vendor:publish. I don't really know what this command does and the description wasn't helpful, so maybe it would help? It didn't.
Question
How do I create a new service provider as a package so that in future projects I can simply include this package and have all the same functionality? Or rather, what did I do wrong so that the package I created isn't working?
After two days of playing with this I managed to find the solution. I had assumed that the directory structure mapped directly to the autoloader's path that it checked (e.g. attempting to access a class Stevendesu\WorldDistance\WorldDistanceServiceProvider would look in vendor/stevendesu/world-distance/WorldDistanceServiceProvider)... This isn't the case.
Reading through the composer source code to see how it actually loads the files, it builds a "classmap" - essentially a gigantic array mapping classes to their respective files. This file is built when you run composer update or composer install - and it will only be built correctly if composer knows the details of your package. That is - if your package is included in your project's composer.json file
I created a local git repository outside of my app then added my package to my app's composer.json file then ran composer update -- suddenly everything worked perfectly.
As for the:
It didn't install as easily as it should have
the secret sauce here was first add the service provider to /config/app.php then, second run php artisan vendor:publish

Laravel: Base table or view not found: 1146 Table 'database.pages doesn't exist

I'm working on a CMS and I have a little problem with my migrations. I added a new migration file and I wanted to add that one. That didn't work so I ran this bit:
php artisan migrate:reset
After that I ran this bit:
php artisan migrate:install
php artisan migrate
And now I get this error:
{"error":{"type":"Illuminate\\Database\\QueryException","message":"SQLSTATE[42S02]: Base table or
view not found:1146 Table 'cms.pages' doesn't exist (SQL: select * from `pages`)"
The error kinda tells me that it can't find the database, because that's true.
I also have a command that runs the migrate and I run that one like this:
php artisan app:install
But that shows the same error...
Remove any lines requesting data from your model from these files to be sure artisan is not trying to load data from your non-existent table:
bootstrap/start.php
app/start/global.php
app/start/local.php
app/routes.php
Also be sure to un-register any service providers that utilize data from that table in their register or boot methods inside of app/config/app.php.
The issue is that these files not only get executed for browser (web) requests, but for all requests, including command-line artisan invocations (e.g. php artisan migrate). So if you try to use something before it is available in any of these files, you are going to have a Bad Time.
You can use this to dictate when your app is running from the console.
I believe this issue only occurs when you run a command
if( !App::runningInConsole() ){
//allow laravel-menu to run
}
This way you will prevent data load from your non-existent table

Laravel 4 Commands stopped working suddenly

Back from vacation, and when I'm trying to run one of my previously working command:
php artisan list
Throws me:
[root#api2]# php artisan list
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Call to a member function getArgument() on a non-object","file":"\/var\/www\/html\/api2.alariscms.com\/vendor\/laravel\/framework\/src\/Illuminate\/Console\/Command.php","line":153}}
And I seriously cannot understand why this happens. I tried debugging the file that throws an error. It awaits argument:
InputInterface $input but it gets NULL
I don't know what can go wrong on a framework level to stop receiving the required object.
Any ideas where to start debugging from? Or I can reload configurations / update laravel via cmd?
Thanks
This is what I would do:
php artisan dump
composer dump-autoload
check for current Laravel version
and then go to that specific command and check for bug there.
Also, what kind of argument are you trying to pass to command ? Is that object - if so check where is implementation of that class ?

Categories