iamamirsalehi

Member Since 1 Year Ago

Tehran

Experience Points
4,710
Total
Experience

290 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
4
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 1
4,710 XP
May
08
1 day ago
Activity icon

Started a new Conversation Google Authenticator Does Not Work In API

Hi there, I have the code below:

 public function enable2fa(EnableRequest $request)
    {
        $validated_data = $request->validated();

        $user = auth()->user();
        $google2fa = (new \PragmaRX\Google2FAQRCode\Google2FA());

        $secret = $validated_data['secret'];

        $valid = $google2fa->verifyKey($user->passwordSecurity->google2fa_secret, $secret);

        if (!$valid) {
            Log::action([
                'type' => 'warning',
                'user_id' => $user->id,
                'method_address' => 'App\Http\Controllers\API\V1\GoogleAuthenticator\GoogleAuthenticatorController::enable2fa',
                'action' => 'the entered validation number are wrong and google authenticator is not enabled',
            ]);

            return Response::send(401, 'wrong code');
        }

        $this->passwordSecurityRepository->updateBy([
            'user_id' => $user->id,
        ], [
            'google2fa_enable' => 1,
        ]);

        Log::action([
            'type' => 'info',
            'user_id' => $user->id,
            'method_address' => 'App\Http\Controllers\API\V1\GoogleAuthenticator\GoogleAuthenticatorController::enable2fa',
            'action' => 'google authenticator is now enabled for the user',
        ]);

        return Response::send(200, 'google authenticator is enabled');
    }

the code above works when I send a request from the form but when I want to use it in API it actually does not work and does verify the sent secret code

I'm using the "pragmarx/google2fa-laravel": "^1.4", package

May
05
4 days ago
Activity icon

Replied to BaconQrCode\Exception\RuntimeException You Need To Install The Imagick Extension To Use This Back End

@s4muel thanks for the reply, I've checked the issue but it couldn't help me

Activity icon

Replied to BaconQrCode\Exception\RuntimeException You Need To Install The Imagick Extension To Use This Back End

@tykus thanks for the reply, I entered the first command and what I got was imagick but when I used the route I couldn't find imagick in the phpinfo

Activity icon

Started a new Conversation BaconQrCode\Exception\RuntimeException You Need To Install The Imagick Extension To Use This Back End

Hi there,

I'm using composer require pragmarx/google2fa-laravel and composer require bacon/bacon-qr-code for google authenticator but I can not use them because I get the error below

BaconQrCode\Exception\RuntimeException
You need to install the Imagick extension to use this back end

I've installed Imagick but I really don't know what's going on! if you have any solution or any alternative package I'll appreciate it. thanks in advance.

Apr
22
2 weeks ago
Activity icon

Replied to The Best Tool For Logging

@silencebringer thanks for the replay, what about elasticsearch logging?

Apr
21
2 weeks ago
Activity icon

Started a new Conversation The Best Tool For Logging

Hello there, what's the best tool to log most actions in Laravel project? (kinda big project) thanks in advance

Activity icon

Replied to What Is The Best Design Pattern To Implement A Shopping Bag?

Should I use decorator pattern?

Activity icon

Started a new Conversation What Is The Best Design Pattern To Implement A Shopping Bag?

Hi there, What is the best design pattern to implement a shopping bag?

Apr
11
4 weeks ago
Activity icon

Started a new Conversation RedisException Php_network_getaddresses: Getaddrinfo Failed: Temporary Failure In Name Resolution

Hi there, Whenever I want to send SMS as I use queue I get the error below

RedisException
php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

I use Redis, I have installed the package and the Redis on my ubuntu, I don't know what the problem is. thanks in advance

Activity icon

Replied to First Or Create Problem

@chaudigv thanks for the reply, Does DB has firstOrCreate?

Activity icon

Started a new Conversation First Or Create Problem

HI there, in the code below when I want to firstOrCreate all the data, it actually gives me an error and does not let me do that but when I pass singly the data it works, What can I do to firstOrCreate all the data? thanks in advance

