I've started to build a new Laravel 5 app. I need a site message feature in my app, so I created one. But now when I'm trying to add messages into stack, I'll get the following error:
FatalErrorException in ExceptionHandler.php line 412: Input string is too long
Apache error log says:
Mon Mar 28 20:25:40.310761 2016] [fcgid:warn] [pid 2075:tid 3028430848] [client 127.0.0.1:56643] mod_fcgid: stderr: PHP Fatal error: Input string is too long in /Users/xxx/Development/Laravel/myapp/vendor/symfony/debug/ExceptionHandler.php on line 412, referer: http://app.dev/page/new
I call Message::set method in my controller:
Message::set('Page created');
And the Message class contains:
<?php
namespace App\Models;
use Session;
class Message {
const MESSAGE_INFO = 0x1;
const MESSAGE_WARNING = 0x2;
const MESSAGE_ERROR = 0x3;
public static function set($message, $type = MESSAGE_INFO) {
$messages = self::get(false);
$messages[$type][] = $message;
Session::put('app.messages', $messages);
}
public static function get($flush = true) {
$default = [ self::MESSAGE_INFO => [], self::MESSAGE_WARNING => [], self::MESSAGE_ERROR => []];
if($flush) Session::pull('app.messages', $default);
return Session::get('app.messages', $default);
}
public static function isAny() {
$messages = self::get(false);
foreach($messages AS $store) if(!empty($store)) return true;
return false;
}
}
I'm so lost with this. Can someone help me with this?
Might be wrong, but I'm not sure you can store an array in a Laravel session.
After you store that array in the session
Session::put('app.messages', $messages);
try to dump your session variable:
dd(Session::get('app.messages'));
Come back with the result you get so we can dig deeper. Good luck!
Problem was with this line:
public static function set($message, $type = MESSAGE_INFO) {
It should be:
public static function set($message, $type = self::MESSAGE_INFO) {
MESSAGE_INFO constant is defined in the Message class, not globally.
The error message was really confusing. When I put the Message::set('Page created'); call inside a try-catch block, then error message was:
FatalErrorException in GroupManagementController.php line 45: Allowed memory size of 268435456 bytes exhausted (tried to allocate 2890768384 bytes)