PHPDoc return type for MySQL Resource - phpdoc

What is convenient name return type for MySQL resource in PHPDoc?
example i have this code
/**
* Get table data
* #param type $table
* #param type $select
* #param type $condition
* #return mysql_resource
*/
function getResource($table, $field, $condition) {
$resource = mysql_query("SELECT $field FROM $table WHERE $condition ");
return $resource;
}
as you can see #return i write mysql_resource,
is there any convenient name for return mysql resource?

This is typically handled by just "#return resource"... I believe just "resource" matches how var_dump() would show as the object's datatype.

Related

how to save and retrieve base64 encoded data using Laravel model

I am doing a web app using Laravel 7 api.
I receive data with a json request that I must store in the db with a base64 encoding.
I store the data in this way:
public function create_request(Request $request)
{
$req_store = new Req;
$req_store->text = base64_encode($request->input('requestInformations.text'));
$req_store->save();
}
Then obviously to retrieve the data of the text column I must use everytime base64_decode().
My question is that: is there a way to say to Laravel that everytime that I store a new request the column text must be authomatically encoded to base64 and everytime that I retrieve that data from the database the field text must be authomatically base64 decoded? I suppose I must write something in the Req.php model...
Can help?
You should use Accessors & Mutators for this. Please follow the link https://laravel.com/docs/7.x/eloquent-mutators#accessors-and-mutators
public function getTextAttribute($value)
{
return base64_decode($value);
}
public function setTextAttribute($value)
{
$this->attributes['text'] = base64_encode($value);
}
You may use a custom caster
https://laravel.com/docs/7.x/eloquent-mutators#custom-casts
<?php
namespace App\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
class Base64 implements CastsAttributes
{
/**
* Cast the given value.
*
* #param \Illuminate\Database\Eloquent\Model $model
* #param string $key
* #param mixed $value
* #param array $attributes
* #return mixed
*/
public function get($model, $key, $value, $attributes)
{
return base64_decode($value);
}
/**
* Prepare the given value for storage.
*
* #param \Illuminate\Database\Eloquent\Model $model
* #param string $key
* #param array $value
* #param array $attributes
* #return string
*/
public function set($model, $key, $value, $attributes)
{
return base64_encode($value);
}
}
And in your model
use App\Casts\Base64;
/**
* The attributes that should be cast.
*
* #var array
*/
protected $casts = [
'text' => Base64::class,
];

Laravel Lighthouse - Receive Eloquent Builder instead of Query Builder in handleBuilder method?

Is there a way to receive an instance of \Illuminate\Database\Eloquent\Builder instead of \Illuminate\Database\Query\Builder in the handleBuilder method when creating a custom ArgBuilderDirective?
See this example:
<?php
namespace Nuwave\Lighthouse\Schema\Directives;
use Nuwave\Lighthouse\Support\Contracts\ArgBuilderDirective;
use Nuwave\Lighthouse\Support\Contracts\DefinedDirective;
class EqDirective extends BaseDirective implements ArgBuilderDirective, DefinedDirective
{
/**
* Name of the directive.
*
* #return string
*/
public function name(): string
{
return 'eq';
}
/**
* Apply a "WHERE = $value" clause.
*
* #param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder
* #param mixed $value
* #return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
*/
public function handleBuilder($builder, $value)
{
// $builder is an instance of \Illuminate\Database\Query\Builder here.
// Is it possible to receive an instance of Illuminate\Database\Eloquent\Builder instead?
return $builder->where(
$this->directiveArgValue('key', $this->nodeName()),
$value
);
}
}

Laravel Nova: TypeError: Cannot read property 'status' of undefined

