How to use RouteCollection in Laravel5.0 - laravel-5

I want to all route namelist, actionlist and other data inside of controller in laravel 5.0 by using Symfony\Component\Routing\Annotation\Route;component
I've used below code in view it will word as well but if I used in Controller I will get errors
$routes = Route::getRoutes();
dd($routes);
Errors happen when I used this method in Controller.
FatalErrorException in Handler.php line 26:
Uncaught TypeError: Argument 1 passed to App\Exceptions\Handler::report() must be an instance of Exception, instance of Error given,
called in vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 73 and defined in
.../app/Exceptions/Handler.php:26
Stack trace:
#0 /vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(73): App\Exceptions\Handler->report(Object(Error))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Error))
#2 {main}
thrown
This is the result if i used those methods inside of views
#routes: array:3 [▶]
#allRoutes: array:329 [▶]
#nameList: array:260 [▶]
#actionList: array:325 [▶]

Try adding the following line in your controller:
use Illuminate\Support\Facades\Route;

Related

Livewire multiple issues with file upload

What seems to be the problem:
6 exceptions being logged with each upload (although the file gets uploaded)
Steps to Reproduce:
Follow the documentation page to create simple file upload
Try uploading a file
Check laravel log file
Laravel version: 5.7
Livewire version: 1.3.5
Laravel log sample:
[2021-01-21 11:05:07] local.ERROR: {"userId":47,"email":"user#example.com","exception":"[object] (Exception(code: 0): at /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php:114)
[stacktrace]
#0 /home/ameer/public_html/livewire.local/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(755): Livewire\\Component->Livewire\\ComponentConcerns\\{closure}()
#1 /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php(121): rescue(Object(Closure), Object(Closure), false)
#2 [internal function]: Livewire\\Component->Livewire\\ComponentConcerns\\{closure}(Object(ReflectionParameter), 0)
#3 /home/ameer/public_html/livewire.local/vendor/laravel/framework/src/Illuminate/Support/Collection.php(1034): array_map(Object(Closure), Array, Array)
#4 /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php(122): Illuminate\\Support\\Collection->map(Object(Closure))
#5 /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php(99): Livewire\\Component->resolveActionParameters('startUpload', Array)
#6 /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/Connection/ConnectionHandler.php(46): Livewire\\Component->callMethod('startUpload', Array)
...
After some debugging I found that the exception is caused by line #111 in vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php
I was able to work around the issue by overriding the resolveActionParameters method from the livewire component file.
Changed the method to simply return a collection of $params
protected function resolveActionParameters($method, $params)
{
return collect($params);
}
So far this has prevented the excesive logging of exceptions and didn't break any livewire functionality.

Laravel custom page for 404 exeption

I faced a problem - I can’t render a custom view for Laravel 5.8 404 error.
I have a resources/views/errors/404.blade.php file that I want to display to visitors.
According to Laravel documentation (https://laravel.com/docs/5.8/errors#custom-http-error-pages) nothing more is needed, a custom view for 404 errors should be displayed without problems.
I have service provider, here is its boot method:
public function boot ()
{
    abort (404); // if i generate a 404 error from here, everything works fine and 404.blade.php is displayed without problems
    View :: composer (['*'], function ($view) {
    abort (404); // but if i generate a 404 error from here, it displays NotFoundHttpException
});
It turns out that calling abort (404) from an anonymous function does not allow you to display a custom view on a 404 error ???
UPDATE
if I generate a 404 error from an anonymous function, I get this exception:
Symfony\Component\Debug\Exception\FatalErrorException thrown with message "Uncaught Symfony\Component\HttpKernel\Exception\NotFoundHttpException in C:\Downloads\OSPanel\domains\site.com\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:992
Stack trace:
#0 C:\Downloads\OSPanel\domains\site.com\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(46): Illuminate\Foundation\Application->abort(404, '', Array)
#1 C:\Downloads\OSPanel\domains\site.com\app\Providers\SiteViewServiceProvider.php(70): abort(404)
#2 C:\Downloads\OSPanel\domains\site.com\app\Providers\SiteViewServiceProvider.php(42): App\Providers\SiteViewServiceProvider->getAntiLocaleURL()
#3 C:\Downloads\OSPanel\domains\site.com\vendor\laravel\framework\src\Illuminate\View\Concerns\ManagesEvents.php(164): App\Providers\SiteViewServiceProvider->App\Providers\{closure}(Object(Illuminate\View\View))
#4 C:\Downloads\OSPanel\domains\site.com\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(344): Illuminate\View\Factory->Illuminate\View\Concerns\{closure}('composing: erro...', Array)
#5 C:\Do"
Stacktrace:
#0 Symfony\Component\Debug\Exception\FatalErrorException in C:\Downloads\OSPanel\domains\site.com\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:992

How to fix null given error in laravel-dump-server?

I added "beyondcode/laravel-dump-server": "^1.2"
to my Laravel 5.7 application and sometimes I got error
[2018-10-18 03:44:02] local.ERROR: Argument 1 passed to Symfony\Component\VarDumper\Dumper\HtmlDumper::dump() must be an instance of Symfony\Component\VarDumper\Cloner\Data, null given, called in /mnt/_work_sdb8/wwwroot/lar/Votes/vendor/symfony/var-dumper/Command/Descriptor/HtmlDescriptor.php on line 47 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Argument 1 passed to Symfony\\Component\\VarDumper\\Dumper\\HtmlDumper::dump() must be an instance of Symfony\\Component\\VarDumper\\Cloner\\Data, null given, called in /mnt/_work_sdb8/wwwroot/lar/Votes/vendor/symfony/var-dumper/Command/Descriptor/HtmlDescriptor.php on line 47 at /mnt/_work_sdb8/wwwroot/lar/Votes/vendor/symfony/var-dumper/Dumper/HtmlDumper.php:111)
[stacktrace]
I run server in my console as :
php artisan dump-server --format=html > public/dump.html
I added wrapper method to commom trait of my app:
<?php
namespace App\Http\Traits;
use File;
use Barryvdh\Debugbar\Facade as Debugbar;
use Carbon\Carbon;
use Config;
use Intervention\Image\Facades\Image as Image;
trait funcsTrait
{
public function d($data)
{
if (empty($data)) {
return;
}
dump($data);
}
and calling this method in my control :
$this->d('ProfilePageTest Test51:: $newUserSessionData::' . print_r($newUserSessionData, true));
And sometimes I got error described above.
In my wrapper I tried to exclude calling of dump with empty value, supposing that empty value could be reason of this error ?
But looks like the reason was different. If there is a way make work it properly?
Thanks!

Header Error while using laravel Mail function

While using laravel Mail function , I am recieving the following error:
Header may not contain more than a single header, new line detected
Here is my stacktrace obtained from error logs:
[2015-03-04 23:52:31] production.ERROR: exception 'ErrorException'
with message 'Header may not contain more than a single header, new line detected' in /var/www/pickup/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php:342
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleError(2, 'Header may not ...', '/var/www/pickup...', 342, Array)
#1 /var/www/pickup/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php(342): header('statusText: Exp...', false, 412)
#2 /var/www/pickup/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php(375): Symfony\Component\HttpFoundation\Response->sendHeaders()
#3 /var/www/pickup/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(643): Symfony\Component\HttpFoundation\Response->send()
#4 /var/www/pickup/public/index.php(49): Illuminate\Foundation\Application->run()
#5 {main} [] []
My Mail function is :
public function sendmail($user){
Mail::queue('emails.verify', array('encryption'=>self::encrypt($user->email) , 'name'=>$user->first_name), function($message) use($user)
{
$message->to($user->email, $user->first_name)->subject('[Pickup] Please verify your email '.$user->email);
});
}
It sounds like one of the variables you're sending into the to method contains a newline character, and that the to method expects you sanitize those values yourself.
I'd start with a simple trim call
$message->to(trim($user->email), trim($user->first_name))->subject(
'[Pickup] Please verify your email '.trim($user->email));
If that doesn't work it means one of those variables has a newline in the middle. I'd try logging the values, and then sanitizing the variables based on what you found. Also, if you just want to skip bad data, wrapping everything in a try/catch is another approach
try
{
$message->to(trim($user->email), trim($user->first_name))->subject(
'[Pickup] Please verify your email '.trim($user->email));
}
catch (\Exception $e)
{
\Log::error($e->getMessage());
}

How to fix Magento 1.7 Developer mode

Whenever I am turning on the Developer mode in Magento 1.7 I am getting this warning message
If there is any other warning or error this there it will show that error
But when there is no error this screen is coming.
Once I turn off the developer mode i can use web site.
Warning: get_class() expects parameter 1 to be object, boolean given in >C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php on line 1340
0 [internal function]: mageCoreErrorHandler(2, 'get_class() exp...', 'C:\xampp\htdocs...', >1340, Array) #1 C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php(1340): >get_class(false) #2 C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php(1317): >Mage_Core_Model_App->_callObserverMethod(false, 'check', Object(Varien_Event_Observer)) #3 >C:\xampp\htdocs\magento\app\Mage.php(447): Mage_Core_Model_App->dispatchEvent('controller_fron...', Array) #4 >C:\xampp\htdocs\magento\app\code\core\Mage\Core\Controller\Varien\Front.php(147): ?>Mage::dispatchEvent('controller_fron...', Array) #5 >C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php(749): ?>Mage_Core_Controller_Varien_Front->init() #6 >C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php(1094): Mage_Core_Model_App->_initFrontController() #7 >C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\App.php(354): Mage_Core_Model_App->getFrontController() #8 C:\xampp\htdocs\magento\app\Mage.php(683): Mage_Core_Model_App->run(Array) #9 C:\xampp\htdocs\magento\index.php(87): Mage::run('', 'store') #10 {main}
Any help or guidance would we appreciated.
You have a defunct observer; see Mage_Core_Model_App::_callObserverMethod() (link):
protected function _callObserverMethod($object, $method, $observer)
{
if (method_exists($object, $method)) {
$object->$method($observer);
} elseif (Mage::getIsDeveloperMode()) {
Mage::throwException('Method "'.$method.'" is not defined in "'.get_class($object).'"');
}
return $this;
}
From the rest of the stack trace it's possible to see that the event being observed is controller_front_init_routers (ref. Mage_Core_Controller_Varien_Front::init() (link)). Unless something has gone awry with Mage_Cms_Controller_Router (link), the issue must be with a custom module which is configured to observe this event.
To find the offending configuration, search in app/code for <controller_front_init_routers>.
You could also create a test script which does not invoke the Front Controller and use it to debug:
<?php
ini_set('display_errors',true);
error_reporting(E_ALL | E_STRICT);
include 'app/Mage.php';
Mage::setIsDeveloperMode(true);
Mage::app();
Zend_Debug::dump(
Mage::getConfig()->getXpath('//controller_front_init_routers//class')
);
Stock output would be as follows; anything else is your troublemaker:
array(1) {
[0] => object(Mage_Core_Model_Config_Element)#66 (1) {
[0] => string(26) "Mage_Cms_Controller_Router"
}
}

Resources