Difference between getMethod() and getRealMethod() in Symphony5 - php

I am not able to understand the difference between getMethod() and getRealMethod() in Symphony5.
I am using:
Symfony 5
PHP 7.4.3
I have already read through this StackOverflow post, but I am still facing strange issues.
What I want to achieve: Currently if I give an empty body to a
POST/PUT request then symfony gives a 500 Internal Server Error. But,
I want to give a 400 Bad Request Error to the user along with a custom
error message like "Empty request body with PUT/POST not allowed"
I have created this Request Listener,
namespace App\EventListener;
use Exception;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
class RequestListener
{
/**
* #var LoggerInterface $logger
*/
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function __invoke(RequestEvent $event): ?Response
{
$request = $event->getRequest();
$method = $request->getMethod();
$realMethod = $request->getRealMethod();
// this echo below is just to know the values for $method and $realMethod for debugging
echo("method = $method and real method = $realMethod");
if (in_array($method, [Request::METHOD_POST, Request::METHOD_PUT]) && $request->get('data') === null) {
$this->logger->info("Method PUT/POST with an empty body");
return new Response(null, Response::HTTP_BAD_REQUEST);
}
}
}
I have also added this Request Listener to the services.yaml file as,
App\EventListener\RequestListener:
tags:
- { name: kernel.event_listener }
Now when I try to test this with postman I have the following response,
as you can see, the method I used is clearly shown as POST, symfony returns it as GET both for getMethod() and getRealMethod() (by the way, I am not sure why I get the echo message "method = GET and real method = GET" twice). And thus I am not able to check for the empty body for POST/PUT.
EDITED:
Running bin/console debug:event-dispatcher gives this output:
"kernel.request" event
----------------------
------- ---------------------------------------------------------------------------------------------- ----------
Order Callable Priority
------- ---------------------------------------------------------------------------------------------- ----------
#1 Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure() 2048
#2 Symfony\Component\HttpKernel\EventListener\ValidateRequestListener::onKernelRequest() 256
#3 Nelmio\CorsBundle\EventListener\CorsListener::onKernelRequest() 250
#4 Symfony\Component\HttpKernel\EventListener\SessionListener::onKernelRequest() 128
#5 Symfony\Component\HttpKernel\EventListener\LocaleListener::setDefaultLocale() 100
#6 Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest() 32
#7 ApiPlatform\Core\EventListener\QueryParameterValidateListener::onKernelRequest() 16
#8 Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest() 16
#9 Symfony\Component\HttpKernel\EventListener\LocaleAwareListener::onKernelRequest() 15
#10 Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener::configureLogoutUrlGenerator() 8
#11 Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener::onKernelRequest() 8
#12 ApiPlatform\Core\EventListener\AddFormatListener::onKernelRequest() 7
#13 ApiPlatform\Core\EventListener\ReadListener::onKernelRequest() 4
#14 ApiPlatform\Core\Security\EventListener\DenyAccessListener::onSecurity() 3
#15 ApiPlatform\Core\EventListener\DeserializeListener::onKernelRequest() 2
#16 ApiPlatform\Core\Security\EventListener\DenyAccessListener::onSecurityPostDenormalize() 1
#17 App\EventSubscriber\EmptyRequestBodySubscriber::handleEmptyRequestBody() 1
#18 App\EventListener\RequestListener::__invoke() 0
#19 ApiPlatform\Core\Bridge\Symfony\Bundle\EventListener\SwaggerUiListener::onKernelRequest() 0
------- ---------------------------------------------------------------------------------------------- ----------
As you can see, my listener is found registered at #18,
#18 App\EventListener\RequestListener::__invoke() 0

Related

Laravel | Queue failed : Missing argument 1 for App\Jobs\SendCollectionSMS:

