Reputation: 21
I am pulling in standard php code from a file called test5.php into a file called subscription.blade.php.
The code works great in the standard php file and almost works in Laravel blade view. The prompt and associated style displays correctly. However, once one of the two array variables are entered into the password box it gives me nothing but a 500 error. When the same code is tested outside of the blade in a standard file it works fine. I considered .htaccess issues since one directly was effected and not the other and came up empty on troubleshooting attempts. I am of course new to Laravel. I tried to use the code directly in the blade using @php and @endphp directives but did not work so I went with the include. It doesn't seem to like the last line Thanks for any insight on this.
I've pulled in the following code from test5.php into subscription.blade.php using @include('test5')
<?php
include('easy-protect.php');
$options = array(
'skin' => 6,
);
protect(array('testing','123456'), $options);
?>
Error Log:
[2020-01-01 21:39:08] local.ERROR: Call to a member function send() on null {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function send() on null at /home/www/mywebsite.com/index.php:56)
[stacktrace]
#0 {main}
"}
[2020-01-01 21:39:08] local.ERROR: Uncaught Error: Call to a member function send() on null in /home/www/mywebsite.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:123
Stack trace:
#0 /home/www/mywebsite.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(100): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#2 {main}
thrown {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 1): Uncaught Error: Call to a member function send() on null in /home/www/mywebsite.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:123
Stack trace:
#0 /home/www/mywebsite.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(100): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->renderHttpResponse(Object(Symfony\\Component\\Debug\\Exception\\FatalThrowableError))
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleException(Object(Symfony\\Component\\Debug\\Exception\\FatalThrowableError))
#2 {main}
thrown at /home/www/mywebsite.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:123)
[stacktrace]
#0 {main}
"}
index.php:56
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send(); (This is LINE 56)
$kernel->terminate($request, $response);
HandleExceptions.php:100
/**
* Handle an uncaught exception from the application.
*
* Note: Most exceptions can be handled via the try / catch block in
* the HTTP and Console kernels. But, fatal error exceptions must
* be handled differently since they are not normal exceptions.
*
* @param \Throwable $e
* @return void
*/
public function handleException($e)
{
if (! $e instanceof Exception) {
$e = new FatalThrowableError($e);
}
try {
self::$reservedMemory = null;
$this->getExceptionHandler()->report($e);
} catch (Exception $e) {
//
}
if ($this->app->runningInConsole()) {
$this->renderForConsole($e);
} else {
$this->renderHttpResponse($e); (This is LINE 100)
}
}
HandleExceptions.php:123
/**
* Render an exception as an HTTP response and send it.
*
* @param \Exception $e
* @return void
*/
protected function renderHttpResponse(Exception $e)
{
$this->getExceptionHandler()->render($this->app['request'], $e)->send();(This is Line 123)
}
1/5/2020 Update : Findings So Far:
1. @adilbo placing the code at the very beginning of the blade file didn't make any change.
2. In fact I deleted all code from the subscription.blade.php file and left only the easy protect code with exactly the same results. This leads me to believe that it is a filename association in Laravel where perhaps I could make an exclusion but where?
3. I tried the code in my own custom named php blade view in the same directory and it works fine. Using the code inside of the specific filename does not work. I hope that makes sense.
Cause Error: Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException The POST method is not supported for this route. Supported methods: GET, HEAD.
Upvotes: 1
Views: 761
Reputation: 21
public function render($request, Exception $exception) { return parent::render($request, $exception); }
This generated an error detailing that the POST method was not allowed.
/* mypage */ Route::get('/mypage', 'CommonController@view_mypage'); Route::post('/mypage', 'CommonController@view_mypage'); /*mypage*/
Option 1 (least secure) - Exclude the page from being checked for a CSRF Token by adding the following code example to /app/Http/Middleware/VerifyCsrfToken.php
protected $except = [ 'https://mywebsite.com/mypage', ];
Option 2 (most secure)- Get your newly introduced form / page to comply with CSRF protection whether it is inline or as part of the included file depending on your unique scenario. You can learn more about that from Laravel HERE
IMPORTANT: Once you are finished with this and hopefully you've had some success, don't forget to go back to /app/Exceptions/Handler.php and comment out the below line of code. Otherwise, any errors the site generates can easily expose all of your database credentials and API keys within the report.
//return parent::render($request, $exception);
This answer is unique to my scenario but will be very common if you try to integrate other PHP products such as forms into the Laravel framework. Again, please note that I am not a Laravel expert or even moderately knowledgeable. I've had to learn all of this through experiencing this problem. I share this detailed answer in hopes to get someone else who is lost on the right path.
Upvotes: 1