dimanche 1 septembre 2019

Laravel Redis key prefix not working as intended

I have a rather weird problem with Laravel lately that when I am storing something in Redis and then get the keys and try to retrieve the values using that key, I get null. However when I manually remove the prefix from the key via substring or something similar, I am able to retrieve the data. Example:

Redis::hmset('users:'.$db_user->id,$db_user->toArray());

Then I do the following to retrieve the stored keys:

foreach(Redis::redis->keys('users:*') as $key){
        Redis::redis->hgetall($key); //returns null
        Redis::hgetall(substr($key,18))); //returns the stored values
    }

A key would come out as:

redisser_database_users:78

Which is to be expected given the prefix settings in Laravel. Now I wonder if this behaviour is intended or not. If it is, it doesn't make a whole lot of sense to me.

Can this be fixed somehow so I can use the keys directly without manually cutting off the prefix?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2HD1a1g
via IFTTT

Laravel: Reverse WHERE NOT IN - exclude any parent table that has children of id=XXX

Scenario is this: Need to get all sites which don't have licensee ID = XXX.

  $data = DB::select("SELECT  * FROM sites AS s
              WHERE status = 'Existing Site' AND
              $sharerId NOT IN (SELECT organisation_id
                      FROM licensees AS l
                        WHERE site_id = s.id)
                    order by siteName;") ;

This code does that fine.

But I get an array, which I can't filter on later, just in case the user wants to search for site name YYY.

$sharerId has the ID to exclude from the sites.

 $data = $this->select($select)
 ->where('status', 'Existing Site')
 ->whereNotIn($sharerId,
 Licensee::where('site_id', DB::raw('sites.id'))
 )->get() ;

Tried this, but I really didn't expect it to work, and it didn't :-P



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/34hQYVm
via IFTTT

Visitor Tracking For A Decoupled Laravel Rest API

We are working on a suite of multi-tenant apps that use a single REST API backend.

This REST API feeds data to all these different apps from a single database and we got the single sign on figured out as well where the single API handles issuing of tokens, refreshing of tokens etc.

All the frontend apps are vue based and we're currently trying to find a way to have link, visitor tracking for the frontend apps and have that data stored in the centralized database.

I have created a single web route in the backend, that basically tracks anyone who opened that url and is opening that url in the background as an image on all the frontend apps so that we can track it and have it saved

But this seems like a really hacky way and I was wondering if there's a better way to deal with visitor tracking for the purely API based projects than this?

Any help or pointers would really help :)



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ZEXYYR
via IFTTT

Laravel 5.8: How to exclude a page from default redirection when user is not authorized

In Laravel all pages are redirected to login page for unauthorized users (Guest). How to exclude a page (e.q. Index) from this redirection? I tried changing file below and set return route('login') to return route('index') but it makes infinite index call and Firefox says:

The page isn't redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

File:

Middleware/Authenticate.php

protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            return route('login');
        }
    }



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2MOAxub
via IFTTT

laravel phpUnit phpStorm docker connection

i have set up of php/mysql/apache/laravel stack through the docker without problems, everything up and running. i have set up docker in phpStorm as well- everything works good.

now im trying to set up phpUnit in phpStorm, which i never set up before especially with the docker container so error could be very simple i just cant understand what is wrong and where :(

when i run any test (which is working well for sure) i'm receiving this kind of errors:

enter image description here

it looks like smth is wrong with the DB connection settings but i cant understand what is wrong because the only change from what main application uses is database name and database with this name exists

here is how i set up phpUnit in phpStorm, as you can see the path to the phpunit.xml is set up and everything look good enter image description here

here is .env

DB_CONNECTION=mysql
DB_HOST=xcard_db
DB_PORT=3306
DB_DATABASE=xcard
DB_TEST_DATABASE=xcard_test
DB_USERNAME=root
DB_PASSWORD=jackjack

this is laravel config/database.php, as you can see i use DB_TEST_DATABASE and this is the only difference (i have cleaned some unnecessary settings, errors are the same with or without them)

        'xcard_test' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_TEST_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
        ],

        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

and here is my phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>

        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <server name="APP_ENV" value="testing"/>
        <server name="BCRYPT_ROUNDS" value="4"/>
        <server name="CACHE_DRIVER" value="array"/>
        <server name="MAIL_DRIVER" value="array"/>
        <server name="QUEUE_CONNECTION" value="sync"/>
        <server name="SESSION_DRIVER" value="array"/>
        <server name="DB_CONNECTION" value="xcard_test"/>
        <server name="LOG_CHANNEL" value="test"/>
    </php>
</phpunit>



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NICEPW
via IFTTT

Laravel: BroadcastException 404 NOT FOUND using Pusher?

I have been stuck on this for like 19 hours. What I was trying was to get Broadcast events working on Laravel 5.5 with pusher...

However, when i set things to pusher I am getting a 404 File not found exception:

Illuminate \ Broadcasting \ BroadcastException 404 NOT FOUND

I composer required pusher 3.0

`composer require pusher/pusher-php-server "~3.0"

.env file

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:pwCPVeM+Ppv0SrYVLMDcnZUqKug3MlfYpTD8IqwA+Ug=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=bsproject
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

PUSHER_APP_ID=853485
PUSHER_APP_KEY=0261946d733c71cdd9dd
PUSHER_APP_SECRET=b98724e99d17facb3a33
PUSHER_APP_CLUSTER=AP2

ANALYTICS_VIEW_ID=

config\ broadcasting.php

<?php

return [

    'default' => env('BROADCAST_DRIVER', 'null'),

    'connections' => [

        'pusher' => [
            'driver' => 'pusher',
            'key' => env('0261946d733c71cdd9dd'),
            'secret' => env('b98724e99d17facb3a33'),
            'app_id' => env('853485'),
            'options' => [
                'cluster' => 'ap2',
                'encrypted' => false,
            ],
        ],

        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
        ],

        'log' => [
            'driver' => 'log',
        ],

        'null' => [
            'driver' => 'null',
        ],

    ],

];



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/30OMR0T
via IFTTT

Laravel Single Action Controller doesn't work

I created CustomerController in Http, later, I fixed-route get customers, but getting an error in a single action Controller.

I tried to show off CustomerController view for displaying customers logged in page

coding error image

Here is an error message

Use of undefined constant view - assumed 'view' (this will throw an Error in a future version of PHP)



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ZsbR1B
via IFTTT