Does request() helper work with laravel queue - php

I am trying to send email using laravel queue and database jobs table. In one of my file which is generating pdf which is attached with email has helper request()->organization, however it is throwing some sort of exception does laravel queue supports request() helper with queue?
Error:
#0 /var/www/app/Http/Services/Payslip.php(18): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Trying to get p...', '/var/www/app/Ht...', 18, Array)

Send the request data in the __construct function

Related

laravel job payload index job undefined

My job sometimes throws an exception:
Undefined index: job
#1 D:\home\site\repository\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(192): Illuminate\Queue\Jobs\Job->failed(Object(Exception))
#2 D:\home\site\repository\vendor\laravel\framework\src\Illuminate\Queue\InteractsWithQueue.php(47): Illuminate\Queue\Jobs\Job->fail(Object(Exception))
The corresponding function in the framework (Job.php):
protected function failed($e)
{
$payload = $this->payload();
[$class, $method] = JobName::parse($payload['job']);
...
So it seems that job is not set in payload. Where and how does it get set? I never do this manually and I think this should always be set automatically by laravel!?
I did not have this issue before I upgraded to laravel 8 from 5.8

Symfony: type error when using flash bag in controller

In order to get the flash bag of the session and add a flash message, in the controller I call:
$request->getSession()->getFlashBag()->addFlash(...);
(where $request is an instance of Request)
but I get the following IDE type error:
Method 'getFlashBag' not found in
null|\Symfony\Component\HttpFoundation\Session\SessionInterface
The problem is that $request->getSession() returns a SessionInterface, which does not contain the getFlashBag method.
That's why the IDE is complaining, even if the actual object returned by that method is an instance of the Session class which has the getFlashBag method.
When inside a controller, a quick solution can just be using:
$this->addFlash(...);
instead of:
$request->getSession()->getFlashBag()->addFlash(...);

Get Monolog JSON Stack Trace as Array

I'm using Laravel 4.2 and want to get logs out as JSON. Laravel uses Monolog, so I've configured the JSON formatter like so:
$logHandler = new Monolog\Handler\StreamHandler(Config::get('app.logFile'), Monolog\Logger::DEBUG);
$logHandler->setFormatter(new Monolog\Formatter\JsonFormatter);
Log::getMonolog()->pushHandler($logHandler);
The problem is that stack traces are included as part of the message string, like so:
{
"message": "exception 'Exception' with message 'Socket operation failed: Host name lookup failure' in /var/www/vendor/clue/socket-raw/Socket/Raw/Socket.php:388\nStack trace:\n#0 /var/www/vendor/clue/socket-raw/So..."
}
Can someone point me in the right direction to make the stack trace its own separate array in the json?
Long overdue update:
The primary problem is that Laravel, and lots of code following its example, tries to log the exception by itself, e.g., Log::error($e). This is the wrong way to log an exception with Monolog. That first parameter is supposed to be a simple message string. In processing it, Monolog\Logger::addRecord() explicitly casts the message to a string:
$record = array(
'message' => (string) $message,
//...
);
If $message is actually an exception, you get the whole stack trace as a string. Unfortunately, this is what Laravel's default exception handler does.
The correct way to get a stack trace as an array is to pass the exception in as context so that it's available non-stringified to the formatter. For instance:
Log::error($e->getMessage(), ['exception' => $e]);
Something equivalent is what you need to put in your custom exception handler for Laravel, and then you can use a proper JSON formatter and get what you except.

Post Web Service in codeigniter using REST Server not working and showing error

I am new for codeigniter and I am using Phil Sturgeon’s REST server for "post" type of web service. althiugh my 'get' type web service is working perfectly. Below is my controller code for post web service.
require(APPPATH.'libraries/REST_Controller.php');
class json extends REST_Controller {
public function __construct() {
parent::__construct();
}
public function data_post() {
$user = array(
'id' => $params['id']
);
$this->response(array('status'=>'success'), 200);
}
}
and i amd using rest add on to check web services working or not but i am getting below error.
Fatal error: Uncaught exception 'Exception' with message 'Format class does not support conversion from "php".' in /home/magnetic/public_html/touch/order-form/application/libraries/Format.php:51 Stack trace: #0 /home/magnetic/public_html/touch/order-form/application/libraries/Format.php(31): Format->__construct('{"id": "restCli...', 'php') #1 /home/magnetic/public_html/touch/order-form/application/libraries/REST_Controller.php(247): Format->factory('{"id": "restCli...', 'php') #2 /home/magnetic/public_html/touch/order-form/application/controllers/json.php(6): REST_Controller->__construct() #3 /home/magnetic/public_html/touch/order-form/system/core/CodeIgniter.php(308): json->__construct() #4 /home/magnetic/public_html/touch/order-form/index.php(202): require_once('/home/magnetic/...') #5 {main} thrown in /home/magnetic/public_html/touch/order-form/application/libraries/Format.php on line 51
http://awesomescreenshot.com/0cd38frz01 is screenshot of rest addon error
Please let me know what else i need to do if anything remaining in my code and please let me know the whole process of using rest server for 'post' web services.
Thanks in advance
In the body of the RESTClient, try sending:
id=restClient%20Test
instead of
{"id": "restCliente Test"}

Ion Auth/CodeIgniter Fatal Error: Undefined method Ion_auth::get_user() called

Receiving this fatal error when trying to access my planner.php and shared.php controllers. Any thoughts?
Fatal error: Uncaught exception 'Exception' with message 'Undefined method Ion_auth::get_user() called' in
/application/libraries/Ion_auth.php:88 Stack trace: #0
/application/core/MY_Controller.php(50): Ion_auth->__call('get_user', Array) #1
/application/core/MY_Controller.php(50): Ion_auth->get_user() #2
/application/controllers/user/planner.php(9): Common_Auth_Controller->__construct() #3
/system/core/CodeIgniter.php(288): Planner->__construct() #4 /index.php(202): require_once('/Users/lrussell...') #5 {main} thrown in/application/libraries/Ion_auth.php on line 88
Library Extension I'm Using for Ion Auth:
http://jondavidjohn.com/blog/2011/01/scalable-login-system-for-codeigniter-ion_auth
Planner Controller:
http://pastie.org/private/wc1bq6eiqb9hn8iubwdgq
Shared Controller:
http://pastie.org/private/uj3ta8dw3jl7kqxizs9n1a
Ion_auth Library Line 88 Segment:
http://pastie.org/private/mhgwdzjyhatwsdrux4gqpa
CRUD Model:
http://pastie.org/private/m2nhfqzabdsx5eiz6xqupw
Events Model:
http://pastie.org/private/b6ksjoowl7wde9errow
Shared Model:
http://pastie.org/private/f741jfnf8o2l5oxphnrl5w
Uhm, it happened to me the same exact thing. In the latest releases of this library, Ben Edmunds used php magic method __call() so that you don't have to call a model's method by using the regular syntax $this->ion_auth_model->method() but using instead $this->ion_auth->method(), as if it was a method belonging to the library.
But, actually, that method belongs to the model. So, if you go have a look at the model, you'll see that there's no get_user() method (nor is there in the library!), or at least in the version I talk about (the latest or the one just before. I downloaded a fresh copy one or two weeks ago).
I think there are some errors in the documentation he provided (though the overall work he did is awesome, kudos to Ben).
You can try using the user() model method, which should yield to the same result (it's the closer in functionality). So call $this->ion_auth->user() and see if that fits your needs.
EDIT
To clarify... instead of this...
$this->end_user = $this->ion_auth->current()->row();
do this...
$this->end_user = $this->ion_auth->user()->row();

Categories