$data = [
            ['name' => 'kyc-user-information',                    'guard_name' => 'admin', 'persian_name' => 'احراز هویت بخش اطلاعات کاربران'],
            ['name' => 'kyc-user-bank-account',                   'guard_name' => 'admin', 'persian_name' => 'احراز هویت بخش حساب بانکی'],
            ['name' => 'kyc-card-id',                             'guard_name' => 'admin', 'persian_name' => 'احراز هویت بخش کارت آیدی کاربر'],
            ['name' => 'manual-prices',                           'guard_name' => 'admin', 'persian_name' => 'تنظیم قیمت به صورت دستی'],
            ['name' => 'setting-management',                      'guard_name' => 'admin', 'persian_name' => 'مدیریت تنظیمات'],
            ['name' => 'send-notification',                       'guard_name' => 'admin', 'persian_name' => 'ارسال نوتیفیکشن به کاربران'],
            ['name' => 'registered-tether-client-management',     'guard_name' => 'admin', 'persian_name' => 'مدیریت مشتری های ثبت شده برای خرید تتر'],
            ['name' => 'contact-us-management',                   'guard_name' => 'admin', 'persian_name' => 'مدیریت اطلاعات ارسال شده از قسمت تماس با ما'],
            ['name' => 'kyc-management',                          'guard_name' => 'admin', 'persian_name' => 'مدیریت kyc کاربران'],
            ['name' => 'user-management',                         'guard_name' => 'admin', 'persian_name' => 'مدیریت کاربران'],
            ['name' => 'role-management',                         'guard_name' => 'admin', 'persian_name' => 'مدیریت نقش کاربران'],
            ['name' => 'permission-management',                   'guard_name' => 'admin', 'persian_name' => 'مدیریت سطح دسترسی ها'],
            ['name' => 'notification-message-management',         'guard_name' => 'admin', 'persian_name' => 'مدیریت پیام های آماده نوتیفیکشن ها'],
            ['name' => 'user-kyc-section',                        'guard_name' => 'web',  'persian_name' => 'کاربر بتواند kyc بکند'],
        ];

        $permission_repository = resolve(PermissionRepositoryInterface::class);

        $permission_repository->firstOrCreate($data);

Am I supposed to just pass a single array?

Apr
10
4 weeks ago
Activity icon

Replied to Decimal Lenght

@rodrigo.pedra thanks for the reply, if I pass the third parameter Would have an unsigned decimal with that lenght?

Activity icon

Replied to Decimal Lenght

@bugsysha thanks for the replay, does $table->decimal accept negative numbers with that length?

Activity icon

Started a new Conversation Decimal Lenght

Hi there, I wanna have a decimal field in my migration that has 000000000.000000000 length, I'm using MySQL and I tried to float, decimal, double but every time I got an out of range error. thanks in advance

Apr
07
1 month ago
Activity icon

Started a new Conversation How Can I Use Eloquent Resource For My Package

Hi there, How can I use eloquent resource for my package?

Activity icon

Started a new Conversation How To Use User Factory In Package Development Testing

Hi there, I'm developing a package and in testing it I need to create a user with the factory but every time I try this It gives an error like User model not found should I create a User model separately for my package? Is there any solution for it?

1) Iamamirsalehi\LaravelBalance\tests\Unit\Services\Balance\DepositTest::test_if_user_can_deposit
Error: Class "App\Models\User" not found
Apr
06
1 month ago
Activity icon

Replied to PDOException: SQLSTATE[HY000] [1045] Access Denied For User 'forge'@'localhost' (using Password: NO)

@tray2 thank you, I can connect to the DB now but what is this error, I already have my tables in the database

PDOException: There is no active transaction

Activity icon

Started a new Conversation PDOException: SQLSTATE[HY000] [1045] Access Denied For User 'forge'@'localhost' (using Password: NO)

Hi there, I have the error below:

PDOException: SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)

when I want to run my tests, This is my phpunit.xml content

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  bootstrap="vendor/autoload.php"
  backupGlobals="false"
  backupStaticAttributes="false"
  colors="true"
  verbose="true"
  convertErrorsToExceptions="true"
  convertNoticesToExceptions="true"
  convertWarningsToExceptions="true"
  processIsolation="false"
  stopOnFailure="false"
  xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
  <coverage>
    <include>
      <directory suffix=".php">src/</directory>
    </include>
  </coverage>
  <testsuites>
    <testsuite name="Unit">
      <directory suffix="Test.php">./tests/Unit</directory>
    </testsuite>
    <testsuite name="Feature">
      <directory suffix="Test.php">./tests/Feature</directory>
    </testsuite>
  </testsuites>
  <php>
    <php>
      <env name="APP_ENV" value="testing"/>
      <env name="DB_CONNECTION" value="sqlite"/>
      <env name="DB_DATABASE" value=":memory:"/>
      <env name="CACHE_DRIVER" value="array"/>
      <env name="SESSION_DRIVER" value="array"/>
      <env name="QUEUE_DRIVER" value="sync"/>
      <env name="MAIL_DRIVER" value="array"/>
    </php>
  </php>
