giwrgos

Hire Me

Experience

8,020

0 Best Reply Awards

  • Member Since 2 Years Ago
  • 14 Lessons Completed
  • 1 Favorite

12th September, 2017

giwrgos left a reply on Task Scheduling Runs Every Minute Instead Of The Time That I Set • 2 months ago

@Cronix i know but for now i have to disable them. do you know how i can do it?

giwrgos left a reply on Task Scheduling Runs Every Minute Instead Of The Time That I Set • 2 months ago

@Cronix is there a way to disable it? I have a console kernel class that creates random hours for the scheduler as cron

                foreach ($times as $time) {
                    $time = Carbon::createFromTimestamp($time);
                    $cron = $time->minute. ' '. $time->hour . ' ' . $time->day .' ' . $time->month .' * ';
                    $schedule->command('client:submit-details')->cron($cron);
                }

giwrgos started a new conversation Task Scheduling Runs Every Minute Instead Of The Time That I Set • 2 months ago

Hello,

I'm working a task scheduler on homestead on my local environment. I've set the following cron job

05 00 * * * php  /home/vagrant/Projects/Laravel/Game/artisan schedule:run

which basically needs to run once a day every midnight at 00:05, but instead it runs every minute. Can anyone tell me what I'm doing wrong?

Thanks

25th January, 2017

giwrgos started a new conversation How I Can Execute Php Artisan Vendor:publish When Installing My Package Via Composer? • 9 months ago

Hello, I wrote a package which has some assets that needs to be published in order to use it. Instead of running 5 php artisan vendor:publish commands I prefer when installing via composer to execute this commands automatically.

I used post-install-cmd and post-update-cmd but didn't worked. Here is my repository

https://github.com/giwrgos88/core-game-platform/blob/master/composer.json#L48-L65

Does anyone knows what I'm doing wrong?

24th January, 2017

giwrgos left a reply on How I Can Allow Users To Set Their Own Urls For RedirectTo And RedirectAfterLogout From Config Value • 9 months ago

instead of writing

$this->redirectAfterLogout = /backoffice/login

I'm doing it like so

$this->redirectAfterLogout = config('core_game.admin-prefix');

So the person that will use my package will be able to replace 'backoffice/login' on whatever he likes

23rd January, 2017

giwrgos started a new conversation How I Can Allow Users To Set Their Own Urls For RedirectTo And RedirectAfterLogout From Config Value • 9 months ago

Hello, I'm working on a package that is using a custom guard and I want to allow the people who will work my package to set up their own redirectTo and redirectAfterLogout paths.

I have a config file of my package that is published when you install the package on laravel. The config has default values for redirectTo and redirectAfterLogout, but when I do the following inside LoginController

    protected $redirectTo = config('core_game.login-prefix');

    protected $redirectAfterLogout = config('core_game.admin-prefix');

I get the following error message

FatalErrorException in LoginController.php line 27:
Constant expression contains invalid operations

Does anyone know how I can fix it?

22nd January, 2017

giwrgos started a new conversation How I Can Change The Guard In SessionGuard Is I'm Using Custom Guard? • 9 months ago

Hello I want to use the 'Illuminate\Contracts\Auth\Guard' in a middleware that I want to write but my package is using a custom guard where the SessionGuard is showing me the users with guard web, so all of the users who signed with the custom guard are returned as null. So how I can change the guard dynamically?

Thank you

13th January, 2017

giwrgos left a reply on Validate Form Data Array • 10 months ago

can you please provide us with your html code, the request class with the validation rules?

12th January, 2017

giwrgos left a reply on Unauthenticated Ajax Request With Custom Guard. • 10 months ago

any help?

giwrgos started a new conversation Unauthenticated With Custom Guard. • 10 months ago

Hello I'm developing a package based on laravel, which I want to separate laravel's users from my package users, therefore I used the following tutorial to add multi auth on laravel: https://metricloop.com/blog/migrating-multi-auth-to-laravel-53

I made two new guards inside config/auth.php one for web access and the other one for api access :


    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],

        'player' => [
            'driver' => 'session',
            'provider' => 'players',
        ],

        'player_api' => [
            'driver' => 'token',
            'provider' => 'players',
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],
        'players' => [
            'driver' => 'eloquent',
            'model' => George\Models\Players::class,
        ],
    ],

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'email' => 'auth.emails.password',
            'table' => 'password_resets',
            'expire' => 60,
        ],
        'players' => [
            'provider' => 'players',
            'email' => 'auth.players.emails.password',
            'table' => 'players_password_resets',
            'expire' => 60,
        ],
    ],

Then I did a Route provider inside my package which is responsible for loading the routes of my package, registering middlewares and mapping middlewares on routes

<?php

namespace George;

use Auth;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;

class RoutesServiceProvider extends ServiceProvider {

    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'George\Http\Controllers';

