In Laravel 5.8 app after submitting form with the data I need to clear data, like doubled spaces, so I created middleware
with clearing code :
app/Http/Middleware/WorkTextString.php :
<?php
namespace App\Http\Middleware;
use Closure;
use App\Http\Traits\funcsTrait;
use function PHPSTORM_META\type;
class WorkTextString
{
use funcsTrait;
public function handle($request, Closure $next, $strip_tags_excluding= false )
{
$inputDataArray = $request->all();
\Log::info($request->all());
$stripTagsExcludingArray= $this->pregSplit('/ /',$strip_tags_excluding);
foreach( $inputDataArray as $next_field_name=>$next_field_value ) {
if ( !empty($next_field_value) and is_string($next_field_value) ) {
$skip_strip_tags= in_array($next_field_name,$stripTagsExcludingArray);
$inputDataArray[$next_field_name] = $this->workTextString($next_field_value, $skip_strip_tags);
}
}
\Log::info('$inputDataArray:: ::'); // I CHECK AND SEE CLEARED DATA!
\Log::info($inputDataArray);
$request->replace($inputDataArray); // THAT DOWS NOT WORK ?
return $next($request);
}
}
But I see that the submitted data are not cleared. Looks like $request->replace does not work for me.
routes/api.php :
Route::resource('skills', 'API\Admin\SkillController')->middleware('WorkTextString');
Modified :
I found article https://dev.to/samolabams/transforming-laravel-request-data-using-middleware-2k7j
and reading the article I suppose I have to use cleanData of my middleware, so I commented method I used before and added
method :
private function cleanData(array $data)
{
\Log::info('$data:: ::');
\Log::info($data);
return collect($data)->map(function ($value, $key) {
\Log::info('$value:: ::');
\Log::info($value);
$value= 'Some text ';
return $value;
})->all();
}
Just to check and replace any value
BuT i got error in log file:
[2019-12-24 12:40:48] local.ERROR: Function name must be a string {"userId":1,"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Function name must be a string at /mnt/_work_sdb8/wwwroot/lar/CTasksRestAPI/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:164)
[stacktrace]
#0 /mnt/_work_sdb8/wwwroot/lar/CTasksRestAPI/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#1 /mnt/_work_sdb8/wwwroot/lar/CTasksRestAPI/vendor/tymon/jwt-auth/src/Http/Middleware/Authenticate.php(32): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#2 /mnt/_work_sdb8/wwwroot/lar/CTasksRestAPI/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Tymon\\JWTAuth\\Http\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#3 /mnt/_work_sdb8/wwwroot/lar/CTasksRestAPI/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#4 /mnt/_work_sdb8/wwwroot/lar/CTasksRestAPI/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#5 /mnt/_work_sdb8/wwwroot/lar/CTasksRestAPI/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#6 /mnt/_work_sdb8/wwwroot/lar/CTasksRestAPI/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#7 /mnt/_work_sdb8/wwwroot/lar/CTasksRestAPI/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(58): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
...
and no message I wrote in \Log::info...
Which way is right ?
How to do it correctly ?
I found a decision using method in model for any fields needs clearing:
public function setNameAttribute($value)
{
$this->attributes['name'] = $this->workTextString($value);
}
without middleware and it works for me
Related
I added proengsoft/laravel-jsvalidation to my laravel 6 app which works ok on my
ubuntu 18 with PHP 7.2.24
But My client pulling the version got error on his Windows / php 7.4.2 as :
#57 C:\\xampp\\htdocs\\primewatch\\public\\index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#58 {main}
[previous exception] [object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Argument 2 passed to Proengsoft\\JsValidation\\JsValidatorFactory::__construct() must be of the type array, null given, called in C:\\xampp\\htdocs\\primewatch\\vendor\\proengsoft\\laravel-jsvalidation\\src\\JsValidationServiceProvider.php on line 38 at C:\\xampp\\htdocs\\primewatch\\vendor\\proengsoft\\laravel-jsvalidation\\src\\JsValidatorFactory.php:37)
[stacktrace]
#0 C:\\xampp\\htdocs\\primewatch\\vendor\\proengsoft\\laravel-jsvalidation\\src\\JsValidationServiceProvider.php(38): Proengsoft\\JsValidation\\JsValidatorFactory->__construct(Object(Illuminate\\Foundation\\Application), NULL)
#1 C:\\xampp\\htdocs\\primewatch\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(799): Proengsoft\\JsValidation\\JsValidationServiceProvider->Proengsoft\\JsValidation\\{closure}(Object(Illuminate\\Foundation\\Application), Array)
#2 C:\\xampp\\htdocs\\primewatch\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(681): Illuminate\\Container\\Container->build(Object(Closure))
#3 C:\\xampp\\htdocs\\primewatch\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(785): Illuminate\\Container\\Container->resolve('jsvalidator', Array, true)
#4 C:\\xampp\\htdocs\\primewatch\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(629): Illuminate\\Foundation\\Application->resolve('jsvalidator', Array)
#5 C:\\xampp\\htdocs\\primewatch\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(770): Illuminate\\Container\\Container->make('jsvalidator', Array)
#6 C:\\xampp\\htdocs\\primewatch\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(1245): Illuminate\\Foundation\\Application->make('jsvalidator')
#7 C:\\xampp\\htdocs\\primewatch\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Facades\\Facade.php(198): Illuminate\\Container\\Container->offsetGet('jsvalidator')
#8 C:\\xampp\\htdocs\\primewatch\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Facades\\Facade.php(166): Illuminate\\Support\\Facades\\Facade::resolveFacadeInstance('jsvalidator')
#9 C:\\xampp\\htdocs\\primewatch\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Facades\\Facade.php(255): Illuminate\\Support\\Facades\\Facade::getFacadeRoot()
#10 C:\\xampp\\htdocs\\primewatch\\storage\\framework\\views\\68757a9c9b2f658eb9358cc98549740ca7f9e23d.php(34): Illuminate\\Support\\Facades\\Facade::__callStatic('formRequest', Array)
#11 C:\\xampp\\htdocs\\primewatch\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Engines\\PhpEngine.php(43): include('C:\\\\xampp\\\\htdocs...')
#12 C:\\xampp\\htdocs\\primewatch\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Engines\\CompilerEngine.php(59): Illuminate\\View\\Engines\\PhpEngine->evaluatePath('C:\\\\xampp\\\\htdocs...', Array)
#13 C:\\xampp\\htdocs\\primewatch\\vendor\\facade\\ignition\\src\\Views\\Engines\\CompilerEngine.php(36): Illuminate\\View\\Engines\\CompilerEngine->get('C:\\\\xampp\\\\htdocs...', Array)
#14 C:\\xampp\\htdocs\\primewatch\\vendor\\laravel\\framework\\src\\Illuminate\\View\\View.php(143): Facade\\Ignition\\Views\\Engines\\CompilerEngine->get('C:\\\\xampp\\\\htdocs...', Array)
I have app/Http/Requests/ShipRequest.php with :
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use App\Http\Traits\funcsTrait;
use App\Ship;
class ShipRequest extends FormRequest
{
use funcsTrait;
/**
* Determine if the user is authorized to make this request.
*
* #return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* #return array
*/
public function rules()
{
$request= Request();
return Ship::getValidationRulesArray( $request->get('id') );
}
}
And in Ship Model method getValidationRulesArray is defined as :
public static function getValidationRulesArray($ship_id= null) : array
{
$validationRulesArray = [
'title' => [
'required',
'string',
'max:255',
Rule::unique(with(new Ship)->getTable())->ignore($ship_id),
],
'company_id' => 'required|exists:' . ( with(new Company)->getTable() ).',id',
];
return $validationRulesArray;
}
I wonder why such error on Windows/php 7.4. Can it be php different issue or what ?
"laravel/framework": "^6.2",
"proengsoft/laravel-jsvalidation": "^2.5",
Thanks!
make sure use JsValidatorFacade not JsValidatorFactory
you can use this syntac
use Proengsoft\JsValidation\Facades\JsValidatorFacade as JsValidator;
Sometimes, all you need is to run following command
php artisan config:cache
because validator is not loading the jsvalidation config file just created in config directory
Hope it helps somebody.
I'm trying to use lumen passport for our project. I already installed by following this lumen-passport. I successfully receive the access_token by doing postman request and here is my code for it.
{
"grant_type": "client_credentials",
"client_id": "2",
"client_secret": "1QaxEr6P3K6kKsqa63nA2SMLsczuJJRvufXEDrzY",
"scope": "*"
}
I receive the access token
{
"token_type": "Bearer",
"expires_in": 120,
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImJmY2YyYjZlM2I4MTlkMzI3OTE5ODgyMjM0M2NlNjcxM2MyYjFkMjJjZDFiNTQ5ODQ5MjkxMzllMDc2NWJmM2UyZGMyMTMxYTRmYzk1MzNkIn0.eyJhdWQiOiIyIiwianRpIjoiYmZjZjJiNmUzYjgxOWQzMjc5MTk4ODIyMzQzY2U2NzEzYzJiMWQyMmNkMWI1NDk4NDkyOTEzOWUwNzY1YmYzZTJkYzIxMzFhNGZjOTUzM2QiLCJpYXQiOjE1Njg2MTg4ODksIm5iZiI6MTU2ODYxODg4OSwiZXhwIjoxNTY4NjE5MDA5LCJzdWIiOiIiLCJzY29wZXMiOlsiKiJdfQ.hIXxn1MJMSS6m2XXrt-EJatMp7KoomzKYnk_McpeeBo9VMYUtKU7tPWCmtw7XpFZFJWvGhIY8cx_A6kTaizFjqEkKmlj3jpjs9X9QUZNQ4J5CwjIcXUAJLRqw6WYvvW94GdPAgUBFz6eIbg_Tzt-149dIwPzlVpd8Ln3Bu84Htj9tiWalkdu5EL6lO_Mc8mFJpAh63fJs84_ES02ex_MACsO52pwfXQLPdrjyWSHPdqDj0hRPVMVMLtPdNtYS12MVf8xg_C6KdcB19viRhmlnQwjl98AXGYt_YeeJozKQax2bSSTqTHfNrBZpka7FZFMznkS3gQ8-9d9FYNSNu3Hiia2ZN44JkolBXB4bNpaa82cj_2yrQ-w8oFivOQqX-dQU7RDD5womVbCd8VmxmtUoTTXdWjridl0F5XasWJfc1N2vTGleY_AGi1qC5_39QXTXsEeesgsiGvq4OJCeIRSLvuuwpFUbV7LVfUvJVL3HSM9-PUBDw0Q2q7mCVLMf_ZLf5s_rNP7uTZOIpZUvUKYXCk4rCB6dE7YIGQZkBr2sOQADd8foMvnxEatwIiJoQCxAEHRgeybmBk4gDUhr-9IoroHxnXrcg2LPulfwe5-hS8cAkjh7OvUuld8W17_TzWOUJq1XPpgWCRomSAB_KeXdyFzrGyVXJTD2r_DU1HbJGE"}
in my routes I have these codes.
$router->group(['prefix' => 'api/v1', 'middleware' => 'client'], function() use (&$router){
$router->get('example/{id}', 'ExampleController#getData');});
Why is it every time the token expires I get 500 error instead 401 error?
I checked the logs in the storage logs and here is the error. I don't know if this is really an error.
[2019-09-17 02:39:59] local.ERROR: Illuminate\Auth\AuthenticationException: Unauthenticated. in /var/www/scheduler-app/vendor/laravel/passport/src/Http/Middleware/CheckClientCredentials.php:48
Stack trace:
#0 /var/www/scheduler-app/vendor/illuminate/pipeline/Pipeline.php(163): Laravel\Passport\Http\Middleware\CheckClientCredentials->handle(Object(Laravel\Lumen\Http\Request), Object(Closure))
#1 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Laravel\Lumen\Http\Request))
#2 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Laravel\Lumen\Http\Request))
#3 /var/www/scheduler-app/vendor/illuminate/pipeline/Pipeline.php(104): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}(Object(Laravel\Lumen\Http\Request))
#4 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(413): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#5 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(259): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#6 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(233): Laravel\Lumen\Application->handleFoundRoute(Array)
#7 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(169): Laravel\Lumen\Application->handleDispatcherResponse(Array)
#8 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(416): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(Object(Laravel\Lumen\Http\Request))
#9 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(171): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#10 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(108): Laravel\Lumen\Application->dispatch(NULL)
#11 /var/www/scheduler-app/public/index.php(28): Laravel\Lumen\Application->run()
#12 {main} {"exception":"[object] (Illuminate\\Auth\\AuthenticationException(code: 0): Unauthenticated. at /var/www/scheduler-app/vendor/laravel/passport/src/Http/Middleware/CheckClientCredentials.php:48)
[stacktrace]
#0 /var/www/scheduler-app/vendor/illuminate/pipeline/Pipeline.php(163): Laravel\\Passport\\Http\\Middleware\\CheckClientCredentials->handle(Object(Laravel\\Lumen\\Http\\Request), Object(Closure))
#1 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Laravel\\Lumen\\Http\\Request))
#2 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Laravel\\Lumen\\Http\\Request))
#3 /var/www/scheduler-app/vendor/illuminate/pipeline/Pipeline.php(104): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}(Object(Laravel\\Lumen\\Http\\Request))
#4 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(413): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#5 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(259): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))
#6 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(233): Laravel\\Lumen\\Application->handleFoundRoute(Array)
#7 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(169): Laravel\\Lumen\\Application->handleDispatcherResponse(Array)
#8 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(416): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}(Object(Laravel\\Lumen\\Http\\Request))
#9 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(171): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))
#10 /var/www/scheduler-app/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(108): Laravel\\Lumen\\Application->dispatch(NULL)
#11 /var/www/scheduler-app/public/index.php(28): Laravel\\Lumen\\Application->run()
#12 {main}
I know this is not the best answer for those developers who know lumen passport, but I figure it out the other way to fix it. I just copy the code from CheckClientCredentials, as what I have checked, the code validate the request. here it is
public function handle($request, Closure $next, ...$scopes)
{
$psr = (new DiactorosFactory)->createRequest($request);
try {
$psr = $this->server->validateAuthenticatedRequest($psr);
} catch (OAuthServerException $e) {
throw new AuthenticationException;
}
$this->validateScopes($psr, $scopes);
return $next($request);
}
In my Authentication middleware I add this code.
public function handle($request, Closure $next, $guard = null)
{
$psr = (new DiactorosFactory)->createRequest($request);
try {
$psr = $this->server->validateAuthenticatedRequest($psr);
} catch (OAuthServerException $e) {
return response('Unauthorized.', 401);
}
// if ($this->auth->guard($guard)->guest()) {
// return response('Unauthorized.', 401);
// }
return $next($request);
}
and the routes I have this
$router->group(['prefix' => 'api/v1', 'middleware' => ['auth', 'client']], function() use (&$router){
$router->get('example/{id}', 'ExampleController#getData');
});
It is working now. I receive 401 error and it validates token if it is not expire.
Instead of changing the middleware, just add something like this to the render method of App\Exceptions\Handler
if ($exception instanceof AuthenticationException && $request->acceptsJson()) {
return response()->json(['error' => $exception->getMessage()], 401);
}
Thanks for your solution. I have added a check if it is really a 401 error.
public function handle($request, Closure $next, ...$scopes)
{
$psr = (new PsrHttpFactory(
new Psr17Factory,
new Psr17Factory,
new Psr17Factory,
new Psr17Factory
))->createRequest($request);
try {
$psr = $this->server->validateAuthenticatedRequest($psr);
} catch (OAuthServerException $e) {
if($e->getHttpStatusCode() === 401) {
return response('Unauthorized.', 401);
}
throw new AuthenticationException;
}
$this->validate($psr, $scopes);
return $next($request);
}
My error log is getting filled with this useless text, I have set my job to only try once and the time out to 0 because the jobs can be really long and it depends on the user.
So the job has tries set at 1 timeout at 0, on laravel forge I have set my worker to have max tries at 1 and timeout 0, and still it gives me this error in the logs:
Illuminate\Queue\MaxAttemptsExceededException: A queued job has been attempted too many times. The job may have previously timed out. in /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:385
Stack trace:
#0 /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(311): Illuminate\Queue\Worker->markJobAsFailedIfAlreadyExceedsMaxAttempts('beanstalkd', Object(Illuminate\Queue\Jobs\BeanstalkdJob), 1)
#1 /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(267): Illuminate\Queue\Worker->process('beanstalkd', Object(Illuminate\Queue\Jobs\BeanstalkdJob), Object(Illuminate\Queue\WorkerOptions))
#2 /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(113): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\BeanstalkdJob), 'beanstalkd', Object(Illuminate\Queue\WorkerOptions))
#3 /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\Queue\Worker->daemon('beanstalkd', 'default', Object(Illuminate\Queue\WorkerOptions))
#4 /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(84): Illuminate\Queue\Console\WorkCommand->runWorker('beanstalkd', 'default')
#5 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#6 /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#7 /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#8 /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#9 /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Container/Container.php(539): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#10 /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Illuminate\Container\Container->call(Array)
#11 /home/forge/Altpocket.io/vendor/symfony/console/Command/Command.php(240): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#12 /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Console/Command.php(167): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#13 /home/forge/Altpocket.io/vendor/symfony/console/Application.php(860): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /home/forge/Altpocket.io/vendor/symfony/console/Application.php(218): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /home/forge/Altpocket.io/vendor/symfony/console/Application.php(122): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /home/forge/Altpocket.io/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /home/forge/Altpocket.io/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 {main}
Here is my job:
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Events\PushEvent;
use Cache;
class ImportBittrex implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* #return void
*/
protected $userid;
protected $withdraws;
protected $cachekey;
public $tries = 1;
public $timeout = 0;
public function __construct($userid, $withdraws)
{
$this->userid = $userid;
$this->withdraws = $withdraws;
}
/**
* Execute the job.
*
* #return void
*/
public function handle()
{
$this->cachekey = 'Import-Bittrex2'.$this->userid;
if(Cache::get($this->cachekey) !== null) {
event(new PushEvent('You already have an import running!', 'error', $this->userid));
return $this->userid;
}
Cache::put($this->cachekey, 1, 5);
app('App\Http\Controllers\ImportController')->importDepositsB($this->userid);
app('App\Http\Controllers\ImportController')->importTradesB($this->userid);
app('App\Http\Controllers\ImportController')->insertBuysB($this->userid);
app('App\Http\Controllers\ImportController')->importWithdrawsB($this->userid, $this->withdraws);
app('App\Http\Controllers\ImportController')->insertSellsB($this->userid);
app('App\Http\Controllers\ImportController')->importBalancesB($this->userid);
app('App\Http\Controllers\ImportController')->safeBittrexCheck($this->userid);
Cache::forget('investments'.$this->userid);
Cache::forget('b_investments'.$this->userid);
Cache::forget('deposits'.$this->userid);
Cache::forget('withdraws'.$this->userid);
Cache::forget('balances'.$this->userid);
Cache::forget('balances-summed'.$this->userid);
Cache::forget('deposits'.$this->userid);
Cache::forget('withdraws'.$this->userid);
Cache::forget($this->cachekey);
}
}
Here is my worker on laravel forge:
https://i.imgur.com/lz22zMX.png
What is wrong here? Why does this keep happening.
Basicially in the first function run in the job it will check if the user has a valid api key combination and if it doesnt it catches it and throws an error like so:
https://i.imgur.com/zldnUnT.png
Please help me I'm losing my mind.
I have a big problem with session in Laravel 5.2. My session doesn't set in some route.
Like this
Route::post('add','SiteController#add');
This is my route.php:
Route::get('admin','AdminController#index');
Route::resource('admin/product','ProcuctController');
Route::resource('admin/news','NewsController');
Route::resource('admin/category','CategoryController');
Route::get('session','SiteController#session');
Route::post('add','SiteController#add');
Route::get('/{title}','SiteController#show');
Route::group(['middleware' => ['web']], function () {
Route::get('session','SiteController#session');
Route::post('add','SiteController#add');
});
My file shopping cms basket doesn't work. This is my SiteController function
public function add(Request $request)
{
if(session::has('cart'))
{
$cart=session::get('cart');
if(array_key_exists($request->product_id,$cart))
{
$cart[$request->product_id]++;
}
else
{
$cart[$request->product_id]=1;
}
session::put('cart',$cart);
//var_dump(session::get('cart'));
print 'ok';
}
else
{
$cart=array();
$cart[$request->product_id]=1;
session::put('cart',$cart);
var_dump(session::get('cart'));
}
}
Every time that I click the buy button, condition doesn't return true
In your router.php you register add and session route twice. one is inside of web middleware and another is outside. Remove the outside one. so your router.php will look like
Route::get('admin','AdminController#index');
Route::resource('admin/product','ProcuctController');
Route::resource('admin/news','NewsController');
Route::resource('admin/category','CategoryController');
Route::get('/{title}','SiteController#show');
Route::group(['middleware' => ['web']], function () {
Route::get('session','SiteController#session');
Route::post('add','SiteController#add');
});
And in your SiteController add this line in to top
use session;
I have a custom function to validate a field, but when i test it I have this error from PyroCMS:
Fatal error: Uncaught exception 'Exception' with message 'Undefined callback "$rule" in admin_razze' in /Applications/MAMP/htdocs/pyrocms/system/cms/libraries/MY_Form_validation.php:178 Stack trace: #0 /Applications/MAMP/htdocs/pyrocms/system/codeigniter/libraries/Form_validation.php(341): MY_Form_validation->_execute(Array, Array, 'test') #1 /Applications/MAMP/htdocs/pyrocms/addons/shared_addons/modules/canile/controllers/admin_razze.php(46): CI_Form_validation->run() #2 [internal function]: Admin_razze->nuovo() #3 /Applications/MAMP/htdocs/pyrocms/system/codeigniter/core/CodeIgniter.php(352): call_user_func_array(Array, Array) #4 /Applications/MAMP/htdocs/pyrocms/index.php(280): require_once('/Applications/M...') #5 {main} thrown in /Applications/MAMP/htdocs/pyrocms/system/cms/libraries/MY_Form_validation.php on line 178
this is my code but I can't see the problem...if I remove the callback it work well
function nuovo(){
//Carico librerie e helper per la gestione del form
$this->load->helper('form');
$this->load->library('form_validation');
//Imposto le regole di validazione
$this->form_validation->set_rules('nome','Nome','trim|required|callback_controllo_esistenza');
$this->form_validation->set_rules('copertina','Immagine di copertina','trim|required|xss_clean');
if($this->form_validation->run() == FALSE){
$this->template->build('admin/razze/inserimento');
}
else{
//Recupero i campi e creo l'array per l'inserimento
$dati_insert = array(
'nome' => ucfirst($this->input->post('nome')),
'copertina' => $this->input->post('copertina')
);
//Carico il modello per salvare la razza
$this->load->model('gestione','',TRUE);
//Invio i dati al model
$this->gestione->salva_razza($dati_insert);
redirect('admin/canile/razze');
}
}
public function callback_controllo_esistenza($str){
if($str=="test"){
return FALSE;
}
}
I think your function should be named like the standard CI form validation callbacks, IE,
public function controllo_esistenza($str)
{
if($str=="test")
{
return FALSE;
}
}
Although I would do this:
$this->form_validation->set_rules('nome','Nome','trim|required|callback__controllo_esistenza');
And then this:
public function _controllo_esistenza($str)
{
if($str=="test")
{
return FALSE;
}
}
So your callbacks don't somehow get called via the request.