</phpunit>
Activity icon

Replied to PDOException: SQLSTATE[HY000]: General Error: 1 No Such Table: Balances

@sr57 the question is should I have another db for my package testing

phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  bootstrap="vendor/autoload.php"
  backupGlobals="false"
  backupStaticAttributes="false"
  colors="true"
  verbose="true"
  convertErrorsToExceptions="true"
  convertNoticesToExceptions="true"
  convertWarningsToExceptions="true"
  processIsolation="false"
  stopOnFailure="false"
  xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
  <coverage>
    <include>
      <directory suffix=".php">src/</directory>
    </include>
  </coverage>
  <testsuites>
    <testsuite name="Unit">
      <directory suffix="Test.php">./tests/Unit</directory>
    </testsuite>
    <testsuite name="Feature">
      <directory suffix="Test.php">./tests/Feature</directory>
    </testsuite>
  </testsuites>
  <php>
    <env name="DB_CONNECTION" value="testing"/>
    <env name="APP_KEY" value="base64:VGUxhj/9CxDVIzTbGQHjImtybPfn7MlDa6VqIFCm9yU="/>
  </php>
</phpunit>

Activity icon

Started a new Conversation PDOException: SQLSTATE[HY000]: General Error: 1 No Such Table: Balances

Hi there, I'm developing a package and I wanna insert data into the database but it tells me that the table does not exist, How can I have my table for my package testing

Mar
31
1 month ago
Activity icon

Replied to Spatie\Permission\Exceptions\RoleDoesNotExist There Is No Role Named `super_admin`.

@silencebringer thanks for the reply but I still get the error

$adminRepository = resolve(AdminRepositoryInterface::class);

        $created_admin = $adminRepository->store([
            'mobile'          => '09392126508',
            'password'        => Hash::make('password123456'),
            'mobile_verified' => 1
        ]);

        $created_admin->assignRole('super_admin', 'admin');

Activity icon

Replied to Spatie\Permission\Exceptions\RoleDoesNotExist There Is No Role Named `super_admin`.

@martinbean sorry I just hitted the best answer, I'm sure i have the role but i still get the error

Activity icon

Started a new Conversation Spatie\Permission\Exceptions\RoleDoesNotExist There Is No Role Named `super_admin`.

Hi there, I don't what the problem is, I've added the guard to my model and I assign a role with the guard but still get this error:

Spatie\Permission\Exceptions\RoleDoesNotExist
There is no role named `super_admin`.

my code:

        $adminRepository = resolve(AdminRepositoryInterface::class);

        $created_admin = $adminRepository->store([
            'mobile' => '09392126508',
            'password' => Hash::make('password123465'),
            'mobile_verified' => 1
        ]);

        $created_admin->assignRole('admin', 'admin');
Activity icon

Replied to Always Returns Null

@tykus Hi again, What's the $limits variable, What's the value?

Mar
30
1 month ago
Activity icon

Replied to Always Returns Null

@tykus I wanna achieve the last price of the day for a duration like a week

Activity icon

Replied to Always Returns Null

@tykus I really suspect to whereBetwen query

Activity icon

Replied to Always Returns Null

@tykus I changed that but I got null again

Activity icon

Replied to Always Returns Null

@tykus this is actually the result that I got

array:2 [▼
  0 => array:2 [▼
    "x" => 0
    "y" => null
  ]
  1 => array:2 [▼
    "x" => 0
    "y" => null
  ]
]

I thought maybe the timestamp between created_at is incorrect but I've checked the timestamps and they are correct! I'm confused

Activity icon

Replied to Always Returns Null

@tykus if you mean:

$prices[] = [
                'x' => (int) $current_price?->trade_buy_sale,
                'y' => $current_price?->created_at,
            ];

this is a temporary code

Activity icon

Started a new Conversation Always Returns Null

