ErrorException : Undefined offset: 0 in laravel 8 - mysql

This is the line am getting error.
$Notify = $this->value('NOTIFY')[0][0]['value1'];
where value is another function as
public function value($type)
{
$arrs = DB::table('notice')->where('code', $type)
->where('flg', '0')
->get();
$arr=array();
foreach ($arrs as $one) {
$arr[]=array('code'=>$one->code,'value1'=>$one->txt);
}
return array($arr);
}
how I can get value1 ?

Related

Got an error in `php artisan migrate` in Laravel

I always use Laravel project since Laravel 4 up to 7. But this is my first time encountering and error when I migrate my database in freshly download Laravel. This is the error when I migrate:
$e = $event->getThrowable();
if (!$event->hasResponse()) {
$this->finishRequest($request, $type);
throw $e;
}
$response = $event->getResponse();
// the developer asked for a specific status code
if (!$event->isAllowingCustomResponseCode() && !$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) {
// ensure that we actually have an error response
if ($e instanceof HttpExceptionInterface) {
// keep the HTTP status code and headers
$response->setStatusCode($e->getStatusCode());
$response->headers->add($e->getHeaders());
} else {
$response->setStatusCode(500);
}
}
try {
return $this->filterResponse($response, $request, $type);
} catch (\Exception $e) {
return $response;
}
}
/**
* Returns a human-readable string for the specified variable.
*/
private function varToString($var): string
{
if (\is_object($var)) {
return sprintf('an object of type %s', \get_class($var));
}
if (\is_array($var)) {
$a = [];
foreach ($var as $k => $v) {
$a[] = sprintf('%s => ...', $k);
}
return sprintf('an array ([%s])', mb_substr(implode(', ', $a), 0, 255));
}
if (\is_resource($var)) {
return sprintf('a resource (%s)', get_resource_type($var));
}
if (null === $var) {
return 'null';
}
if (false === $var) {
return 'a boolean value (false)';
}
if (true === $var) {
return 'a boolean value (true)';
}
if (\is_string($var)) {
return sprintf('a string ("%s%s")', mb_substr($var, 0, 255), mb_strlen($var) > 255 ? '...' : '');
}
if (is_numeric($var)) {
return sprintf('a number (%s)', (string) $var);
}
return (string) $var;
}
}
Error
Stack trace:
#0 D:\Supporting Enterprises\Projects\Laravel Projects\SuperpagesAPI\artisan(18): require()
#1 {main}
thrown in D:\Supporting Enterprises\Projects\Laravel Projects\SuperpagesAPI\vendor\autoload.php on line 7
Fatal error: Uncaught Error: Class 'ComposerAutoloaderInitbe984857c53a573c5f216d0eb36fe0e7' not found in D:\Supporting Enterprises\Projects\Laravel Projects\SuperpagesAPI\vendor\autoload.php:7
Stack trace:
#0 D:\Supporting Enterprises\Projects\Laravel Projects\SuperpagesAPI\artisan(18): require()
#1 {main}
thrown in D:\Supporting Enterprises\Projects\Laravel Projects\SuperpagesAPI\vendor\autoload.php on line 7
Before this happen I start IIS from the IIS Manager. I don't know if this will effect. I turn it on because I run a C# web application on my end.
It looks like this is composer problem. Just try to run this bash script:
composer dump-autoload

PHP Fatal error Uncaught Error: Call to a member function getMetaTitle() on null in

I'm getting the following error but it says it in Magento core. I was wondering how to debug this because I'm sure there is nothing wrong in Magentos core.
Here is the error:
30-Apr-2018 18:05:23 UTC] PHP Fatal error: Uncaught Error: Call to a member function getMetaTitle() on null in /home/example/public_html/app/code/core/Mage/Catalog/Block/Product/View.php:18
Stack trace:
#0 /home/example/public_html/app/code/core/Mage/Core/Block/Abstract.php(139): Mage_Catalog_Block_Product_View->_prepareLayout()
#1 /home/example/public_html/app/code/core/Mage/Core/Model/Layout.php(322): Mage_Core_Block_Abstract->setLayout(Object(Inchoo_PHP7_Model_Layout))
#2 /home/example/public_html/app/code/core/Mage/Core/Model/Layout.php(332): Mage_Core_Model_Layout->createBlock('review/product_...', 'product.info')
#3 /home/example/public_html/app/code/core/Mage/Core/Model/Layout.php(147): Mage_Core_Model_Layout->addBlock('review/product_...', 'product.info')
#4 /home/example/public_html/app/code/core/Mage/Core/Model/Layout.php(119): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
#5 /home/example/public_html/app/co in /home/example/public_html/app/code/core/Mage/Catalog/Block/Product/View.php on line 18
Here is /home/angelsforeveryon/public_html/app/code/core/Mage/Catalog/Block/Product/View.php:18
protected function _prepareLayout()
{
$this->getLayout()->createBlock('catalog/breadcrumbs');
$headBlock = $this->getLayout()->getBlock('head');
if ($headBlock) {
$product = $this->getProduct();
line 18 here --> $title = $product->getMetaTitle();
if ($title) {
$headBlock->setTitle($title);
}
$keyword = $product->getMetaKeyword();
$currentCategory = Mage::registry('current_category');
if ($keyword) {
$headBlock->setKeywords($keyword);
} elseif ($currentCategory) {
$headBlock->setKeywords($product->getName());
}
$description = $product->getMetaDescription();
if ($description) {
$headBlock->setDescription( ($description) );
} else {
$headBlock->setDescription(Mage::helper('core/string')->substr($product->getDescription(), 0, 255));
}
if ($this->helper('catalog/product')->canUseCanonicalTag()) {
$params = array('_ignore_category' => true);
$headBlock->addLinkRel('canonical', $product->getUrlModel()->getUrl($product, $params));
}
}
return parent::_prepareLayout();
}
Thanks
it looks like your product is null, you need make sure this function work well
$product = $this->getProduct();