    /**
     * The middleware classes that are use
     *  on the project.
     *
     * @var array
     */
    protected $middleware = [
        'no_auth' => \George\Http\Middleware\Authentication::class,
        'new_player' => \George\Http\Middleware\NewPlayerRedirection::class,
        'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'player' => [
            \George\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \George\Http\Middleware\VerifyCsrfToken::class,
        ],
        'player_api' => [
            'throttle:60,1',
            'bindings',
        ],
    ];

    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = false;

    /**
     * Gets the base path of the file.
     *
     * @var string
     */
    public function getBasePath() {
        return dirname(__DIR__);
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot() {

        parent::boot();
        /**
         * Register Package Middleware
         */
        $this->registerMiddleware($this->app['router']);

        $this->applyMiddleware($this->app['router']);
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register() {
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides() {
        return [];
    }

    /**
     * Define the routes for the application.
     */
    public function map() {
        $this->mapApiRoutes();
        $this->mapWebRoutes();
        //
    }
    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes() {
        Route::group([
            'namespace' => $this->namespace,
            'middleware' => ['player'],
        ], function ($router) {
            require dirname(__DIR__) . '/routes/web.php';
        });
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes() {
        Route::group([
            'namespace' => $this->namespace,
            'middleware' => ['player_api', 'auth:player_api'],
        ], function ($router) {
            require dirname(__DIR__) . '/routes/api.php';
        });
    }
    /**
     * Register the filters.
     *
     * @param  Router $router
     */
    public function registerMiddleware($router) {
        foreach ($this->middleware as $name => $middleware) {
            $router->middleware($name, $middleware);
        }
    }

    private function applyMiddleware($route) {
        foreach ($this->middlewareGroups as $group => $middlewares) {
            $route->middlewareGroup($group, $middlewares);
        }
    }

}

When I run the command ' php artisan route:list ' I'm getting the following list (note is not the full list)

GET|HEAD | / | George::home.dashboard | \George\Http\Controllers\Home\[email protected] | player,auth:player,Closure 

GET|HEAD | api | George::home.dashboard | \George\Http\Controllers\Api\[email protected] | player_api,auth:player_api,Closure

The dashboard route with the guard player is working fine, when I do an api call from the dashboard page I'm getting the following error message '401 Unauthorized' . I changed the auth:player_api from mapApiRoutes (RoutesServiceProvider) to 'auth' for all guards or with 'auth:player' but still I was having the same error message.

Here is also my javascript code which makes the ajax call. Note I added the csrf token meta on the header of my html.

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

function ajax(type = 'POST', data, dataType = 'html', cache = false, async = true) {
    $.ajax({
        url: apiurl,
        type: type,
        data: data,
        dataType: dataType,
        cache: cache,
        async: async,
        success: function(html) {
            $("#results").append(html);
        }
    });
}

Does anyone knows what I'm doing wrong?

11th January, 2017

giwrgos left a reply on How I Can Apply Application's Route Middleware Groups On Multi Authentication L5.3? • 10 months ago

After a long research and tries I found the solution. So I did the following changes inside the RoutesServiceProvider

The boot from this

    public function boot() {
        /**
         * Include Package Routes
         */
        if (!$this->app->routesAreCached()) {
            include $this->getBasePath() . '/routes/web.php';
            include $this->getBasePath() . '/routes/api.php';
        }

        /**
         * Register Package Middleware
         */
        $this->registerMiddleware($this->app['router']);

        $this->applyMiddleware();
    }

became

    public function boot() {
        parent::boot();

        /**
         * Register Package Middleware
         */
        $this->registerMiddleware($this->app['router']);

        $this->applyMiddleware($this->app['router']);
    }

This

    protected function mapWebRoutes() {
        Route::group([
            'middleware' => ['player'],
            'namespace' => 'George',
        ], function ($router) {
            require base_path('routes/web.php');
        });
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes() {
        Route::group([
            'middleware' => ['player_api', 'auth:player_api'],
            'namespace' => 'George',
        ], function ($router) {
            require base_path('routes/api.php');
        });
    }

became

    protected function mapWebRoutes() {
        Route::group([
            'namespace' => 'George',
            'middleware' => ['player'],
        ], function ($router) {
            require dirname(__DIR__) . '/routes/web.php';
        });
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes() {
        Route::group([
            'namespace' => 'George',
            'middleware' => ['player_api', 'auth:player_api'],
        ], function ($router) {
            require dirname(__DIR__) . '/routes/api.php';
        });
    }

last the

    private function applyMiddleware() {
        $kernel = $this->app->make('Illuminate\Contracts\Http\Kernel');
        foreach ($this->middlewareGroups as $group => $middlewares) {
            foreach ($middlewares as $key => $middleware) {
                $kernel->pushMiddleware($group, $middleware);
            }
        }
    }

became

    private function applyMiddleware($route) {
        foreach ($this->middlewareGroups as $group => $middlewares) {
            $route->middlewareGroup($group, $middleware);
        }
    }

giwrgos started a new conversation How I Can Apply Application's Route Middleware Groups On Multi Authentication L5.3? • 10 months ago

Hello, I used the following tutorial (https://metricloop.com/blog/setting-up-multi-auth-in-laravel-52 - and the updated version for L5.3) and I have created a custom authentication for my package. Now I want to apply the middlewares of web and api which can be found inside the Kernel on my custom authentication inside my package.

    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,

        ],

        'api' => [
            'throttle:60,1',
        ],
    ];

So I did the following

auth.php file

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],

        'player' => [
            'driver' => 'session',
            'provider' => 'players',
        ],

        'player_api' => [
            'driver' => 'token',
            'provider' => 'players',
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],
        'players' => [
            'driver' => 'eloquent',
            'model' => George\Models\Players::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'email' => 'auth.emails.password',
            'table' => 'password_resets',
            'expire' => 60,
        ],
        'players' => [
            'provider' => 'players',
            'email' => 'auth.players.emails.password',
            'table' => 'players_password_resets',
            'expire' => 60,
        ],
    ],

And inside my package service provider I did the following

<?php

namespace George;

use Auth;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;

class RoutesServiceProvider extends ServiceProvider {

    /**
     * The middleware classes that are use
     *  on the project.
     *
     * @var array
     */
    protected $middleware = [
        'profile.restriction' => \George\Http\Middleware\Profile::class,
        'geolocation' => \AGeorge\Http\Middleware\GeoLocation::class,
        'no_auth' => \George\Http\Middleware\Authentication::class,
        'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
        'new_player' => \George\Http\Middleware\NewPlayerRedirection::class,
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'player' => [
            \George\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \George\Http\Middleware\VerifyCsrfToken::class,
        ],

        'player_api' => [
            'throttle:60,1',
        ],
    ];

    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = false;

    /**
     * Gets the base path of the file.
     *
     * @var string
     */
    public function getBasePath() {
        return dirname(__DIR__);
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot() {
        /**
         * Include Package Routes
         */
        if (!$this->app->routesAreCached()) {
            include $this->getBasePath() . '/routes/web.php';
            include $this->getBasePath() . '/routes/api.php';
        }

        /**
         * Register Package Middleware
         */
        $this->registerMiddleware($this->app['router']);

        $this->applyMiddleware();
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register() {

    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides() {
        return [];
    }

    /**
     * Define the routes for the application.
     *
     */
    public function map() {
        $this->mapApiRoutes();
        $this->mapWebRoutes();
        //
    }
    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes() {
        Route::group([
            'middleware' => ['player'],
            'namespace' => 'George',
        ], function ($router) {
            require base_path('routes/web.php');
        });
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes() {
        Route::group([
            'middleware' => ['player_api', 'auth:player_api'],
            'namespace' => 'George',
        ], function ($router) {
            require base_path('routes/api.php');
        });
    }
    /**
     * Register the filters.
     *
     * @param  Router $router
     */
    public function registerMiddleware($router) {
        foreach ($this->middleware as $name => $middleware) {
            $router->middleware($name, $middleware);
        }
    }

    private function applyMiddleware() {
        $kernel = $this->app->make('Illuminate\Contracts\Http\Kernel');
        foreach ($this->middlewareGroups as $group => $middlewares) {
            foreach ($middlewares as $key => $middleware) {
                $kernel->pushMiddleware($group, $middleware);
            }
        }
    }

}
```php

When I run the project I'm getting the following error message

ReflectionException in Container.php line 749: Class player does not exist

But If i remove the $group from the below code is working but I don't know if the middleware have been applied on my custom authentications. Can anyone help me?
``php
$kernel->pushMiddleware($group, $middleware);

5th January, 2017

giwrgos started a new conversation AliasLoader.php Line 66: Class 'Laravel\Socialite\Facades\Socialite' Not Found • 10 months ago

Hello,

I'm developing my own package based on laravel. Inside my package I have a service provider which is responsible for loading all the service providers of my package and external providers which my package needs to work. I did it like this so the user needs to add only one provider inside the config/app.php.

Here is my service provider

<?php

namespace CMS;

use CMS\Classes\Helped\BladeHelped;
use CMS\Exceptions\Handler;
use Illuminate\Support\ServiceProvider;

class CMSServiceProvider extends ServiceProvider {
    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = false;

    /**
     * The provider classes that are use on the project.
     *
     * @var array
     */
    protected $packageProviders = [
        \UrlSigner\UrlSignerServiceProvider::class,
        \CMS\CMSRepositoriesServiceProvider::class,
        \CMS\CMSRoutesServiceProvider::class,
        \CMS\CMSValidationServiceProvider::class,
    ];

    /**
     * External provider classes that are use on the project.
     *
     * @var array
     */
    protected $providers = [
        \Laravel\Socialite\SocialiteServiceProvider::class,
        \Bican\Roles\RolesServiceProvider::class,
        \Torann\GeoIP\GeoIPServiceProvider::class,
        \Bogardo\Mailgun\MailgunServiceProvider::class,
        \Collective\Html\HtmlServiceProvider::class,
    ];

    protected $facadeAliases = [
        'GeoIP' => \Torann\GeoIP\GeoIPFacade::class,
        'Form' => \Collective\Html\FormFacade::class,
        'Html' => \Collective\Html\HtmlFacade::class,
        'Socialite' => \Laravel\Socialite\Facades\Socialite::class,
    ];

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot() {

    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register() {
        /**
         * Bind Package Repositories and Interfaces
         * to Laravel's IOC container
         */
        $this->registerProviders();

        $this->registerAlias();

        $this->app->singleton(
            Illuminate\Contracts\Debug\ExceptionHandler::class,
            Handler::class
        );
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides() {
        return $this->providers;
    }

    /**
     * Bind Package Providers to Laravel's IOC container.
     */
    private function registerProviders() {
        foreach ($this->packageProviders as $key => $provider) {
            $this->app->register($provider);
        }
    }

    /**
     * Register Allias
     */
    public function registerAlias() {
        $this->app->bind('BladeHelped', function () {
            return new BladeHelped;
        });

        $loader = \Illuminate\Foundation\AliasLoader::getInstance();

        foreach ($this->facadeAliases as $alias => $facade) {
            $loader->alias($alias, $facade);
        }
        //$this->app->alias('Socialite', \Laravel\Socialite\Facades\Socialite::class);
    }

    /**
     * Define the routes for the application.
     *
     */
    public function map() {
    }

}

When I'm trying to load a page I'm getting the following message

 AliasLoader.php line 66: Class 'Laravel\Socialite\Facades\Socialite' not found

Does anyone know what I'm doing wrong?

My package is based on laravel 5.3

20th December, 2016

giwrgos started a new conversation Fatal Error: Declaration Of Paginator::render() Must Be Compatible With Paginator::render($view = NULL • 11 months ago

I'm getting the following error message when I'm trying to use paginate on Eloquent. Does anyone else had the same issue?

where is my code


if (isset($requests['paged'])) {
    $currentPage = (int) $requests['paged'];
    Paginator::currentPageResolver(function () use ($currentPage) {
    return $currentPage;
     });
}

$results = $this->model
->with('seller')
->with('buyer')
->with('author')
->with(array('property.meta' => function ($query) {
    $query->where('meta_key', 'ref-code');
}))
->orderBy('created_at', 'DESC')->paginate(Helper::get('paginate'), ['*'], 'paged');

The error

Fatal error: Declaration of Illuminate\Pagination\Paginator::render(Illuminate\Contracts\Pagination\Presenter $presenter = NULL) must be compatible with Illuminate\Contracts\Pagination\Paginator::render($view = NULL) in vendor/illuminate/pagination/Paginator.php on line 15

17th November, 2016

giwrgos left a reply on Best Practise To Call A Table From Another's Table Decorator When Using Repository Pattern • 1 year ago

Ok I found a proper solution for my questions. Basically on the constructor of my repository class I'm using the App::make to get the instance of the interface that I want. For example:

App::make(GamesInterface::class);

15th November, 2016

giwrgos started a new conversation Best Practise To Call A Table From Another's Table Decorator When Using Repository Pattern • 1 year ago

I have implemented the repository pattern on my project. I have a service provider where I'm binding the the interfaces to the app and based on the parameter of the cache I'm initialising the cache decorator or the eloquent repository. Here is an example of code


$this->app->bind(PlayerRepositoryInterface,
    function () {
        $repository = new PlayerDecorator(new PlayerModel());
        if (!config('app.cache')) {
            return $repository;
        }
        return new PlayerCacheRepository($repository);
    }
);
```php

Inside the PlayerDecorator I have a function called profile, where I'm collecting player's information based on the given parameter, where parameter can be the id of the player, email or nickname. 
```php
    public function profile($argument) {

        if (is_numeric($argument)) {
            $profile = $this->model->with('city')
                ->where('id', $argument)
                ->first();
        } else {
            $profile = $this->model->with('city')
                ->where('email', $argument . '%')
                ->orWhere('username', '=', $argument)
                ->orWhere('username', 'like', $argument . '%')
                ->first();
        }

        if (is_null($profile)) {
            return null;
        }

        if (!config('app.cache')) {
            $profile->player_value = $this->playerValue($profile->id);
        }
    }
```php
As you can see from the code I tried to add an extra attribute to the profile object with results from another table (function playerValue ). I though some solutions but I don't know which one is the best option.

First solution is to use an eloquent model and do the following
```php
PlayerValue::where('player_id', $id)->get();

This option solves the issue but is not using the repository pattern, so in case of removing Laravel Eloquent ORM that means I have to go throw my code and remove the lines of code that I'm using Laravel Eloquent ORM.

The second option is to use DB::raw method which solves the issue too and doen't affect my code if I remove the Laravel Eloquent ORM.

Is there any other better way, like using interfaces instead of raw and eloquent? For example calling Player Value interface from the PlayerDecorator?

Thank you

9th November, 2016

giwrgos left a reply on How To Change Array Index Key Of DB::select Results • 1 year ago

Ok the problem was the UNION ALL, I had to put JOIN so I changed the query from this


$streak = "SELECT win.wins FROM (
        $wins )win
        UNION ALL
        SELECT defeat.defeats FROM ($defeats
        )defeat";

to this


$streak = "SELECT * FROM ($wins)win JOIN ($defeats)defeat";

giwrgos started a new conversation How To Change Array Index Key Of DB::select Results • 1 year ago

I'm using the DB::select to make some difficult SQL queries in my system. Basically I have the following SQL queries for detecting longest wins or defeats. Here are my queries

//breaks results into run groups
        $SQL = "
        SELECT challenge_date, result,
            (
                SELECT COUNT(*) FROM challenges_results c
                WHERE c.team_id = '$teamID'
                AND c.result <> 'D'
                AND c.result <> ch.result
                AND c.challenge_date <= ch.challenge_date

            ) as RunGroup
            FROM challenges_results ch WHERE ch.team_id = '$teamID'";

        //determine how many games in each run
        $SQL2 = "SELECT result,
            MIN(challenge_date) as StartDate,
            MAX(challenge_date) as EndDate,
            COUNT(*) as Games
            FROM ($SQL) A
            GROUP BY result, RunGroup
            ORDER BY Min(challenge_date)";

        $wins = "SELECT a.Games as wins FROM ($SQL2) a WHERE a.result ='W' ORDER BY a.Games LIMIT 1";
        $defeats = "SELECT b.Games as defeats FROM ($SQL2) b WHERE b.result ='L' ORDER BY b.Games LIMIT 1";
        $streak = "SELECT win.wins FROM (
        $wins )win
        UNION ALL
        SELECT defeat.defeats FROM ($defeats
        )defeat";
        $streaks = DB::select($streak);

The $streaks returns an array of size two which contains the wins and the defeats of the given team. The issue is that both results are on a different position in the array the one is on position 0 and the other one on the position 1 and both have index key wins instead of wins and defeat. How I can change the second key which is for defeats value from win to defeat?

4th November, 2016

giwrgos left a reply on Multi Auth Not Authenticating User • 1 year ago

Ok I found the issue was on my routes, I changed only the middleware auth of the dashboard route and I forgot to change the middleware auth of the edit route, that's way it wasn't working

giwrgos started a new conversation Multi Auth Not Authenticating User • 1 year ago

Hello I used the following tutorial to add multi authentication on a project that I'm working on. "https://metricloop.com/blog/migrating-multi-auth-to-laravel-53" Basically I'm building a package on laravel that will have a separate authentication from the default one that laravel is coming , the "web" and you will be able to authenticate using your social networks. So I used the " "laravel/socialite": "^2.0"" package. I tried to authenticate via facebook but it keeps redirecting me to the login page. I have added middleware 'auth:player' on the routes that my custom authentication class will be redirect me but again is not working.

But I changed the default authentication from auth.php from web to player, which is my custom authentication, is working fine. Can anyone help me?

auth.php

return [

/*
        |--------------------------------------------------------------------------
        | Authentication Defaults
        |--------------------------------------------------------------------------
        |
        | This option controls the default authentication "guard" and password
        | reset options for your application. You may change these defaults
        | as required, but they're a perfect start for most applications.
        |
*/

'defaults' => [
    'guard' => 'web',
    'passwords' => 'users',
],

/*
        |--------------------------------------------------------------------------
        | Authentication Guards
        |--------------------------------------------------------------------------
        |
        | Next, you may define every authentication guard for your application.
        | Of course, a great default configuration has been defined for you
        | here which uses session storage and the Eloquent user provider.
        |
        | All authentication drivers have a user provider. This defines how the
        | users are actually retrieved out of your database or other storage
        | mechanisms used by this application to persist your user's data.
        |
        | Supported: "session", "token"
        |
*/

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],

    'player' => [
        'driver' => 'session',
        'provider' => 'players',
    ],
],

/*
        |--------------------------------------------------------------------------
        | User Providers
        |--------------------------------------------------------------------------
        |
        | All authentication drivers have a user provider. This defines how the
        | users are actually retrieved out of your database or other storage
        | mechanisms used by this application to persist your user's data.
        |
        | If you have multiple user tables or models you may configure multiple
        | sources which represent each model / table. These sources may then
        | be assigned to any extra authentication guards you have defined.
        |
        | Supported: "database", "eloquent"
        |
*/

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],
    'players' => [
        'driver' => 'eloquent',
        'model' => Test\Models\Players::class,
    ],

    // 'users' => [
    //     'driver' => 'database',
    //     'table' => 'users',
    // ],
],

/*
        |--------------------------------------------------------------------------
        | Resetting Passwords
        |--------------------------------------------------------------------------
        |
        | Here you may set the options for resetting passwords including the view
        | that is your password reset e-mail. You may also set the name of the
        | table that maintains all of the reset tokens for your application.
        |
        | You may specify multiple password reset configurations if you have more
        | than one user table or model in the application and you want to have
        | separate password reset settings based on the specific user types.
        |
        | The expire time is the number of minutes that the reset token should be
        | considered valid. This security feature keeps tokens short-lived so
        | they have less time to be guessed. You may change this as needed.
        |
*/

'passwords' => [
    'users' => [
        'provider' => 'users',
        'email' => 'auth.emails.password',
        'table' => 'password_resets',
        'expire' => 60,
    ],
    'players' => [
        'provider' => 'players',
        'email' => 'auth.players.emails.password',
        'table' => 'players_password_resets',
        'expire' => 60,
    ],
],

];

LoginController class

namespace Test\Http\Controllers\Auth;

useTest\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Support\Facades\Auth;

class LoginController extends Controller { /* |-------------------------------------------------------------------------- | Login Controller |-------------------------------------------------------------------------- | | This controller handles authenticating users for the application and | redirecting them to your home screen. The controller uses a trait | to conveniently provide its functionality to your applications. | */ use AuthenticatesUsers;

/**
 * Where to redirect users after login.
 *
 * @var string
 */
protected $redirectTo = '/';

protected $guard = 'player';

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct() {
    $this->middleware('guest', ['except' => 'logout']);
}

public function showPasswordLoginForm() {
    return view('futsal::auth.login_password');
}

public function showLoginForm() {
    return view('futsal::auth.login');
}

protected function guard() {
    return Auth::guard('player');
}

}

Last my social auth controller

namespace Test\Http\Controllers\SocialAuth;

use Test\Classes\Authentication\SocialAccountService; use Test\Http\Controllers\Controller; use Auth; use Socialite;

class SocialAuthController extends Controller { public function redirect($provider) { return Socialite::driver($provider)->redirect(); }

public function callback(SocialAccountService $service, $provider) {
    $player = $service->createOrGetUser(Socialite::driver($provider));

    auth()->login($player);

    if (empty($player->first_name)) {
        return redirect()->route('test::player.edit', $player->id);
    }

    return redirect()->route('test::player..dashboard');
}

}

3rd November, 2016

giwrgos left a reply on Took Too Long To Respond. • 1 year ago

Ok the issue was with the host file

giwrgos started a new conversation Took Too Long To Respond. • 1 year ago

Hello everyone. Does anyone knows how I can solve the error "took too long to respond.” ? I'm using homestead on mac. I know that the server must be timing out but something is wrong with my code. I’ve checked all the files and the editor does not shows any syntax error. Is there any other way to check for errors like php command in terminal?

14th October, 2016

giwrgos left a reply on How To Use Repository In A Class • 1 year ago

Ok I think the second example of this page " http://www.php5dp.com/design-pattern-principles-for-php-program-to-an-interface-not-an-implementation/ " helped me to understand how to implement it.

Inside the doSomething I can check if the cache is enable or not . If the cache is enable I can make an instance of the cache decorator otherwise I will do an instance of the eloquent repository. Like so

$repository = new CategoryEloquentRepository(new CategoryModel); if (config('app.cache')) { $repository = new CategoryCacheDecorator($repository); }

giwrgos left a reply on How To Use Repository In A Class • 1 year ago

@clay no, but this is how I implemented the repository pattern on my project. Taking your example let's say that I have another interface called "MyInterfaceTwo", which is used for collecting some extra data from cache or model, I want to use it inside "$this->myInterface->doSomething();" without passing it as a parameter like the following code:

use MyInterface; use MyInterfaceTwo;

class MyClassA { protected $myInterface; protected $myInterfaceTwo;

public __construct(MyInterface $myInterface, MyInterfaceTwo $myInterfaceTwo)
{
    $this->myInterface = $myInterface;
    $this->myInterfaceTwo = $myInterfaceTwo;
}

public function store()
{
    $productList = $this->myInterface->getAllProducts();
    $this->myInterface->doSomething($this->myInterfaceTwo, $productList); //<---- calls doSomething method on MyClassB
}

}

Does anyone knows how I can use the myInterfaceTwo without passing it as parameter to doSomething?

13th October, 2016

giwrgos left a reply on How To Use Repository In A Class • 1 year ago

@boynet yes but that means when I will do $classB = new Bclass(); I have to pass the interface as parameter. in order to use it in the B class. If I need to initialize the interface in order to pass it to Bclass how I can do it from classA? Just writing $repository = new IRepository()?

giwrgos left a reply on How To Use Repository In A Class • 1 year ago

@tomi this is how I implemented the repository pattern. But let say that I have a class A and a class B and I initialize class B inside a function A, how I can initialise the interface that B class needs?

giwrgos started a new conversation How To Use Repository In A Class • 1 year ago

Hello, I'm using repository pattern on a system that I'm working on. I know that on the default contractor of a controller, you can set a repository as a parameter and then from there is available in all functions of that controller. If I want to use a repository on a class can I do the same or I have to somehow, initialise the repository inside inside that class? If yes how I can do it? I don't want to pass all of my repositories as parameters from the one function to another. Thank you

26th September, 2016

giwrgos left a reply on Cookie Returns Null • 1 year ago

I see, thanks then i will use the $_COOKIE in the blade

giwrgos started a new conversation Cookie Returns Null • 1 year ago

Hello, I'm trying to use cookies on my system and I need a help. On a controller I have the following code which I'm setting a cookie.

return response()->json(['steps' => $session, 'view' => $view])->withCookie(cookie()->forever('test', serialize(uniqid('test_', true))));

Using the EditThisCookie extension on chrome I can see that the laravel adds this cookie but when I'm doing dd(Cookie::ge('test')); or $reponse->cookie('test')

I'm getting a null value. Does anyone know why?

12th September, 2016

giwrgos started a new conversation Looking For Good Cache Implementation Suggestions • 1 year ago

Hi, I'm developing a project which I want to use a caching system. The most important reason of that is because of the database queries. But first let me brief you with the general idea of the project so you have a basic idea.

Basically the project has to do with challenges, where a player from the A team can challenge the player from B team on a specific date and time. Both teams have the option to choose their team's participants for that challenge. So I'm sending invitations to all of the participants where player A and B have choosen, with accept or reject option.

Now I want to make some cron jobs to check all the challenges that have been ended. My first check is to check the status of the challenge if it is still pending, which means the player B didn't reply on player's A invitation to cancel the challenge. Second to send emails to all players to review the challenge if the status is "approved".

So I thought (which I'm not sure if it is the correct way), is when player A makes the challenge to make a cache of that instance and save it on a cache list where I have all the pending challenges, or make a new query to select all the pending delete that cache list and recreate it, and use same approach with the "approved" challenges too. Then on the cron job I will use the cache files instead of making a query call to collect all the the challenges from the database which have status "pending" and "approved". Then I will make a "foreach" loop in that list to update the status in the database if it is "pending" or if it is "approved" to check which players haven't replied to the invitation to change the status and then send emails for review to players who have attended. Then after the loop finished to collect all the cancelled challenges, and make a new cache file with all the cancelled challenges and make another one from the "approved".

If anyone has a better approach please feel free to post it. Thanks

5th September, 2016

giwrgos left a reply on Call To Undefined Method Illuminate\Mail\Mailer::to() • 1 year ago

It's funny but the issue was that I was using laravel 5.2 instead of 5.3, and that feature is available on 5.3.

giwrgos left a reply on Call To Undefined Method Illuminate\Mail\Mailer::to() • 1 year ago

Taylor has this use Illuminate\Support\Facades\Mail;

if you see the video on 49:00

https://streamacon.com/video/laracon-us/taylor-otwell-laravel-53-overview

giwrgos started a new conversation Call To Undefined Method Illuminate\Mail\Mailer::to() • 1 year ago

I did a class to send invitations using the queue method. The class I'm initializing the class from the controller

    $invitation = new SendChallangeInvitation($model, $this->teamRepository);
    $invitation = $invitation->invite();

I did the same code that this example says https://laravel.com/docs/5.3/mail#sending-mail but I'm getting the error message " Call to undefined method Illuminate\Mail\Mailer::to()"

This is the class that I'm using

use Illuminate\Support\Facades\Mail;

and this is my code

        foreach ($players as $key => $player) {
            $invitation = Invitations::create(['player_id' => $player->player_id, 'status' => 'pending']);
            $urlSigner = UrlSigner::sign(URL::route('invitation.form'),
                Carbon::now(config('constants.timezone'))->addHours(24),
                ['invitation_id' => $invitation->id, 'challange_id' => $this->model->id]
            );

            Mail::to($player->player->email)
                ->queue(new ChallangeInvitation($player->player, $urlSigner));
        }

I'm doing something wrong?

2nd September, 2016

giwrgos started a new conversation How I Can Use Existing Repositories Of A Package To Package 's B Middleware • 1 year ago

Hello I'm developing two packages. On package A I used the repository pattern which I'm registering the repositories in Package 's A service provider. Now I did another package which is used in the first package. The role of the second package is to creates URLs with a limited lifetime. So I did a middleware which I will do some validations to check for example if the token is valid and some other more complicated checks. What I want to do is to use my existing repositories for queries instead of writing news. Does anyone know how I can use my existing repositories inside my middleware class? thank you

giwrgos left a reply on Repository, Model Or Service? • 1 year ago

If the generation of the text doesn't affect the submission form then you can use queue jobs where you can create a separated class that get this data, which by the way you can pass them after you saved them, without making a new query. Then you can do your caclulations on background affecting and to this calculations on the background.

https://laravel.com/docs/5.3/queues

Hope it helps

1st September, 2016

giwrgos left a reply on Library For Creating Secure Urls With A Limited Lifetime • 1 year ago

@Slaff you can do it without cron jobs as well, with the use of middleware

31st August, 2016

giwrgos started a new conversation Library For Creating Secure Urls With A Limited Lifetime • 1 year ago

Hello I'm looking a library for creating secure (for example using token) urls with a limited lifetime, so that when someone tries to access a link that has been expired or a link that he already visited to throw 404 page. I found the following library https://github.com/spatie/laravel-url-signer but I'm also looking for any alternative libraries. Thank you

giwrgos left a reply on Method [validateTimeFormat] Does Not Exist. • 1 year ago

Ok the problem was on the Core Service provider which was responsible to load the Validation Service Provider but it wasn't

giwrgos left a reply on Method [validate] Does Not Exist • 1 year ago

Ok the problem was on the Core Service provider which was responsible to load the Validation Service Provider but it wasn't

giwrgos started a new conversation Method [validateTimeFormat] Does Not Exist. • 1 year ago

I'm trying to add new validation methods on Laravel's validation. So I did a Service Provider which on the boot function I did the following

    $this->app->validator->resolver(function ($translator, $data, $rules, $messages = array(), $customAttributes = array()) {

        // We create our own validation class here
        return new CustomValidation($translator, $data, $rules, $messages, $customAttributes);
    });

Then I did the following class

4th August, 2016

giwrgos started a new conversation Load Handle Exceptions On My Own Package • 1 year ago

I want to make a Handler class similar to the Handler that laravel has inside the Exceptions for my package. Which is the correct way to load it with the package? Can I use bind or singleton for this? Here is the class of handling, I just want it to handle errors like 404 or 500

27th July, 2016

giwrgos started a new conversation My Package Provider Was Not Found • 1 year ago

Hello, I'm trying to make a package for a custom project. My package contains a composer.json file and src folder on the root directory of my package. Here is my composer: http://pastebin.com/9fqy85q5 and this is my provider: http://pastebin.com/zKzwUrXi When I add the service provider like this on my config/app.php provider "Test\Core\Providers\CoreServiceProvider::class,", I get error message that doesn't exist if i do composer update or try to open the page. Does anyone know what I'm doing wrong?

7th July, 2016

giwrgos left a reply on Can't Run Composer Command Because Of An Error • 1 year ago

@martinbean It's true, you gave me suggestions to try which all was not solving my issue. At the end using this post "http://stackoverflow.com/questions/32312693/laravel-5-php-artisan-syntax-error" I found where my problem was

giwrgos left a reply on Can't Run Composer Command Because Of An Error • 1 year ago

thanks all for the help. I found the issue. i had an error on a controller

giwrgos left a reply on Can't Run Composer Command Because Of An Error • 1 year ago

@jlrdw i have posted my composer

giwrgos left a reply on Can't Run Composer Command Because Of An Error • 1 year ago

@jlrdw cache didn't work. @bart permissions are fine. @martinbean i saw the error but i don't know from where is coming. here is a trace

Exception trace: () at phar:///opt/sp/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:226 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///opt/sp/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:95 Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar:///opt/sp/bin/composer.phar/src/Composer/Installer.php:296 Composer\Installer->run() at phar:///opt/sp/bin/composer.phar/src/Composer/Command/UpdateCommand.php:172 Composer\Command\UpdateCommand->execute() at phar:///opt/sp/bin/composer.phar/vendor/symfony/console/Command/Command.php:259 Symfony\Component\Console\Command\Command->run() at phar:///opt/sp/bin/composer.phar/vendor/symfony/console/Application.php:844 Symfony\Component\Console\Application->doRunCommand() at phar:///opt/sp/bin/composer.phar/vendor/symfony/console/Application.php:192 Symfony\Component\Console\Application->doRun() at phar:///opt/sp/bin/composer.phar/src/Composer/Console/Application.php:227 Composer\Console\Application->doRun() at phar:///opt/sp/bin/composer.phar/vendor/symfony/console/Application.php:123 Symfony\Component\Console\Application->run() at phar:///opt/sp/bin/composer.phar/src/Composer/Console/Application.php:102 Composer\Console\Application->run() at phar:///opt/sp/bin/composer.phar/bin/composer:43 require() at /opt/sp/bin/composer.phar:24

update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] []...

[email protected]:/srv/users/serverpilot/apps/testing#

giwrgos started a new conversation Can't Run Composer Command Because Of An Error • 1 year ago

Hello I'm running the composer install command and I'm getting the following error message

Writing lock file Generating autoload files

Illuminate\Foundation\ComposerScripts::postUpdate php artisan optimize

[Symfony\Component\Debug\Exception\FatalThrowableError] Parse error: syntax error, unexpected ';', expecting ',' or ')'

Script php artisan optimize handling the post-update-cmd event returned with an error

[RuntimeException] Error Output:

here is my composer

{ "name": "test/test", "description": "Test", "keywords": ["framework", "laravel"], "license": "MIT", "type": "project", "require": { "php": ">=5.5.9", "laravel/framework": "5.2.", "spatie/laravel-analytics": "^1.4", "laravelcollective/html": "^5.2", "bican/roles": "2.1.", "jenssegers/agent": "^2.3", "laracasts/utilities": "~2.0", "maatwebsite/excel": "~2.1.0", "nesbot/carbon": "^1.21", "rachidlaasri/laravel-installer": "^1.4" }, "require-dev": { "fzaninotto/faker": "~1.4", "mockery/mockery": "0.9.", "phpunit/phpunit": "~4.0", "symfony/css-selector": "2.8.|3.0.", "symfony/dom-crawler": "2.8.|3.0.*" }, "autoload": { "classmap": [ "database" ], "psr-4": { "Test\": "app/" } }, "autoload-dev": { "classmap": [ "tests/TestCase.php" ] }, "scripts": { "post-root-package-install": [ "php -r "copy('.env.example', '.env');"" ], "post-create-project-cmd": [ "php artisan key:generate" ], "post-install-cmd": [ "Illuminate\Foundation\ComposerScripts::postInstall", "php artisan optimize" ], "post-update-cmd": [ "Illuminate\Foundation\ComposerScripts::postUpdate", "php artisan optimize" ] }, "config": { "preferred-install": "dist" } }

Can anyone help me?

4th July, 2016

giwrgos left a reply on How To Add Indexing On Loop (Blade) With Pagination • 1 year ago

Thanks @willvincent, your solution solved my problem

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.