mercredi 28 août 2019

Laravel get exercises by day from pivot table

I am trying to query a pivot table to show how many exercises have one day, but there is something wrong with that.

I need to get all the exercises by Monday or any day.

I have three tables: routines, exercises and exercise_routine.

routines     exercise_routine  exercise
--------     ----------------  --------
id           id                id
name         routine_id        name
description  exercise_id       description
user_id      week_day_id
             sets
             reps

I would like to get all the exercises by week_day_id, hope you understand my problem.

I tried these examples from other people on stackoverflow but it does not work.

Exercise::whereHas('routines', function($q) {
                $q->where('routines.week_day_id', 1);
            })
            ->get();

        return \DB::table('exercises')
            ->join('exercise_routine', 'exercise_routine.exercise_id', '=', 'exercises.id')
            ->where('exercise_routine', 1)
            ->get();

        dd( DB::table('exercises')
            ->where('exercises.id', '=', 1)
            ->select('exercises.id'));

// Routine Model

public function exercises() {
        return $this->belongsToMany('App\Models\Exercise');
    }

// ExerciseModel

public function routines() {
        return $this->belongsToMany('App\Models\Routine')->as('plan')->withPivot('sets', 'reps', 'week_day_id')->withTimestamps();
    }

// Controller
public function show(WeekDay $weekday) {
        Exercise::whereHas('routines', function($q, $weekday) {
                $q->where('routines.week_day_id', $weekday);
            })
            ->get();

    }

// api routes
Route::group(['prefix' => '/{weekday}/exercises'], function () {
        Route::get('/', 'WeekDayExerciseController@show')->middleware('auth:api');
    });

I expected to get all the exercises by Monday for example like this:

   {
        "id": 236,
        "name": "Upright Row (Barbell)",
        "description": "Description for Upright Row (Barbell)"
    },
    {
        "id": 237,
        "name": "Upright Row (Cable)",
        "description": "Description for Upright Row (Cable)"
    },
    {
        "id": 238,
        "name": "Upright Row (Dumbbell)",
        "description": "Description for Upright Row (Dumbbell)"
    },



via Chebli Mohamed

how to array inside the array in laravel chart

i have issue of having data from database, i want to get the array of my sales in group by month and group by product with array of sales sum of per month please help me.

i tried to get it using query builder and eloquent but i cant do it .

                    ->title('Sales Chart for CF')
                    ->colors(['#ff0000', '#ff','#56f442','#41caf4'])
                    ->labels($month_array)
                    ->dataset('product1',[])
                    ->dataset('product1',[5212,383,153])
                    ->dataset('product1',[1212,383,113])
                    ->dataset('product1',[1212,383,113]);

my desire output is

->dataset('array of proudct','array of sales monthly')



via Chebli Mohamed

mardi 27 août 2019

Sorry, your bank wasn't able to verify your MASTERCARD at this time. Please choose another way to pay. during Paypal Sandbox account testing

have used the Paypal Payment API of PHP and done implementation is done server side.And when Paypal sandbox personal account user logs in and tries to make payment. It throws the error as "Sorry, your bank wasn't able to verify your MASTERCARD x-8417 at this time. Please choose another way to pay."

Tried with different card but still the error persists.

Expected To make payment to the merchant



via Chebli Mohamed

Laravel: How to get count of total Comments of total Posts

I have 10000 posts and each post have many comments. I need to calculate all comments count when i take posts.

[
    'post_1' => [
        'comments' => [
            'comment_1' => 'trst comment',
            'comment_2' => 'trst comment',
            'comment_3' => 'trst comment',
        ],
    ],
    'post_2' => [
        'comments' => [
            'comment_1' => 'trst comment',
            'comment_2' => 'trst comment',
            'comment_3' => 'trst comment',
        ],
    ],
    'post_3' => [
        'comments' => [
            'comment_1' => 'trst comment',
            'comment_2' => 'trst comment',
            'comment_3' => 'trst comment',
        ],
    ],
]

there are total 9 comments. i want get this count.

In laravel is possible to get count of hasMany relation of one row

Post::first()->comments()-count()

I need like this:

Post::get()->comments()-count()

i dont want use foreach because my server may get down.



via Chebli Mohamed

How can I redirect only after transaction is finalized?

In the sample code I have for checking out with paypal, there is a redirect request to a route purchase/complete. I'd like to ensure that this route is requested only after the post request to /paypal/purchase/complete has been completed so that I can get the orderID created on the server side and pass it as a get parameter to the purchase/complete route so that it would resemble something like purchase/complete?orderId=XXXX. XXXX here would be the received data.orderID

Client side:

    // Render the PayPal button into #paypal-button-container
    paypal.Buttons({

      // Set up the transaction
      createOrder: function(data, actions) {
        var payableAmount = $("#finalAmountTotalOrders").attr("amountData");
        return actions.order.create({
          purchase_units: [{
            amount: {
              value: payableAmount
            }
          }]
        });
      },

      // Finalize the transaction
      onApprove: function(data, actions) {
        return actions.order.capture().then(function(details) {
          //will redirect user to custom page change values as desired
          window.location.replace("/purchase/complete");
          // Call your server to save the transaction
          return fetch('/paypal/purchase/complete', {
            method: 'post',
            headers: {
              'content-type': 'application/json',
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            body: JSON.stringify({
              orderID: data.orderID,
              details: details

            })

          });

        });
      }


    }).render('#paypal-button-container');

Edit:

The reason I'd like to do this is because although I am able to create an order and store it in my database once the /paypal/purchase/complete post request is made, I'm not sure when I would do something like email the customer and merchant with the ID of the order (database row) I just created. Trying to do it in the post request throws an error so if I could just get the ID on the /purchase/complete route, I can query the database and get the order details and email it. Any other approach would be useful to me.



via Chebli Mohamed

this.$router.push() is not recognizing inside google map place_changed function

I have a textbox which is connected to google map place autocomplete function . I called the new google.maps.places.Autocomplete() function inside vue mounted property . Based on the search results i want to redirect my page to a search filter page calling this.$router.push() function . But i don't know why this.$router.push() function is not recognizing inside google map place_changed function .

I called this.$router.push() inside mounted(){} function . Its working fine but i need to recognize this.$router.push() function inside place_changed function .

<input id="modal-filters-Main"
                                        placeholder="Enter an address, neighborhood, city or ZIP code"
                                        class="typeahead form-control form-ready-for-bubble" >


var SearchBox = new google.maps.places.Autocomplete(document.getElementById('modal-filters-Main'));
            SearchBox.addListener('place_changed', function() {
                 this.place = SearchBox.getPlace();
                 this.formatter = this.place.formatted_address;
                 this.lower = this.formatter.toLowerCase();
                 this.modified = this.lower.replace(", ","_");
                this.$router.push('/listing/'+this.modified);
                // window.location.href = '/listing/'+modified;
            });



via Chebli Mohamed

How to Create Login and Register in React Native with Laravel Passport Authentication as BackEnd?

I'm a student now, and I'm developing an Hybrid Mobile App for my smal project. I already finished the back-end login and registration in Laravel with passport (I'm using XAMPP for DB), but I have no clue about how to integrate the laravel sign-in passport with React Native. Of course I did researched in Google and followed some of tutorials in Youtube, but it doesn't really work tho. Could anybody explain to me how to create login and register in react native with laravel passport authentication.

and Also, how do we create route for login with API in laravel so that we can call it in react native?

Thank you :D



via Chebli Mohamed