A bunch of my Nova ressources stopped working. When trying to create them, I get the following error in the console:
Uncaught (in promise) TypeError: Cannot read property 'status' of undefined
at a.<anonymous> (app.js?id=7319bf5027431449796c:1)
at y (app.js?id=7319bf5027431449796c:1)
at Generator._invoke (app.js?id=7319bf5027431449796c:1)
at Generator.e.(anonymous function) [as next] (http://url/vendor/nova/app.js?id=7319bf5027431449796c:1:460720)
at o (app.js?id=7319bf5027431449796c:1)
at app.js?id=7319bf5027431449796c:1
at new Promise (<anonymous>)
at new t (app.js?id=7319bf5027431449796c:1)
at a.<anonymous> (app.js?id=7319bf5027431449796c:1)
at a.<anonymous> (app.js?id=7319bf5027431449796c:1)
Nothing shows up in the error log at all. Any pointers to where I should be looking? Only affects some ressources, others are working fine.
Edit: Here is one of the affected Nova ressources:
<?php
namespace App\Nova;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\HasMany;
use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Naxon\NovaFieldSortable\Concerns\SortsIndexEntries;
use Naxon\NovaFieldSortable\Sortable;
class Unterprodukt extends Resource
{
use SortsIndexEntries;
public static $defaultSortField = 'order';
/**
* The model the resource corresponds to.
*
* #var string
*/
public static $model = 'App\Unterprodukt';
/**
* Get the displayble label of the resource.
*
* #return string
*/
public static function label()
{
return 'Unterprodukte';
}
/**
* Get the displayble singular label of the resource.
*
* #return string
*/
public static function singularLabel()
{
return 'Unterprodukt';
}
/**
* The logical group associated with the resource.
*
* #var string
*/
public static $group = 'Versicherung';
/**
* The single value that should be used to represent the resource when being displayed.
*
* #var string
*/
public static $title = 'name';
/**
* The columns that should be searched.
*
* #var array
*/
public static $search = [
'id',
'name',
];
/**
* Get the fields displayed by the resource.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
public function fields(Request $request)
{
return [
ID::make()
->sortable()
->hideFromIndex(),
Text::make('Name', 'name')
->sortable(),
BelongsTo::make('Produkt', 'produkt', 'App\Nova\Produkt')
->sortable(),
Sortable::make('Reihenfolge', 'id')
->sortable(),
HasMany::make('Dokumente', 'dokumente', 'App\Nova\Dokument'),
];
}
/**
* Get the cards available for the request.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
public function cards(Request $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
public function filters(Request $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
public function lenses(Request $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
public function actions(Request $request)
{
return [];
}
}
The quick fix for this is this way
Sortable::make('Order', 'id')->exceptOnForms()
I had this problem too, and it was because I had an incoherence between nova fields and migrations fields.
Now, another possible way to fix it is:
php artisan nova:publish
php artisan view:clear
Check this issue for more details: https://github.com/laravel/nova-issues/issues/1735

adodb setConnectionParameter CharacterSet

How do you use the following code in adodb?
Where to put "'CharacterSet ',' UTF-8'"?
protected $connectionParameters = array();
/**
* Adds a parameter to the connection string.
*
* These parameters are added to the connection string when connecting,
* if the driver is coded to use it.
*
* #param string $parameter The name of the parameter to set
* #param string $value The value of the parameter
*
* #return null
*
* #example, for mssqlnative driver ('CharacterSet','UTF-8')
*/
final public function setConnectionParameter($parameter,$value)
{
$this->connectionParameters[$parameter] = $value;
}
set it after you create the ADOdb object, but before you connection to the database.
$db = newADOConnection('mssqlnative');
$db->setConnectionParameter('CharacterSet', 'UTF-8');
$db->connect($host, $user, $password, $database);
'CharacterSet' will not work for mysqli.
Correct one:
$db->setConnectionParameter(MYSQLI_SET_CHARSET_NAME, 'utf8');

An alternative to deprecated addKey() method in Magento?

I am trying to add an index for a column over Magento data setup script.
/** #var Mage_Eav_Model_Entity_Setup $installer */
$installer = $this;
$installer->startSetup();
$installer
->getConnection()
->addKey(
$installer->getTable('enterprise_rma/rma'),
'IDX_EXPORT_DATE',
'export_date'
);
However our inspection tool complains:
The method Varien_Db_Adapter_Pdo_Mysql::addKey() has been deprecated with message: since 1.5.0.0
What I can use instead of addKey() in this case?
Look at the addKey function in the class Varien_Db_Adapter_Pdo_Mysql:
public function addKey($tableName, $indexName, $fields, $indexType = 'index', $schemaName = null)
{
return $this->addIndex($tableName, $indexName, $fields, $indexType, $schemaName);
}
It is just making a call to the addIndex function of the same class, this function is not deprecated, so you should use this one.
/**
* Add new index to table name
*
* #param string $tableName
* #param string $indexName
* #param string|array $fields the table column name or array of ones
* #param string $indexType the index type
* #param string $schemaName
* #return Zend_Db_Statement_Interface
* #throws Zend_Db_Exception|Exception
*/
public function addIndex($tableName, $indexName, $fields,
$indexType = Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX, $schemaName = null)
(My code come from Magento Enterprise 1.12)

Resources