SimonAngatia

SimonAngatia

Member Since 1 Month Ago

Experience Points
1,630
Total
Experience

3,370 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
0
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.

Level 1
1,630 XP
Sep
26
1 day ago
Activity icon

Awarded Best Reply on Errno: 150 "Foreign Key Constraint Is Incorrectly Formed

I solved it by doing this:

public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->longText('slug');
            $table->string('title');
            $table->string('img');
            $table->dropForeign(['user_id']);
            $table->boolean('published')->default(0);
            $table->timestamps();
        });
    }

The id field on the user's table is of data type unsignedBigInteger, so the same should apply on the foreign key. They have to be the same data-type.

You can also do like this:


Schema::table('posts', function (Blueprint $table) {
    $table->unsignedBigInteger('user_id');

    $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});

That's laravel 7

Activity icon

Replied to Errno: 150 "Foreign Key Constraint Is Incorrectly Formed

I solved it by doing this:

public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->longText('slug');
            $table->string('title');
            $table->string('img');
            $table->dropForeign(['user_id']);
            $table->boolean('published')->default(0);
            $table->timestamps();
        });
    }

The id field on the user's table is of data type unsignedBigInteger, so the same should apply on the foreign key. They have to be the same data-type.

You can also do like this:


Schema::table('posts', function (Blueprint $table) {
    $table->unsignedBigInteger('user_id');

    $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});

That's laravel 7

Activity icon

Started a new Conversation Errno: 150 "Foreign Key Constraint Is Incorrectly Formed

The below is my posts migration but when I run php artisan migrate:fresh I get an error SQLSTATE[HY000]: General error: 1005 Can't create tableidevs.posts (errno: 150 "Foreign key constraint is incorrectly formed What might be the problem?

public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->integer('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('strict');
            $table->longText('slug');
            $table->string('title');
            $table->string('img');
            $table->boolean('published')->default(0);
            $table->timestamps();
        });
    }
Sep
25
2 days ago
Activity icon

Replied to Model::decrement() And Model::increment() Not Working Efficiently

casino_bakiye is on users table, casino_balance on xpgtransactions table

Activity icon

Replied to Model::decrement() And Model::increment() Not Working Efficiently

What I am doing is that after the amount being saved in the database, it should increment or decrement the user balance in the user's model. Something that is working for some but not others

Activity icon

Replied to Model::decrement() And Model::increment() Not Working Efficiently

Look at this and you will see that it works for many requests but not a few. https://imgur.com/a/mFg4g3W

Activity icon

Replied to Model::decrement() And Model::increment() Not Working Efficiently