Passing Laravel Collection to Vue

I am trying to return customers from model Customer where id < 10. I do have some in the database.
$customers = Customer::where('id', '<', 10)->get();
return json_encode(['customers' => $customers]);
The above code will error out "Trailing data"
and when I try to dd($customers), I get a list of the collection Customer
I have no idea why I keep getting that and why the model is returning raw collection and not an object of the list of customers???
It seems like a null date "updated_at" field is causing the error. don't know why!
Solved By:
on the Customer model I had to do:
//ask Laravel to not manage default date columns
public $timestamps = false;
also I to mutate those columns:
public function setDateRemindedAttribute($value)
{
if (strlen($value)) {
$this->attributes['date_reminded'] = Carbon::createFromFormat('d/m/Y', $value);
} else {
$this->attributes['date_reminded'] = null;
}
}
public function setUpdatedAtAttribute($value)
{
if (strlen($value)) {
$this->attributes['updated_at'] = Carbon::createFromFormat('d/m/Y', $value);
} else {
$this->attributes['updated_at'] = $_SERVER['REQUEST_TIME'];
}
}
Use response()->json() like this
$customers = Customer::where('id', '<', 10)->get();
return response()->json(['customers' => $customers]);

PHP Fatal Error – yii\base\ErrorException

I have uploaded my site to fpt and I can't fix that error. Please help me.
The error is:
PHP Fatal Error – yii\base\ErrorException
Call to undefined function yii\web\json_encode()
Error is on the line $hash = md5(json_encode($this->rules));
The code is:
public function init()
{
parent::init();
if (!$this->enablePrettyUrl || empty($this->rules)) {
return;
}
if (is_string($this->cache)) {
$this->cache = Yii::$app->get($this->cache, false);
}
if ($this->cache instanceof Cache) {
$cacheKey = $this->cacheKey;
$hash = md5(json_encode($this->rules));
if (($data = $this->cache->get($cacheKey)) !== false && isset($data[1]) && $data[1] === $hash) {
$this->rules = $data[0];
} else {
$this->rules = $this->buildRules($this->rules);
$this->cache->set($cacheKey, [$this->rules, $hash]);
}
} else {
$this->rules = $this->buildRules($this->rules);
}
}

Yii2 afterSave. Using changedAttributes show error

I have this weird error in my Yii2 Model's AfterSave Function
When I do this
public function afterSave($insert, $changedAttributes) {
parent::afterSave($insert, $changedAttributes);
if(!$insert):
print_r($changedAttributes);exit;
$this->prepareMail(self::MAIL_APPROVE);
;
}
I get
Array (
[reason_for_travel] => 1 [project_id] => [billable] => 1
[advance_required] => 0 [status] => 2 ) // See it contains 'status'
But when i do this
public function afterSave($insert, $changedAttributes) {
parent::afterSave($insert, $changedAttributes);
if(!$insert):
$status = $changedAttributes['status']; // this line shows error
if($status == Self::STATUS_CONFIRMED):
$this->prepareMail(self::MAIL_APPROVE);
;
;
}
$status = $changedAttributes['status']; This line shows error
Error is "Undefined index: status"
What am I not seeing ?
use this lines:
if(!$insert):
$status = isset($changedAttributes['status']) ? $changedAttributes['status'] : 0); // this line shows error
if($status == Self::STATUS_CONFIRMED):
$this->prepareMail(self::MAIL_APPROVE);
;
;
$changedAttributes contains the old values of the modified fields but only modified fields, valid if exist with "isset" skip errors.
How to check is an attribute has changed after saving
public function afterSave($insert, $changedAttributes){
//isAttributeChangedAfterSave
var_dump(array_key_exists('name', $changedAttributes) && $this->name != $changedAttributes['name']);
//...
}
Note that isAttributeChanged() does not work in afterSave() because after saving, $this->oldAttributes is assigned new values.