All my jobs fail because of this strange error and can't figure out whats the problem here.
Job:
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* #return void
*/
public $fName, $lName, $colAmt, $colDate, $totalAmt, $balAmt, $dueDate, $mobile_no, $is_loan_complete;
public function __construct($fName, $lName, $colAmt, $colDate, $totalAmt, $balAmt, $dueDate, $mobile_no, $is_loan_complete)
{
//
$this->fName = $fName;
$this->lName = $lName;
$this->colAmt = $colAmt;
$this->colDate = $colDate;
$this->totalAmt = $totalAmt;
$this->balAmt = $balAmt;
$this->dueDate = $dueDate;
$this->mobile_no = $mobile_no;
$this->is_loan_complete = $is_loan_complete;
}
/**
* Execute the job.
*
* #return void
*/
public function handle($fName, $lName, $colAmt, $colDate, $totalAmt, $balAmt, $dueDate, $mobile_no, $is_loan_complete)
{
//
$username = "xxxxxxxxxx";
$hash = "xxxxxxxxxxxxxxxxxxxxxxxxx";
// Config variables. Consult http://api.textlocal.in/docs for more info.
$test = "0";
// Data for text message. This is the text message data.
$sender = "xxxxx"; // This is who the message appears to be from.
$numbers = $mobile_no; // A single number or a comma-seperated list of numbers
$message = "Dear ".$fName." ".$lName.", your payment of Rs. ".$colAmt." has been received on ".$colDate.".
Total: Rs. ".$totalAmt.", Balance: ".$balAmt.", Due Date: ".$dueDate.". Thank You";
// 612 chars or less
// A single number or a comma-seperated list of numbers
$message = urlencode($message);
$data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test;
$ch = curl_init('http://api.textlocal.in/send/?');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $result = curl_exec($ch); // This is the result from the API
curl_close($ch);
$this->pusher($result);
}
From the error in my failed_jobs table I notice that the handle function doesn't even run due the argument error
Exception thrown:
exception 'ErrorException' with message 'Missing argument 1 for App\Jobs\SendCollectionSMS::handle()' in C:\xampp\htdocs\financetest1\app\Jobs\SendCollectionSMS.php:42
Stack trace:
#0 C:\xampp\htdocs\financetest1\app\Jobs\SendCollectionSMS.php(42): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Missing argumen...', 'C:\\xampp\\htdocs...', 42, Array)
#1 [internal function]: App\Jobs\SendCollectionSMS->handle()
#2 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(30): call_user_func_array(Array, Array)
#3 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#4 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#5 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Container\Container.php(531): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#6 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#7 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(114): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(App\Jobs\SendCollectionSMS))
#8 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\SendCollectionSMS))
#9 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#10 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(43): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\SendCollectionSMS), NULL)
#11 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(69): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#12 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(291): Illuminate\Queue\Jobs\Job->fire()
#13 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(258): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#14 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(110): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#15 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(101): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#16 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#17 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#18 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(30): call_user_func_array(Array, Array)
I'm calling the job from a controller like :(sorry for the mess in below code but it works)
dispatch(new SendCollectionSMS(ucwords($collection->loan->customer->first_name), ucwords($collection->loan->customer->last_name), $collection->collected_amount, Carbon::parse($collection->created_at)->format('d-m-Y'), $collection->loan->loan_amount, ($collection->loan->loan_amount - $collection->loan->collected_amount), Carbon::parse($collection->loan->end_date)->format('d-m-Y'), $collection->loan->customer->mobile_no, false));
Now I am positive that the arguments which I am passing when creating a new job in my controller are proper but It seems there is an issue in the way I'm referencing the variables in my handler.
Whats going wrong here?
This is a very old post, but for anyone who runs into this problem.
Your handle function doesn't need any variables
public function handle()
Within this function you can get your variables by calling them as followed:
$this->fName
If you still run into the "missing argument 1" problem: Restart your artisan command
php artisan queue:work
This took me a while to figure out, changing your Job file has no effect if your queue:work is already running.

Owncloud app - dependency injection issue