public function Debit(){
      $data = json_decode(file_get_contents('php://input'), true);
      $username = $data['Login'];
      $user = User::where('username', $username)->first();
      if(!$user){
        $rivalaoResponse = ["d"=>["ErrorCode"=>-10,"HasErrors"=>true,"Message"=>"InvalidPlayer"]];
        return response()->json($rivalaoResponse);
      }

      $userId = $user->id;
      $userBalance = $user->casino_bakiye;
      $operator = $data['OperatorId'];
      $session = $data['Session'];
      $gameId = $data['GameId'];
      $roundId = $data['RoundId'];
      $sequence = $data['Sequence'];
      $amount = $data['Amount'];
      $debitDetails =$data['DebitDetails'];
      if($sequence){
        $game = XpgTransaction::where('gameId', $gameId)
                              ->where('roundId', $roundId)
                              ->where('sequence', $sequence)
                              ->first();
        if(!$game){
          
          $trxn = new XpgTransaction;
          $trxn->user_id = $userId;
          $trxn->operatorId = $operator;
          $trxn->session = $session;
          $trxn->gameId =$gameId;
          $trxn->roundId =$roundId;
          $trxn->sequence = $sequence;
          $trxn->type = "debit";
          $trxn->debitDetails = $debitDetails;
          $trxn ->request=json_encode($data);
          $trxn->amount = $amount;
          $trxn->save();
            $updatedBalance = $user->fresh()->casino_bakiye;
            if($updatedBalance !=null){
              $rivalaoResponse = ["d"=>["Data"=>[(float)$updatedBalance],"ErrorCode"=>0,"HasErrors"=>false,"Message"=>""]];
              return response()->json($rivalaoResponse);
            } 
            $rivalaoResponse = ["d"=>["ErrorCode"=>-10,"HasErrors"=>true,"Message"=>"Invalid balance returned"]];
            return response()->json($rivalaoResponse); 
        
        }
        return response()->json($game);
        $rivalaoResponse = ["d"=>["ErrorCode"=>-20,"HasErrors"=>true,"Message"=>"Duplicate transaction"]];
        return response()->json($rivalaoResponse);
      }

Activity icon

Started a new Conversation Model::decrement() And Model::increment() Not Working Efficiently

Hey guys, I am getting data from a request and I have created a model observer to do some computations on the data after it has been saved. The computations are like incrementing the user balance based on the amount that came in the request. The shocking thing however is that this is working for some instances and not others, even though the amount is received and saved in the database. What could be happening?

public function created(XpgTransaction $xpgTransaction)
    {   $userId = $xpgTransaction->user_id;
        $user = User::where('id', $userId)->first();
        $userBalance = $user->casino_bakiye;
        if($xpgTransaction->type =="debit"){
            $debitBalance = $xpgTransaction->amount;
            $user->decrement('casino_bakiye', $debitBalance);
        }
        if($xpgTransaction->type =="credit"){
            $creditBalance = $xpgTransaction->amount;
            $user->increment('casino_bakiye', $creditBalance);
        }

    }
Sep
24
3 days ago
Activity icon

Started a new Conversation How To Queue Transactions In Laravel

I am receiving requests from an API and I ought to update the user balance based on the amount that came in the request. It is working well, however, when the requests are sent concurrently, some data is not saved. I guess this is due to the speed in which the requests are being sent. Is there a way of queueing transactions in laravel so that no transaction is skept? Or Is there an error in my code that is causing this? This is how the data is saved, in some requests, the balance is null yet the request is received: https://imgur.com/7BVBPvq

     $trxn = new XpgTransaction;
          $trxn->user_id = $userId;
          $trxn->operatorId = $operator;
          $trxn->session = $session;
          $trxn->gameId =$gameId;
          $trxn->roundId =$roundId;
          $trxn->sequence = $sequence;
          $trxn->type = "debit";
          $trxn->debitDetails = $debitDetails;
          $trxn ->request=json_encode($data);
          $trxn->amount = $amount;
          if($trxn->save()){
            if($user->casino_bakiye >=$amount){
       
              $user->casino_bakiye = ($user->casino_bakiye - $amount);
              if($user->save()){
                $lastTrxn = XpgTransaction::latest()->first();
                $lastTrxn->casino_balance = $user->casino_bakiye;
                $lastTrxn->save();

                $response = ["d"=>["Data"=>[(float)$user-				 
                 >casino_bakiye],"ErrorCode"=>0,"HasErrors"=>false,"Message"=>""]];
                return response()->json($rivalaoResponse);
              }
              $response = ["d"=>["ErrorCode"=>-20,"HasErrors"=>true,"Message"=>"Insufficient amount"]];
              return response()->json($rivalaoResponse);
              
            }
            
          }
Sep
22
5 days ago
Activity icon

Replied to Given An Array Of Usernames, How Do I Retrieve All The User Details From A Model?

 [   {
        "id": 3,
        "username": "Simon",
        "pasif": 0,
       
    }
]
Activity icon

Replied to Given An Array Of Usernames, How Do I Retrieve All The User Details From A Model?

    {
    
       $usernames = ["simon"," Yonetim"];
       $users= User::whereIn('username', $usernames)->get();
       return $users;
    }
Activity icon

Replied to Given An Array Of Usernames, How Do I Retrieve All The User Details From A Model?

I want to retrieve all the users and all of them are in the database

Activity icon

Replied to Given An Array Of Usernames, How Do I Retrieve All The User Details From A Model?

Is there any helper that can help retrieve all the users given specific usernames?

Activity icon

Replied to Given An Array Of Usernames, How Do I Retrieve All The User Details From A Model?

Model::whereIn('username',$users)->get(); Returns the information of the first username alone

Activity icon

Started a new Conversation Given An Array Of Usernames, How Do I Retrieve All The User Details From A Model?

Lets say I want to retrieve a user with a username $username, normally I will do Model::where('username',$username)->first(); Now, how should I do to get all the users given an array of usernames? Like $users = ['enock', 'Erick','Simon'];?

Activity icon

Replied to How Do You Handle An API That Sends Data To A Callback URL Using Various Methods

  1. Player place a bet/s on any XPG live game
  2. XPG sends Debit API call
  3. Operator processes Debit API call and will reply to XPG within 3sec.
  4. Operator waits for Credit API call to see if player did Win or Lost [“Lost” Credit API calls will contain “Amount=0”]

This is part of instruction on how it works, please...

Activity icon

Replied to How Do You Handle An API That Sends Data To A Callback URL Using Various Methods

In this case, they are the ones sending data to us. For example when a player wins or losses, they send the debit or credit data that we ought to process and return data to them to update the player's account information

Activity icon

Replied to How Do You Handle An API That Sends Data To A Callback URL Using Various Methods

It comes because they told me to send them a callback URL

Activity icon

Replied to How Do You Handle An API That Sends Data To A Callback URL Using Various Methods

The documentation doesn't talk about callback URL anywhere

Sep
21
6 days ago
Activity icon

Replied to How Do You Handle An API That Sends Data To A Callback URL Using Various Methods

How do I do that when the callback URL looks something like this: http://mywebsite.com/api/response

Activity icon

Started a new Conversation How Do You Handle An API That Sends Data To A Callback URL Using Various Methods

I have an API that sends data to the callback URL using various methods. For example: getPlayerBalance method comes with data like this: {"Login":"username","OperatorId":"1","Session":"465663"} while getPlayerBalances method comes with data like this: {"d":{"Data":[{"Balance":100.0000,"Login":" username1"},{"Balance":200,"Login":" username2"}],"ErrorCode":0,"HasErrors":false,"Message":""}} Now the question is how do I know the method sending data so that I can handle the data differently?

Sep
17
1 week ago
Activity icon

Replied to Is There A Way Of Translating The Website Based On The User's Locale(language) In Laravel Without Using Google Translate Package?

Thanks. About the same google translate is working well on the website but on the live server, it is throwing 429 many requests error. How do I solve that?

```[2020-09-17 08:04:03] production.ERROR: Client error: GET https://translate.google.com/translate_a/single?client=webapp&hl=en&dt=t&dt=bd&dt=at&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&sl=auto&tl=en&q=Canl%C4%B1+Bahisler&ie=UTF-8&oe=UTF-8&multires=1&otf=0&pc=1&trs=1&ssel=0&tsel=0&kc=1&tk=40965.430971 resulted in a 429 Too Many Requests response:

Activity icon

Started a new Conversation Is There A Way Of Translating The Website Based On The User's Locale(language) In Laravel Without Using Google Translate Package?

I am using Laravel's google translate package but it is throwing errors of too many requests. So I was thinking if I could achieve translating to any language(user's locale) in Laravel without using third party packages?

Sep
15
1 week ago
Activity icon

Started a new Conversation Embedding Vue Js Variables In PHP Tags In Blade Template

Hello guys, I am trying to implement https://github.com/Stichoza/google-translate-php for translation on my site. Now I have set up everything well and static variables are being translated. However, I have a problem with dynamic variables since they can from vue. So my question is, is there a way I can pass vue variables to PHP tags? Because if that is possible I know how I am going to go around it. This is what I am trying to do which the initialized google translate instance to translate dynamic data from vue, but it is throwing error! I want to translate the dynamic variable from vue spor.detail :)


<span @click="bultenSpor.id == spor.id ? bultenSpor = 'null': bultenSpor = spor; bultenCurrentId = spor.id">
                            <div class="text">
                          <?php   
				$tr = new GoogleTranslate();
				$tr->translate(@{{spor.detail}}, "en") 
			 ?>
                            </div>
                            <div class="sayi">
                                @{{ count(spor) }}
                            </div>
                        </span>
Sep
12
2 weeks ago
Activity icon

Replied to Error Establishing A Database Connection On Home('/') Route

The wordpress in the public_html folder, then laravel inside public_html's subfolder

Activity icon

Replied to Error Establishing A Database Connection On Home('/') Route

Ooh, more information on that? Because I actually have WordPress and laravel hosted together.

Sep
11
2 weeks ago
Activity icon

Replied to How To Redirect/return View From API Route Controller

I said API route controller. The normal redirecting don't work

Activity icon

Started a new Conversation Error Establishing A Database Connection On Home('/') Route

All other routes of my Laravel App are working except the home route('/'). When I visit the homepage, it returns an error page with the title (Database error) with a kind of h2 text saying Error establishing a database connection

I guess that maybe it is my .htaccess file problem. This is how it looks like.

    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On
    <Files .env>
      Order allow,deny
      Deny from all
    </Files>
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteEngine on
RewriteRule ^$ https://mywebsite.com/ [R=301,L]```
Activity icon

Started a new Conversation How To Redirect/return View From API Route Controller

Hi, I am working on some payment API and using some controller to handle the request sent through that Api. Now I want to redirect to another page immediately that request has been successful but then it is not working on that route.

//My controller:
$curl_response = curl_exec($curl);
        if($curl_response){
            $this->confirmForm();
        }```

//confirmForm Method:

 public function confirmForm(){
        $page_title = "Lipa na M-PESA confirmation";
        return view(activeTemplate() . 'payment.mpesa-confirm', compact('page_title'));
    }

The curl_response is running successfully but it is not redirecting. How do I solve this?
Sep
10
2 weeks ago
Activity icon

Replied to Routes Not Working On The Server But Works Well On The Localhost

That my .htacess file inside the public_html folder. THe laravel project is in ./acc/core path inside the public_html folder

Activity icon

Replied to Routes Not Working On The Server But Works Well On The Localhost

Redirect /register/ /acc/user/register

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
   php_flag display_errors Off
   php_value max_execution_time 60
   php_value max_input_time 60
   php_value max_input_vars 3000
   php_value memory_limit 512M
   php_value post_max_size 96M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php70"
   php_value upload_max_filesize 64M
   php_flag zlib.output_compression On
</IfModule>
<IfModule lsapi_module>
   php_flag display_errors Off
   php_value max_execution_time 60
   php_value max_input_time 60
   php_value max_input_vars 3000
   php_value memory_limit 512M
   php_value post_max_size 96M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php70"
   php_value upload_max_filesize 64M
   php_flag zlib.output_compression On
</IfModule>
# END cPanel-generated php ini directives, do not edit

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Activity icon

Started a new Conversation Routes Not Working On The Server But Works Well On The Localhost

I am having an issue where my laravel application is working on the localhost but when I upload the project to the server, none of the routes work except the home page. All other pages are falling back to page 404.. What might be the issue? The application was hosted on another domain and had google Recaptcha set and it is throwing an error that the key is invalid. So I dont know if google capture can block the routes due to invalid key?

Sep
09
2 weeks ago
Activity icon

Replied to How To Get Full URL Without Sorting Query Parameters

Yes, I am doing that. My problem is that url()->full(); is sorting the parameters yet I want the query part to be as it is without being sorted

Activity icon

Started a new Conversation How To Get Full URL Without Sorting Query Parameters

I want to extract the query part of a URL, this is my URL for example http://mywebsite.com/tvbet/response?action=balance&refId=0&accountId=1&gameId=100138&clientType=desktop&currency=TRY&isBonus=False&username=Yonetim&hash=iobVJKHFhhgjvfcVJHIKVGYFG

To do that, I am using laravel helper url()->full() . Now the problem is that it is re-arranging the parameters like this:

http://mywebsite.com/tvbet/response?accountId=1&action=balance&clientType=desktop&currency=TRY&gameId=100138&hash=iobVJKHFhhgjvfcVJHIKVGYFG&isBonus=False&refId=0&username=Yonetim

What should I do so that I get the full url without sorting the parameters?

Sep
08
2 weeks ago
Activity icon

Started a new Conversation Setting Allow CORS Headers In Laravel

I am working with an API that requires me to embed their games lobby into an iFrame on the website I am working on. I realized that the lobby interacts with my website by sending messages to it. Now the problem is that on rendering the iFrame, it doesn't show anything but a blank page. However, on checking the console, I get this error: Uncaught DOMException: Blocked a frame with origin "https://website.co" from accessing a cross-origin frame.

Meaning that my page is blocking the domain in the iFrame from accessing the main window where the iFrame is contained. On doing research, I found out that you can have control over this if you have control of the domain in the iframe src. In my case though I don't have control over it. I also came across a resource talking of setting headers in my Laravel app to add the domain in the URL into the list of allowed origins. However, I have no idea how to go about this in Laravel. Could anyone help me get a hint on how to go about this?

My html file:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">

</head>
<body>
<div class="container"> 
<iframe class="responsive-iframe" src="{{$FULL_URL}}"  style="border: 0; position:fixed; top:0; left:0; right:0; bottom:0; " allowfullscreen></iframe>

</div>



</body>
</html>

enter image description here

Sep
07
2 weeks ago
Activity icon

Started a new Conversation Uncaught DOMException: Blocked A Frame With Origin <URL> From Accessing A Cross-origin Frame

I am generating a dynamic URL in the controller and sending it to the view but when I try accessing it in the browser, I get this error Uncaught DOMException: Blocked a frame with origin <URL> from accessing a cross-origin frame. The URL is from another origin. Your help appreciated.

my controller method:

public function home(){
    $user = auth()->user();
    $LANGUAGE_CODE = 'tr';
    $userId =$user->id;
    $DEVICE_ID = md5($userId);
    $INBET_LOBBY_URL ="https://rivala0.vlobby.co";

  //  https://<lobby_host>?l=<LANGUAGE_CODE>&d=<DEVICE_ID>&s=<SESSION_ID>

    $FULL_URL=$INBET_LOBBY_URL."?l=".$LANGUAGE_CODE."&d=".$DEVICE_ID;
   
    return view('inbet.home', compact('FULL_URL'));


}

My blade file:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">

</head>
<body>
<div class="container"> 
<iframe class="responsive-iframe" src="{{$FULL_URL}}"  style="border: 0; position:fixed; top:0; left:0; right:0; bottom:0; " allowfullscreen></iframe>

</div>



</body>
</html>

enter image description here

Sep
03
3 weeks ago
Activity icon

Replied to Auth()->user()||Auth::user() Not Working No A Route Where VerifycsrfToken Middleware Is Disabled

The home() method has access to auth()->user(); the bill() method returns an empty object with auth()->user(); please check the code above

Activity icon

Replied to Auth()->user()||Auth::user() Not Working No A Route Where VerifycsrfToken Middleware Is Disabled


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use Illuminate\Support\Facades\Auth;
use App\Classes\InbetBill;
class InbetController extends Controller
{
  
    const REPLY_SING_FAIL = 'sign_not_found';
    const REPLY_SESSION_FAIL = 'session_not_found';
    const REPLY_MONEY_FAIL = 'not_enough_money';
    const REPLY_OK = 'OK';
    public  $salt = "sdbVHKVJHHCCfhjghFFJ";
   



    public function home(){
        $user = auth()->user();
        $LANGUAGE_CODE = 'tr';
        $DEVICE_ID = $user->id;
        $INBET_LOBBY_URL ="https://rivala0.vlobby.co";

      //  https://<lobby_host>?l=<LANGUAGE_CODE>&d=<DEVICE_ID>&s=<SESSION_ID>

        $FULL_URL=$INBET_LOBBY_URL."?l=".$LANGUAGE_CODE."&d=".$DEVICE_ID;
       
        return view('inbet.home', compact('FULL_URL'));


    }


    public function bill(Request $request)
     {
        $jsonText = file_get_contents("php://input");
        $json = json_decode($jsonText, true);
        
        // If the request body is empty
        if (empty($json)) {
            return $this->returnAnswer(self::REPLY_SESSION_FAIL);
        }
        $trxnId = $json['trx_id'];
        $sign = $json['sign'];
        $session = $json['session'];
        $retry = $json['retry'];
        $plus = $json['plus'];
        $minus = $json['minus'];
        $method = $json['method'];

        if($method==='do'){
            
            //Signature verification
            if (!$this->_checkSalt($json)) {
                return $this->returnAnswer(self::REPLY_SING_FAIL);
            }
            
            /** @var Users $user */
            //$user =User::where('id', 1)->first();
		$user=auth()->user();
            
            if (!$user) {
                return $this->returnAnswer(self::REPLY_SESSION_FAIL);
            }
            
            // If not enough funds
            if ($minus > $user->inbet_bakiye) {
                $this->returnAnswer(self::REPLY_MONEY_FAIL, $user->inbet_bakiye, "TRY");
            }else{
                $newBakiye = $user->inbet_bakiye  - $json['minus'];
                $user->inbet_bakiye = $newBakiye;
                $user->save();

            }
            
            if($plus !==0){
                $newBakiye = $user->inbet_bakiye  + $json['plus'];
                $user->inbet_bakiye = $newBakiye;
                $user->save();
            }
            
            
            return $this->returnAnswer(self::REPLY_OK, $user->inbet_bakiye, "TRY");
        }
        
        
        
       
    }
    
    /**
     * Signature verification FUNC
     * @param array $json
     * @return bool
     */
    private function _checkSalt(array $json)
    {   
        // $str = "do::".$json['session']."::".$json['trx_id']."::".$this->salt;
        // for($i=1; $i<=45; $i++) {
        //     $str = md5($str);
        // }
        // if ($str == $json['sign']) {
        //     return true;
        // }
        return true;
     }
    
    /**
     * Preparing a response to a request
     * @param string $status
     * @param array $moreData
     * @return array
     */
    private function returnAnswer($status, $balance = null, $currency = null, array $moreData = array())
    {
        $_return = array('status' => $status);
        
        if (!empty($balance)) {
            $_return['balance'] = $balance;
        }
        if (!empty($currency)) {
            $_return['currency'] = $currency;
        }
        
        if (!empty($moreData)) {
            if (!empty($moreData['status'])) {
                unset($moreData['status']);
            }
            $_return = array_merge($_return, $moreData);
        }
        return $_return;
    }
}
Activity icon

Started a new Conversation Auth()->user()||Auth::user() Not Working No A Route Where VerifycsrfToken Middleware Is Disabled

I have two methods in the same controller. Now, one of the routes handles the POST requests from an API and I had to disable the VerifyCsrfToken middleware because it wasn't receiving data then, and since it is a callback URL, it has to receive data in order to save or do something to the data. Before I disabled the VerifyCsrfToken middleware on the route, the POST request was throwing an error that the page expired. This worked when I disabled the middleware though. Now this developed yet another problem, I can't access the current logged in user through auth()->user()||Auth::user(); yet I can access the logged-in user from the other methods on the same controller. Whoever knows any solution to this problem?

Aug
31
3 weeks ago
Activity icon

Started a new Conversation Php Artisan Key:generate Runs Successfully But No Key Is Generated PHP 7.4.9

I just pulled my project from GitHub with an intention of working on it but then when I run PHP artisan serve after doing composer install, PHP artisan config: cache and making sure that I have the .env file in the root directory, the command runs successfully but no key is generated. A quick search gives me solutions such as making sure I have a .env file, I do PHP artisan config: clear/cache, I do composer update --no-scripts etc. I have done all those but then realized again that it might be an error with PHP 7.4 from this post on GitHub: https://github.com/laravel/framework/issues/32059

Could anyone suggest possible solutions to this problem?