In Laravel 8 / livewire 2.5 I use spatie/laravel-permission 5 and for CRUD operations I make checks in components like
public function edit()
{
$loggedUser = Auth::user();
if ( $loggedUser->can(PERMISSION_EDIT_HOSTEL) ) {
return view('livewire.error-msg', [
...
and I need to make such checks in any method of my component.
Looking at Lifecycle Hooks I wonder if there is a way to keep all checks in one place ?
How can I implement it ?
UPDATED BLOCK #1:
I try to use booted method, I see that is has 1 parameter like :
Livewire\Request Object
(
[fingerprint] => Array
(
[id] => N88CNnpmNSd1xzBTuGQc
[name] => admin.crud-items
[locale] => en
[path] => admin/items
[method] => GET
)
[updates] => Array
(
)
[memo] => Array
(
)
when I show listing(render method) and when I call "edit" method :
Livewire\Request Object
(
[fingerprint] => Array
(
[id] => N88CNnpmNSd1xzBTuGQc
[name] => admin.crud-items
[locale] => en
[path] => admin/items
[method] => GET
)
[updates] => Array
(
[0] => Array
(
[type] => callMethod
[payload] => Array
(
[id] => ki8a
[method] => edit
[params] => Array
(
[0] => 44
)
)
)
)
...
It permits me to make checks I need, but I doubt to use booted method parameter, which is not described in docs.
Or there is some official docs on it ? Is it good way/safe to use this way?
Thanks in advance!
Related
I have tried to read content from a s3 object through the below code.
$content = $s3Client->getObject(
array(
'Bucket'=> $bucketName,
'Key' => $pathToObject,
'ResponseContentType' => 'text/plain',
)
);
And I got below response
GuzzleHttp\Psr7\Stream Object (
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #87
[size:GuzzleHttp\Psr7\Stream:private] =>
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
Any help will be appreciated to read object content in S3.
Actually its return Psr7\Stream object.
So if we need to get contents from PSR Stream we have to call getContents() method from the object.
<?php
$s3Client = new Aws\S3\S3Client(array(
'stats' => TRUE,
'http' => array(
'verify' => FALSE,
'connect_timeout' => 30
),
'version' => 'latest'
));
$result = $s3Client->getObject(array(
'Key' => $filename,
'Bucket' => $bucketName
));
echo $result['Body']->getContents();
//Also you can get metadata like this print_r($result['Body']->getMetadata());
Hope this will help someone who is actually using SDK version 3.
Specification here https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-GuzzleHttp.Psr7.Stream.html
I am trying to query my dynamodb table to get feed_guid and status_id = 1. But it returns Query key condition not supported error.
Please find my table schema and query.
$result =$dynamodbClient->createTable(array(
'TableName' => 'feed',
'AttributeDefinitions' => array(
array('AttributeName' => 'user_id', 'AttributeType' => 'S'),
array('AttributeName' => 'feed_guid', 'AttributeType' => 'S'),
array('AttributeName' => 'status_id', 'AttributeType' => 'N'),
),
'KeySchema' => array(
array('AttributeName' => 'feed_guid', 'KeyType' => 'HASH'),
),
'GlobalSecondaryIndexes' => array(
array(
'IndexName' => 'StatusIndex',
'ProvisionedThroughput' => array (
'ReadCapacityUnits' => 5,
'WriteCapacityUnits' => 5
),
'KeySchema' => array(
array(
'AttributeName' => 'status_id',
'KeyType' => 'HASH'
),
),
'Projection' => array(
'ProjectionType' => 'ALL'
)
),
array(
'IndexName' => 'UserIdIndex',
'ProvisionedThroughput' => array (
'ReadCapacityUnits' => 5,
'WriteCapacityUnits' => 5
),
'KeySchema' => array(
array(
'AttributeName' => 'user_id',
'KeyType' => 'HASH'
),
),
'Projection' => array(
'ProjectionType' => 'ALL'
)
)
),
'ProvisionedThroughput' => array(
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 20
)
));
Following is my query to update that table.
$result = $dynamodbClient->query(array(
'TableName' => 'feed',
'KeyConditionExpression' => 'feed_guid = :v_fid AND status_id = :v_sid ',
'ExpressionAttributeValues' => array(
':v_fid' => array('S' => '71a27f0547cd5456d9ee7c181b6cb2f8'),
':v_sid' => array('N' => 1)
),
'ConsistentRead' => false
));
As mentioned, the attribute included in "KeyConditionExpression" should be your hash key only, matching your base table schema (in this case 'feed_guid'). If you want to query on both 'feed_guid' and 'status_id', you need to create the table with hash and range key and specify 'status_id' as your range key.
Global secondary indexes are completely separate from the base table, so in this case you can query the indexes separately (use 'status_id' in key condition when querying StatusIndex and use 'user_id' in key condition when querying UserIdIndex).
Please find more details on querying global secondary indexes here
Another option would be to use a FilterExpression in addition to the KeyConditionExpression. As Daniela mentioned KeyConditionExpression should contain only columns in the hash key. But any un-indexed columns can be included in the FilterExpression.
You need to have both hash_key (Partition Key) and range_key (Sort Key) provided in the KeyConditionExpression. hash_key must be exact match (=), but the range_key can use other operators like 'begins_with'
Well the question pretty much lies in the title. I've read the docs and what I can't find out is how to register the function to my ORM Configuration.
Any help here? Thanks!
Edit: Okay I've done it as Sam said, and made my own class and registered it like
'numeric_functions' => array(
'LOG10' => 'Admin\Model\Log10',
),
However it can't find the class and gives the error
Class 'Admin\Model\Log10' not found in C:\webserver\apache\htdocs\test\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php on line 3322
Any idea on why this happens?
Actually the link that #foozy gave you is all that you'd need. You simply extend your doctrine configuration array:
return array(
'doctrine' => array(
'connection' => array(
'orm_default' => array(
// Foo
)
),
'configuration' => array(
'orm_default' => array(
'numeric_functions' => array(
'MD5' => 'DoctrineExtensions\Query\Mysql\Md5'
),
'datetime_functions' => array(),
'string_functions' => array(),
'metadata_cache' => 'filesystem',
'query_cache' => 'filesystem',
'result_cache' => 'filesystem',
)
)
)
);
The error is connected to DoctrineExtensions autoload. For me both solutions from How to implement beberlei doctrine extensions in zend framework 2 (manual injection of custom functions and applying via config) worked.
Realtime updates are kicking my ass! I have my entire fb app working except for this one area and I'm just not sure what I'm doing wrong.
My app is approved using these permissions:
"scope" => "offline_access,publish_stream,read_stream,user_location,user_status",
Next, I subscribe using these settings:
$subscribe = array( 'access_token'=> substr($my_access_token,13),
'object' => 'user',
'fields' => 'name,feed',
'callback_url' => $fbconfig['callback'],
'verify_token' => $fbconfig['secret']);
Via my app I post a status update on behaf of Bill Smith (userid: 000041143) and
that appears on Bill Smith's wall just fine. Next, using a an account for John
Doe (userid: 000004842 which has NOT authorized my app) I comment on the status post
made on Bill Smith's wall and this triggers the callback but what I'm getting (see below)
is an entry telling me that John Doe's wall has changed and no mention of Bill Smiths
wall is ever made.
Here's the notification given in the callback:
updates = Array
(
[object] => user
[entry] => Array
(
[0] => Array
(
[uid] => 000004842
[id] => 000004842
[time] => 1325101631
[changed_fields] => Array
(
[0] => feed
)
)
[1] => Array
(
[uid] => 000004842
[id] => 000004842
[time] => 1325101651
[changed_fields] => Array
(
[0] => feed
)
)
)
)
As you can see, this is not a notification that a comment has been made to Bill Smiths wall but that one has been made to John Doe's... I dont get this... I must be doing SOMETHING wrong!
I had similar issues before with photo IDs turning up 'wrong', the issue occurred because I was treating it as an INT but PHP was truncating it because it was too big, I had to treat it as a string. Could this be your issue perhaps?
I have never been any good at regular expressions. I am trying to use them in building a simple site. I construct a URL just fine like /some-course/some-vtm-1, but when it tries to lookup the defined controller, it fails. Here is the route I have defined:
chapter' => array(
'type' => 'Zend_Controller_Router_Route_Regex',
'route' => '/:course/:vtm\-(\d+)',
'defaults' => array(
'module' => 'learn',
'controller' => 'chapter',
'action' => 'index'
),
'map' => array(
1 => 'course',
2 => 'vtm',
3 => 'id'
),
'reverse' => '%s/%s-%d/'
),
How should I correct this Regex so it finds the correct module/controller/action when I a link like /some-course/some-vtm-1 is clicked
Your problem is that you're trying to mix the syntax of Zend_Controller_Router_Route (named variables in the route starting with :) and Zend_Controller_Router_Route_Regex (bracketed regular expression patterns in the route). You want to drop the former and just use the regexp syntax, leaving you with something like this:
array(
'type' => 'Zend_Controller_Router_Route_Regex',
'route' => '([\w]+)/(vtm)-([\d]+)',
'defaults' => array(
'module' => 'learn',
'controller' => 'chapter',
'action' => 'index'
),
'map' => array(
1 => 'course',
2 => 'vtm',
3 => 'id'
),
'reverse' => '%s/%s-%d'
),