I get the following error from Owncloud when I try to inject my storage class to my controller.
Request ID: PYpBq4u97OltF80ORglm
Type: OCP\AppFramework\QueryException
Code: 0
Message: Could not resolve storage! Class storage does not exist
File: /var/www/html/lib/private/appframework/utility/simplecontainer.php
Line: 89
Trace
#0 /var/www/html/lib/private/appframework/utility/simplecontainer.php(104): OC\AppFramework\Utility\SimpleContainer->resolve('storage')
#1 /var/www/html/lib/private/appframework/utility/simplecontainer.php(64): OC\AppFramework\Utility\SimpleContainer->query('storage')
#2 /var/www/html/lib/private/appframework/utility/simplecontainer.php(83): OC\AppFramework\Utility\SimpleContainer->buildClass(Object(ReflectionClass))
#3 /var/www/html/lib/private/appframework/utility/simplecontainer.php(104): OC\AppFramework\Utility\SimpleContainer->resolve('OCA\\BusMediaMon...')
#4 /var/www/html/lib/private/appframework/utility/simplecontainer.php(64): OC\AppFramework\Utility\SimpleContainer->query('OCA\\BusMediaMon...')
#5 /var/www/html/lib/private/appframework/utility/simplecontainer.php(83): OC\AppFramework\Utility\SimpleContainer->buildClass(Object(ReflectionClass))
#6 /var/www/html/lib/private/appframework/utility/simplecontainer.php(104): OC\AppFramework\Utility\SimpleContainer->resolve('OCA\\BusMediaMon...')
#7 /var/www/html/lib/private/appframework/app.php(97): OC\AppFramework\Utility\SimpleContainer->query('OCA\\BusMediaMon...')
#8 /var/www/html/lib/private/appframework/routing/routeactionhandler.php(45): OC\AppFramework\App::main('GpsController', 'online', Object(OC\AppFramework\DependencyInjection\DIContainer), Array)
#9 [internal function]: OC\AppFramework\routing\RouteActionHandler->__invoke(Array)
#10 /var/www/html/lib/private/route/router.php(276): call_user_func(Object(OC\AppFramework\routing\RouteActionHandler), Array)
#11 /var/www/html/lib/base.php(882): OC\Route\Router->match('/apps/busmediam...')
#12 /var/www/html/index.php(39): OC::handleRequest()
#13 {main}
In the controller I have:
class GPSController extends Controller {
private $gpsService;
private $busService;
private $appStorage;
public function __construct($AppName, IRequest $request, GPSService $gpsService, BusService $busService, AppStorage $appStorage){
In the application.php I have:
$container->registerService('AppStorage', function($c) {
return new AppStorage(
$c->query('UserStorage'),
$c->query('AppName'),
$c->query('CoreConfig'),
$c->query('UserId'));
});
$container->registerService('UserStorage', function($c) {
return $c->query('ServerContainer')->getUserFolder();
});
and
$container->registerService('GPSController', function($c) {
return new GPSController(
$c->query('AppName'),
$c->query('Request'),
$c->query('GPSService'),
$c->query('BusService'),
$c->query('AppStorage')
);
});
The same storage class is injected into another controller and it works fine there.
What am I doing wrong?

Google_Service_Exception 403 when listing groups with PHP

Getting an error when trying to list the groups of my domain through the PHP Directory API. The really weird thing is that if I list the groups using OAuth playground, it works seamlessly with these scopes:
https://www.googleapis.com/auth/admin.directory.group
https://www.googleapis.com/auth/admin.directory.group.member
Note: I'm not using a service account do this. My email address has super admin access, so I'm assuming this should be fine when trying to manage groups and group members? I'm using Slim 3 to handle the applications details. My client is initialized and authenticated (according to a quick var_dump on the object), yet I get an error when trying to do:
$service = new \Google_Service_Directory($this->client);
var_dump($service->groups->listGroups(["domain" => "example.google.com"])); // placeholder domain for SO
and here is the error I'm receiving when trying to load the page so I can list the groups:
#0 /Applications/MAMP/htdocs/aslists/vendor/google/apiclient/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client))
#1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request))
#2 /Applications/MAMP/htdocs/aslists/vendor/google/apiclient/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array)
#3 /Applications/MAMP/htdocs/aslists/vendor/google/apiclient/src/Google/Http/REST.php(46): Google_Task_Runner->run()
#4 /Applications/MAMP/htdocs/aslists/vendor/google/apiclient/src/Google/Client.php(593): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
#5 /Applications/MAMP/htdocs/aslists/vendor/google/apiclient/src/Google/Service/Resource.php(240): Google_Client->execute(Object(Google_Http_Request))
#6 /Applications/MAMP/htdocs/aslists/vendor/google/apiclient/src/Google/Service/Directory.php(2122): Google_Service_Resource->call('list', Array, 'Google_Service_...')
#7 /Applications/MAMP/htdocs/aslists/src/controllers/DashboardController.php(23): Google_Service_Directory_Groups_Resource->listGroups(Array)
#8 [internal function]: a_s\controllers\DashboardController->index(Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
...
#18 {main}
Why would the query fail using the PHP API, but succeed on OAuth playground?
Update 1
My apologies in advance, this will contain a lot of code...
I spent some time tinkering around following the PHP Quickstart example where my client_secret.json file is loaded into the application like so:
$this->client->setAuthConfigFile('/path/to/client_secret.json');
$credentialsPath = $this->expandHomeDirectory('/path/to/.credentials/admin-directory_v1-php-quickstart.json');
if(file_exists($credentialsPath)) {
$accessToken = file_get_contents($credentialsPath);
}
if(isset($accessToken)) {
$this->client->setAccessToken($accessToken);
}
if($this->client->isAccessTokenExpired()) {
$this->client->refreshToken($this->client->getRefreshToken());
file_put_contents($credentialsPath, $this->client->getAccessToken());
}
$this->service = new \Google_Service_Directory($this->client);
If I use this method, it works perfectly with my application – very strange. I did additional investigation between this method and using Google to sign into the application and I was unable to find anything conclusive. Given that, it should work if I use Google to sign in, but it still doesn't.
Here is how I am initializing the client:
class GoogleController extends Controller {
private static $APP_NAME = "Lists Manager";
private static $CLIENT_ID = "...";
private static $CLIENT_SECRET = "...";
private static $REDIRECT_URI = "postmessage";
private static $ACCESS_TYPE = "offline";
private static $scopes = [
\Google_Service_Oauth2::USERINFO_PROFILE,
\Google_Service_Oauth2::USERINFO_EMAIL,
\Google_Service_Directory::ADMIN_DIRECTORY_GROUP,
\Google_Service_Directory::ADMIN_DIRECTORY_GROUP_MEMBER,
\Google_Service_Directory::ADMIN_DIRECTORY_USER
];
protected $client;
public function __construct($container) {
parent::__construct($container);
$this->client = new \Google_Client();
$this->client->setApplicationName(self::$APP_NAME);
$this->client->setClientId(self::$CLIENT_ID);
$this->client->setClientSecret(self::$CLIENT_SECRET);
$this->client->setRedirectUri(self::$REDIRECT_URI);
$this->client->setScopes(self::$scopes);
$this->client->setAccessType(self::$ACCESS_TYPE);
}
}
From here, I have another controller which extends GoogleController that contains an ajax endpoint (i.e. where the access code it POSTed to). The code for this is shown below:
class LoginController extends GoogleController {
public function __construct($container) {
parent::__construct($container);
}
public function login($request, $response) {
if($this->client->isAccessTokenExpired()) {
unset($_SESSION[GoogleController::AS_PERSISTENT_CLIENT_OBJECT]);
$this->tokens = $this->client->authenticate($request->getBody()->getContents());
// $this->client->setAccessToken($this->token); // Not sure if I need to do this. Either way, I still get the exception
}
$_SESSION[GoogleController::AS_PERSISTENT_CLIENT_OBJECT] = serialize($this->client);
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write($this->generateJsonSuccess('dashboard'));
}
}

How can I add the session ID to all log entries in Laravel 5.2

I understand that I can add attributes to Monolog using the TagProcessor
$log->getMonolog()->pushProcessor(
new TagProcessor(
array(
'session: ' => session_id(),
'session2' => Session::getId()
)
)
);
And that I should extend Illuminate\Foundation\Bootstrap\ConfigureLogging.
This works ok, however when I try to add the session ID I get errors.
It seems that the session and Request objects are not available at the time the logger is produced?
[2016-03-30 18:52:21] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Fatal error: Class 'Session' not found in /mywebapp/bootstrap/ConfigureLogging.php:43
Stack trace:
#0 /mywebapp/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/ConfigureLogging.php(60): Bootstrap\ConfigureLogging->configureTechOpsHandler(Object(Illuminate\Foundation\Application), Object(Illuminate\Log\Writer))
#1 /mywebapp/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/ConfigureLogging.php(30): Illuminate\Foundation\Bootstrap\ConfigureLogging->configureHandlers(Object(Illuminate\Foundation\Application), Object(Illuminate\Log\Writer))
#2 /mywebapp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(203): Illuminate\Foundation\Bootstrap\ConfigureLogging->bootstrap(Object(Illuminate\Foundation\Application))
#3 /mywebapp/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(232): Illuminate\Foundation\Application->bootstrapWith(Array)
#4 /mywebapp/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(127): Illuminate\Foundation\Http\Kernel->bootstrap()
#5 /mywebapp/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(99): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#6 /mywebapp/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#7 {main}
Gist for my custom ConfigureLogging.php file: https://gist.github.com/quixand/323227a08ede13e1536e51f37000674b
We used the following in the end, in ConfigureLogging.php
<?php namespace Bootstrap;
use Illuminate\Log\Writer;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Bootstrap\ConfigureLogging as BaseConfigureLogging;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter;
use Monolog\Logger as Monolog;
class ConfigureLogging extends BaseConfigureLogging {
/**
* Configure the Monolog handlers for the application.
*
* #param \Illuminate\Contracts\Foundation\Application $app
* #param \Illuminate\Log\Writer $log
* #return void
*/
protected function configureDailyHandler(Application $app, Writer $log)
{
// Stream handlers
$logPath = $app->storagePath().'/logs/laravel.log';
$logStreamHandler = new RotatingFileHandler(
$logPath,
$app->make('config')->get('app.log_max_files', 5));
// Adds Username to each log line
$log->getMonolog()->pushProcessor( function ($record) {
$record['extra']['user'] = \Session::get("username");
$record['extra']['sessionId'] = \Session::getId();
return $record;
});
// Formatting
// the default output format is "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"
$logFormat = "%datetime% [%level_name%] (%channel%) %extra%: %message% %context%\n";
$formatter = new LineFormatter($logFormat, null, true, true);
$logStreamHandler->setFormatter($formatter);
// push handlers
$logger = $log->getMonolog();
$logger->pushHandler($logStreamHandler);
}
}
You are missing use Session; at the top of your file

Monolog get requested url and simple log on in Laravel 5

I have checked the official repo of monolog and put together below code, its working great and I am getting response in Slack. But the response are very verbose, How Can i get simple response, without Stack Trace.
And as suggested on doc I have added $monolog->pushProcessor(new WebProcessor($_SERVER)); but its not giving any information about requested URL and server.
class AppServiceProvider extends ServiceProvider {
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
if ($this->app->environment('production')) {
// Get The Logger
$monolog = Log::getMonolog();
// **********************************************************************************************
// I have tried official WebProcessor to get url, but its not giving me anything
// **********************************************************************************************
$monolog->pushProcessor(new WebProcessor($_SERVER));
$monolog->pushProcessor(function ($record) {
$record['extra']['session_id'] = Cookie::get(config('session.cookie'));
$record['extra']['request_id'] = Session::get('request_id');
return $record;
});
$slackHandler = new SlackHandler(env('SLACK_TOKEN'), '#sss-sslogs', 'sss-log', true, ':warning:', Logger::ERROR);
// **********************************************************************************************
// Setup Line Formatter but no luck
// **********************************************************************************************
// the default date format is "Y-m-d H:i:s"
$dateFormat = "Y n j, g:i a";
// the default output format is "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"
$output = "%datetime% > %level_name% > %message% %context% %extra%\n";
// finally, create a formatter
$formatter = new LineFormatter($output, $dateFormat);
$slackHandler->setFormatter($formatter);
$monolog->pushHandler($slackHandler);
}
}
Above code is giving me below response in Slack channel
exception 'Illuminate\Database\Eloquent\ModelNotFoundException' with message 'No query results for model [App\User].' in /home/vagrant/Code/App/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:151
Stack trace:
#0 /home/vagrant/Code/App/app/Http/Controllers/PortfolioController.php(30): Illuminate\Database\Eloquent\Builder->firstOrFail()
#1 [internal function]: App\Http\Controllers\PorofileController->show('users')
#2 /home/vagrant/Code/App/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(246): call_user_func_array(Array, Array)
#3 /home/vagrant/Code/App/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(162): Illuminate\Routing\Controller->callAction('show', Array)
#4 /home/vagrant/Code/App/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(107): Illuminate\Routing\ControllerDispatcher->call(Object(App\Http\Controllers\PortfolioController), Object(Illuminate\Routing\Route), 'show')
#5 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#6 /home/vagrant/Code/App/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#7 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#8 /home/vagrant/Code/App/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(101): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#9 /home/vagrant/Code/App/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(108): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#10 /home/vagrant/Code/App/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(67): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(App\Http\Controllers\PortfolioController), Object(I…
Level
----------------
ERROR
Where is the requested URL and session data??
How can I get only below part with requested URL, I am not interested in Stack trace:
exception 'Illuminate\Database\Eloquent\ModelNotFoundException' with message 'No query results for model [App\User].' in /home/vagrant/Code/App/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:151

Categories