Hi there, I don't know why but the below code always returns null to me, the timestamp that the Carbon is generating is correct


 public function getTheLastUSDTPriceForTheLastWeek(\Carbon\Carbon $start, \Carbon\Carbon $end)
    {
        $query = $this->model::query();

        $different_between_date = $start->diffInDays($end);

        $prices = [];

        foreach (range(0, $different_between_date) as $day){

            $start_timestamp = Carbon::parse($end->subdays($different_between_date - $day)->startOfDay())->timestamp;
            
            $end_timestamp   = Carbon::parse($end->subdays($different_between_date - ($day + 1))->endOfDay())->timestamp;
            
            $query->whereBetween('created_at', [$start_timestamp, $end_timestamp]);

            $query->where('trade_type', self::TYPES['USDT']);

            $current_price = $query->max('created_at');

            $prices[] = [
                'x' => (int) $current_price?->trade_buy_sale,
                'y' => $current_price?->created_at,
            ];
        }
                
        return $prices;
    }

my table in database:

+-----+------------+----------------+-----------------+------------+
| id  | trade_type | trade_buy_sale | trade_sell_sale | created_at |
+-----+------------+----------------+-----------------+------------+
| 242 |          1 | 23232          | 32434           |  234234234 |
| 243 |          2 | 23232          | 32434           |  234234234 |
| 244 |          3 | 23232          | 32434           |  234234234 |
| 245 |          2 | 26343          | 26343           | 1616825328 |
| 246 |          2 | 26217          | 26207           | 1616849958 |
| 247 |          2 | 26154          | 26154           | 1616850492 |
| 248 |          2 | 26335          | 26335           | 1617026254 |
| 249 |          2 | 26340          | 26340           | 1617026421 |
| 250 |          2 | 26314          | 26314           | 1617090558 |
| 251 |          1 | 25515          | 25515           | 1617090562 |
| 252 |          1 | 25510          | 25510           | 1617093466 |
| 253 |          1 | 25508          | 25508           | 1617096145 |
| 254 |          2 | 26139          | 26139           | 1617096147 |
+-----+------------+----------------+-----------------+------------+


Activity icon

Replied to Object Of Class Illuminate\Database\Eloquent\Builder Could Not Be Converted To String

@tykus yes, I've just seen the return, and these two work correctly

Activity icon

Replied to Object Of Class Illuminate\Database\Eloquent\Builder Could Not Be Converted To String

@tykus Thanks, my result is always null, Could you please check this again?

   public function getTheLastUSDTPriceForTheLastWeek(\Carbon\Carbon $start, \Carbon\Carbon $end)
    {
        $query = $this->model::query();

        $different_between_date = $start->diffInDays($end);

        $prices = [];

        foreach (range(0, $different_between_date) as $day){

            $query->whereBetween('created_at', [
                Carbon::parse($end->subdays($different_between_date - $day)->startOfDay())->timestamp,
                Carbon::parse($end->subdays($different_between_date - ($day + 1))->endOfDay())->timestamp
            ]
            );

            $query->where('trade_type', self::TYPES['USDT']);

            $current_price = $query->max('created_at');

            $prices[] = [
                'x' => (int) $current_price?->trade_buy_sale,
                'y' => $current_price?->created_at,
            ];
        }
        
        return $prices;
    }

Activity icon

Started a new Conversation Object Of Class Illuminate\Database\Eloquent\Builder Could Not Be Converted To String

Hey there, What's the problem of the below query

    public function getTheLastUSDTPriceForTheLastWeek(\Carbon\Carbon $start, \Carbon\Carbon $end)
    {
        $query = $this->model::query();

        $different_between_date = $start->diffInDays($end);

        $prices = [];

        foreach (range(0, $different_between_date) as $day){

            $query->where('created_at', $query->whereBetween('created_at', [
                    Carbon::parse($end->subdays($different_between_date - $day)->startOfDay())->timestamp,
                    Carbon::parse($end->subdays($different_between_date - ($day + 1))->endOfDay())->timestamp
                ])
            );

            $query->where('trade_type', self::TYPES['USDT']);

            $current_price = $query->latest()->first();

            $prices[] = [
                'x' => (int) $current_price->trade_buy_sale,
                'y' => $current_price->created_at,
            ];
        }
        
        return $prices;
    }

Mar
27
1 month ago
Activity icon

Started a new Conversation Is It Possible To Have Nuxt And Laravel In The Same Folder?

