Laravel custom page for 404 exeption - laravel

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

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.

I have a problem with optional parameters that gives 404 error in laravel 7

I have the following function in laravel 7:
public function create(Franchise $franchise = null)
{
...
}
And the route is as follows:
Route::get('series/create/{franchise?}', 'SerieController#create')->name('serie.create');
when I execute it with parameters for example page_name/series/create/1 it executes normally but when I execute without parameters page_name/series/create I get an error 404 | Not Found.
I also used dd() at the beginning of the function and it keeps giving me the same error
I also did the same with index:
Route::get('series/{franchise?}', 'SerieController#index')->name('serie');
And there it executes me well with or without parameters
Is there a route problem?
it seems you didn't add /series/create to your router. This is the reason why Laravel doesn't see this route and throws a 404 error. Add that route to your router file:

Class 'Illuminate\Auth\Events\Registered' not found -laravel

i have used laravel default registration form.
when i register a new user following error coming.
Symfony\Component\Debug\Exception\FatalThrowableError thrown with message "Class 'Illuminate\Auth\Events\Registered' not found"
Stacktrace:
#0 Symfony\Component\Debug\Exception\FatalThrowableError in /vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php:33

prestashop 1.7 class not found on custom controller

I am creating a custom page /devis
So I have made a simple controller like so:
<?php
class DevisControllerCore extends FrontController
{
public $php_self = 'devis';
public function initContent()
{
$this->setTemplate('devis/devis');
parent::initContent();
}
}
I have been created devis.tpl in my themes/myTheme/templates/devis/ folder
I have been added the friendly url to reach the page (/devis)
My problem is : When I reach the page
Fatal error: Uncaught Error: Class 'DevisController' not found in /var/www/vhosts/example.com/httpdocs/preprod_online/classes/controller/Controller.php:208 Stack trace: #0 /var/www/vhosts/example.com/httpdocs/preprod_online/classes/Dispatcher.php(503): ControllerCore::getController('DevisController') #1 /var/www/vhosts/example.com/httpdocs/preprod_online/index.php(28): DispatcherCore->dispatch() #2 {main} thrown in /var/www/vhosts/example.com/httpdocs/preprod_online/classes/controller/Controller.php on line 208
The solution is to check if the name of the file is correct
structure
/controllers/front/NameController.php
and then (even if it was correctly named) Clear the cache in prestashop back office
parameters > Performances > Clear cache

Laravel Getting Error in exception handler:bootstrap/compiled.php:768 when App::abort(404);

I use:
App::missing(function($exception)
{
return App::make('ErrorController')->get404Error($exception);
});
in \app\filters.php to handle errors 404, it works ok for all the pages like:
"http://example.com/page1, http://example.com/page2, etc.."
But when I use 2 level URL like:
"http://example.com/news/page1"
404 dosen't work if there is a missing page/slug, and an "Whoops, looks like something went wrong." comes, so I trigger 404 error by adding "App::abort(404);" in a controller before the error comes because of the non exisiting slug, then It gives me "Error in exception handler: .../bootstrap/compiled.php:768" . doesn't matter if I have debug true or false.
How can I trigger a 404 error without getting error handler error?, is that possible?
Many thanks.

Resources