Is it possible to have Nuxt and Laravel in the same folder to work together?

Activity icon

Started a new Conversation How To Add An Nuxt Project To Laravel

Hello there, I have a Nuxt project and I wanna add it to my Laravel existing project, What should I do for that? thanks in advance

Mar
23
1 month ago
Activity icon

Started a new Conversation Adding A Vue Template To A Existing Laravel Project

Hi there, I wanna add a Vue template to my existing Laravel project, How can I do that? Thanks in advance

Mar
17
1 month ago
Activity icon

Started a new Conversation Should I Have Multiple Modles For Multiple Authentication Guard?

Hi there, I wanna use multiple guards for my admins and users but is it required to have multiple models separately because I just have a users table

Mar
16
1 month ago
Activity icon

Replied to Request Class For API

@trin I got it \Illuminate\Contracts\Validation\Validator

Activity icon

Replied to Request Class For API

@trin the namespace of the Validator parameter in the method is Illuminate\Validation\Validator, right?

Activity icon

Replied to Request Class For API

@trin thank you, this solution is better

Activity icon

Started a new Conversation Request Class For API

Hi there I wanna use the request class for my API method but whenever a request is sent to my API method, it actually redirects with HTML, The question is I wanna get a response JSON from the validation class to validate my data, What should I do? thanks in advance

Mar
14
1 month ago
Activity icon

Replied to I Can't Validate My Api Request

@sergiu17 Do you think the class name should be like UserInformations instead of UserInformation?

Activity icon

Replied to I Can't Validate My Api Request

@sergiu17

+--------+-----------+-------------------------------------------------+---------------------------+------------------------------------------------------+------------+
| Domain | Method    | URI                                             | Name                      | Action                                               | Middleware |
+--------+-----------+-------------------------------------------------+---------------------------+------------------------------------------------------+------------+
|        | GET|HEAD  | api/v1/kyc/user-informations                    | user-informations.index   | App\Http\Controllers\API\KYC\[email protected]   | api        |
|        | POST      | api/v1/kyc/user-informations                    | user-informations.store   | App\Http\Controllers\API\KYC\[email protected]   | api        |
|        | GET|HEAD  | api/v1/kyc/user-informations/{user_information} | user-informations.show    | App\Http\Controllers\API\KYC\[email protected]    | api        |
|        | PUT|PATCH | api/v1/kyc/user-informations/{user_information} | user-informations.update  | App\Http\Controllers\API\KYC\[email protected]  | api        |
|        | DELETE    | api/v1/kyc/user-informations/{user_information} | user-informations.destroy | App\Http\Controllers\API\KYC\[email protected] | api        |
+--------+-----------+-------------------------------------------------+---------------------------+------------------------------------------------------+------------+


Activity icon

Replied to I Can't Validate My Api Request

@sergiu17 thanks for your answer but I got the same error

Activity icon

Replied to I Can't Validate My Api Request

@iamamirsalehi I've just changed that but unfortunately, it didn't work, I've done the cache:clear and route:cache but the result is as usual

Activity icon

Started a new Conversation I Can't Validate My Api Request

Hi there

I have the route below in my API route file


Route::prefix('v1')->group(function() {

    Route::prefix('kyc')->group(function (){
               Route::apiResource('user-informations', UserInformation::class);
    });

});

and my update method in my API controller


    public function update(UpdateRequest $request, $user_id)
    {
        $validated_data = $request->validated();

        $user = $this->userRepository->findOrFail($user_id);

        $data = [
            'user_id'               => $user->id,
            'user_first_name'       => $validated_data['first_name'],
            'user_last_name'        => $validated_data['last_name'],
            'user_sex'              => $validated_data['gender'] == 'male' ? $this->userRepository::MALE : $this->userRepository::FEMALE,
            'user_date_of_birth'    => $validated_data['date_of_birth'],
            'user_national_code'    => $validated_data['card_id'],
            'user_landline_phone'   => $validated_data['landline_numnber'],
            'user_address'          => $validated_data['address'],
        ];

        $kycService = new KYCService($data, 'UserInformation', false);

        if($kycService->perform())
            return response()->json([
                'message' => 'اطلاعات شما برای احراز هویت با موفقیت ثبت شد'
            ]);
    }

the result that I get is the error below when I try to send some information with Postman

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The PUT method is not supported for this route. Supported methods: GET, HEAD.

thanks in advance