lundi 30 janvier 2023

Laravel - How to get all product ids and quantity in a current cart?

How to get all product ids and quantity in a current cart? I learned that i can get the total sum with , but can someone help me how to get the product id's and quantity.

I need to fill this with correct data:

contents: [
      {
        id: ''',
        quantity: X
      },
      {
        id: ''',
        quantity: X
      }],

Thank you. Keep in mind that i'm not a programmer, but i have to find a way to do it :) Laravel 5.2.

I tried everything that i saw in google.



via Chebli Mohamed

dimanche 29 janvier 2023

How to change dynamically APP_KEY in config/app.php in laravel

basically i want to give different different APP_KEY to different different user so, when i try to do this they give fatal error

    /*
    |--------------------------------------------------------------------------
    | Encryption Key
    |--------------------------------------------------------------------------
    |
    | This key is used by the Illuminate encrypter service and should be set
    | to a random, 32 character string, otherwise these encrypted strings
    | will not be safe. Please do this before deploying an application!
    |
    */

    'key' => Auth::User()->APP_KEY

    'cipher' => 'AES-256-CBC',


via Chebli Mohamed

vendredi 27 janvier 2023

When I try to collapse my element it automatically opens again and again

enter image description here

When I try to close my element it automatically opens again and again

<div class="portlet box purple ">
  <div class="portlet-title">
    <div class="caption">
      <i class="fa fa-gift"></i> Advance Search </div>
    <div class="tools">
      <a href="" class="<?= isset($_GET['advanceSearch']) ? " expand " : "collapse "  ?>"><i class="icon-collapse"></i></a>
    </div>
  </div>
  <div class="portlet-body form">
    {!! Form::open(['method'=>'GET','url'=>route('users.index'),'class'=>'form-horizontal','role'=>'search']) !!}
    <div class="form-body">
      <div class="row">
        <div class="col-md-4">
          <div class="form-group">
            <div class="col-md-12">
              <label>First Name<span class="required"></span></label> {!! Form::text('first_name', null, array('placeholder' => 'First Name','class' => 'form-control')) !!}
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="form-group">
            <div class="col-md-12">
              <label>Email<span class="required"></span></label> {!! Form::text('email', \Request::get('email'), array('placeholder' => 'Email','class' => 'form-control')) !!}
            </div>
          </div>
        </div>
        <div class="clearfix"></div>
        <div class="form-actions" style="text-align: center">
          <input class="btn green" type="submit" name="advanceSearch" value="Search">
        </div>
      </div>
    </div>
    {!! Form::close() !!}
  </div>
  <!-- search-form -->
</div>


via Chebli Mohamed

jeudi 26 janvier 2023

How I can pipeline the incomming results in Laravel so I can process them whilst I read them?

I need to run a query in a console command:


use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

use App\Jobs\SendVaccationEmail;

class ProcessDbResult extends Command
{
  protected $signature = "process:entries";
  protected $description = "Bulk Process of results";

   public function handle() 
   {
     $sql = "
        SELECT DISTINCT 
             user_id 
        from 
         (Select user_id from travels where destination = "Bahamas") as bahamas_vac
         LEFT JOIN (Select user_id from travels where destination <> "Bahamas") as non_bahamas_vac ON bahamas_vac.user_id = non_bahamas_vac.user_id
        WHERE
          non_bahamas_vac.user_id = NULL
 ";

     $results = DB:select($sql);
     foreach($results as $result){
       SendVaccationEmail::dispatch($result);
     }
   }
}

But expect the results to be rather large ~ 100.000 records, therefore in order to save memory consumption, I want somehow the database results to be streamed instead being fetched on one go.

What I actually want to do is:

enter image description here

Meaning I do not want to wait for results to be returned but once I have the first result I want to begin to process it.

Is somehow feasible Using laravel? I'm stuck with laravel 5.8.



via Chebli Mohamed

mardi 24 janvier 2023

How can i decrypt my old data with new laravel new generated key [closed]

encrypt library's link with laravel:- https://www.nicesnippets.com/blog/laravel-8-automatic-database-encryption-decryption-with-eloquent

I have decrypt and insert data in db throw this library, but problem with this, i can decrypt and fetch my data with my only old (APP_KEY base64:xxxxxxxxxxxxxxxxxxxx), i am unable to decrypt the data with updated key. i need help to solve this problem.



via Chebli Mohamed

lundi 23 janvier 2023

Compare one zipcode in range of zips [closed]

If my single zip code is 00624 and range in databse is 005-009, how do I compare this?

public function postalcode(Request $request)
{
    dd($request->postalcode);
}


via Chebli Mohamed

mercredi 18 janvier 2023

Laravel controller Merge 2 array to Comparision selling

I have 2 array to get the sold products from location at different date ranges then I need to make comparison between the two arrays

$results_day_report = DB::table('transaction_sell_lines as tsl')
        ->select(DB::raw('b.name as business_location_name , t.location_id as location_id , tsl.product_id as product_id , p.name as product_name , tsl.variation_id as variation_id , sum(tsl.quantity) AS quantity , sum(tsl.quantity * tsl.unit_price_inc_tax) AS total'))
        ->leftjoin('transactions as t','t.id', '=', 'tsl.transaction_id')
        ->leftjoin('business_locations as b','b.id', '=', 't.location_id')
        ->leftjoin('products as p','p.id', '=', 'tsl.product_id')
        ->whereRaw("t.transaction_date LIKE '$reportdate%'")
        ->where('b.custom_field1', $location_type)
        ->where('t.type', '=' , 'sell')
        ->where('t.status', '=' , 'final')
        ->where('p.id', '!=' , 1)
        ->groupBy('tsl.variation_id')
        ->orderBy('tsl.variation_id', 'asc')
        ->orderBy('b.id', 'asc')
        ->get(); 
        
        $results_day_report_year_before = DB::table('transaction_sell_lines as tsl')
        ->select(DB::raw('b.name as business_location_name , t.location_id as location_id , tsl.product_id as product_id , p.name as product_name , tsl.variation_id as variation_id , sum(tsl.quantity) AS quantity , sum(tsl.quantity * tsl.unit_price_inc_tax) AS total'))
        ->leftjoin('transactions as t','t.id', '=', 'tsl.transaction_id')
        ->leftjoin('business_locations as b','b.id', '=', 't.location_id')
        ->leftjoin('products as p','p.id', '=', 'tsl.product_id')
        ->whereRaw("t.transaction_date LIKE '$reportdate_year_before%'")
        ->where('b.custom_field1', $location_type)
        ->where('t.type', '=' , 'sell')
        ->where('t.status', '=' , 'final')
        ->where('p.id', '!=' , 1)
        ->groupBy('tsl.variation_id')
        ->orderBy('tsl.variation_id', 'asc')
        ->orderBy('b.id', 'asc')
        ->get();  

and Now I have results to be $results_day_report =

Illuminate\Support\Collection {#4170 ▼
  #items: array:23 [▼
    0 => {#4172 ▼
      +"business_location_name": "Gaming Area"
      +"location_id": 19
      +"product_id": 526
      +"product_name": "سيارات تصادم (مايكل)"
      +"variation_id": 674
      +"quantity": "15.0000"
      +"total": "300.00000000"
    }
    1 => {#4178 ▼
      +"business_location_name": "Gaming Area"
      +"location_id": 19
      +"product_id": 528
      +"product_name": "قطار اطفال (مايكل)"
      +"variation_id": 676
      +"quantity": "5.0000"
      +"total": "50.00000000"
    }
    2 => {#4179 ▼
      +"business_location_name": "Gaming Area"
      +"location_id": 19
      +"product_id": 529
      +"product_name": "ارنوب (مايكل)"
      +"variation_id": 677
      +"quantity": "3.0000"
      +"total": "30.00000000"
    }
    3 => {#4173 ▼
      +"business_location_name": "Lavandula Gym"
      +"location_id": 17
      +"product_id": 594
      +"product_name": "جم رجال يومى ع.د"
      +"variation_id": 742
      +"quantity": "3.0000"
      +"total": "90.00000000"
    }
    4 => {#4171 ▼
      +"business_location_name": "Lavandula Gym"
      +"location_id": 17
      +"product_id": 595
      +"product_name": "جم رجال يومى ق.م"
      +"variation_id": 743
      +"quantity": "1.0000"
      +"total": "60.00000000"
    }
    5 => {#4177 ▼
      +"business_location_name": "Lavandula Gym"
      +"location_id": 17
      +"product_id": 597
      +"product_name": "جم رجال شهرى ع.د"
      +"variation_id": 745
      +"quantity": "1.0000"
      +"total": "200.00000000"
    }
    6 => {#4175 ▼
      +"business_location_name": "Lavandula Gym"
      +"location_id": 17
      +"product_id": 615
      +"product_name": "رسم استخراج كارنيه اول مره"
      +"variation_id": 763
      +"quantity": "1.0000"
      +"total": "30.00000000"
    }
    7 => {#4180 ▼
      +"business_location_name": "Tiba Rose Gym"
      +"location_id": 16
      +"product_id": 637
      +"product_name": "جلسة مساج مشتركين"
      +"variation_id": 785
      +"quantity": "2.0000"
      +"total": "400.00000000"
    }
    8 => {#4181 ▼
      +"business_location_name": "Tiba Rose Gym"
      +"location_id": 16
      +"product_id": 679
      +"product_name": "جيم سيدات يومى ع د"
      +"variation_id": 827
      +"quantity": "2.0000"
      +"total": "70.00000000"
    }
    9 => {#4182 ▼
      +"business_location_name": "Tiba Rose Gym"
      +"location_id": 16
      +"product_id": 681
      +"product_name": "جيم  سيدات يومى مدنى"
      +"variation_id": 829
      +"quantity": "1.0000"
      +"total": "85.00000000"
    }
    10 => {#4183 ▼
      +"business_location_name": "Tiba Rose Gym"
      +"location_id": 16
      +"product_id": 683
      +"product_name": "جيم سيدات  شهرى ق م"
      +"variation_id": 831
      +"quantity": "1.0000"
      +"total": "450.00000000"
    }
    11 => {#4184 ▼
      +"business_location_name": "Tiba Rose Gym"
      +"location_id": 16
      +"product_id": 705
      +"product_name": "حمام سباحة مغطى(م)"
      +"variation_id": 853
      +"quantity": "1.0000"
      +"total": "75.00000000"
    }
    12 => {#4185 ▼
      +"business_location_name": "Subscriptions"
      +"location_id": 20
      +"product_id": 773
      +"product_name": "العاب ثابته"
      +"variation_id": 921
      +"quantity": "3.0000"
      +"total": "30.00000000"
    }
    13 => {#4186 ▼
      +"business_location_name": "Gaming Area"
      +"location_id": 19
      +"product_id": 6140
      +"product_name": "الترامبولين م"
      +"variation_id": 6291
      +"quantity": "7.0000"
      +"total": "70.00000000"
    }
    14 => {#4187 ▼
      +"business_location_name": "Gaming Area"
      +"location_id": 19
      +"product_id": 6568
      +"product_name": "كاروسيل (مايكل)"
      +"variation_id": 6719
      +"quantity": "5.0000"
      +"total": "50.00000000"
    }
    15 => {#4188 ▼
      +"business_location_name": "Red Zone"
      +"location_id": 44
      +"product_id": 7781
      +"product_name": "مصارعه سومو"
      +"variation_id": 7932
      +"quantity": "10.0000"
      +"total": "217.39100000"
    }
    16 => {#4189 ▼
      +"business_location_name": "Red Zone"
      +"location_id": 44
      +"product_id": 7782
      +"product_name": "تيلي جيمز"
      +"variation_id": 7933
      +"quantity": "10.0000"
      +"total": "217.39100000"
    }
    17 => {#4190 ▼
      +"business_location_name": "Red Zone"
      +"location_id": 44
      +"product_id": 7783
      +"product_name": "فولي بيج بول"
      +"variation_id": 7934
      +"quantity": "10.0000"
      +"total": "347.82600000"
    }
    18 => {#4191 ▼
      +"business_location_name": "Red Zone"
      +"location_id": 44
      +"product_id": 7784
      +"product_name": "سوكر شوز"
      +"variation_id": 7935
      +"quantity": "10.0000"
      +"total": "347.82600000"
    }
    19 => {#4192 ▼
      +"business_location_name": "Red Zone"
      +"location_id": 44
      +"product_id": 7785
      +"product_name": "الساعة"
      +"variation_id": 7936
      +"quantity": "10.0000"
      +"total": "434.78300000"
    }
    20 => {#4193 ▼
      +"business_location_name": "Tiba Rose Gym"
      +"location_id": 16
      +"product_id": 9091
      +"product_name": "اكستريم جيم سيدات شهري مدني"
      +"variation_id": 9251
      +"quantity": "1.0000"
      +"total": "800.00000000"
    }
    21 => {#4194 ▼
      +"business_location_name": "Red Zone"
      +"location_id": 44
      +"product_id": 9341
      +"product_name": "ارشيرلي فايت"
      +"variation_id": 9501
      +"quantity": "10.0000"
      +"total": "434.78300000"
    }
    22 => {#4195 ▼
      +"business_location_name": "Red Zone"
      +"location_id": 44
      +"product_id": 9342
      +"product_name": "كومبو (2)"
      +"variation_id": 9502
      +"quantity": "10.0000"
      +"total": "2000.00000000"
    }
  ]
}

and result of $results_day_report_year_before to be

Illuminate\Support\Collection {#4174 ▼
  #items: array:15 [▼
    0 => {#4196 ▼
      +"business_location_name": "Video Game"
      +"location_id": 18
      +"product_id": 513
      +"product_name": "موتوسيكل"
      +"variation_id": 661
      +"quantity": "1.0000"
      +"total": "15.00000000"
    }
    1 => {#4202 ▼
      +"business_location_name": "Video Game"
      +"location_id": 18
      +"product_id": 517
      +"product_name": "هزازات"
      +"variation_id": 665
      +"quantity": "1.0000"
      +"total": "10.00000000"
    }
    2 => {#4203 ▼
      +"business_location_name": "Video Game"
      +"location_id": 18
      +"product_id": 520
      +"product_name": "هدايا كبيرة"
      +"variation_id": 668
      +"quantity": "1.0000"
      +"total": "20.00000000"
    }
    3 => {#4197 ▼
      +"business_location_name": "Gaming Area"
      +"location_id": 19
      +"product_id": 526
      +"product_name": "سيارات تصادم (مايكل)"
      +"variation_id": 674
      +"quantity": "24.0000"
      +"total": "480.00000000"
    }
    4 => {#4176 ▼
      +"business_location_name": "Gaming Area"
      +"location_id": 19
      +"product_id": 527
      +"product_name": "سامبا (مايكل)"
      +"variation_id": 675
      +"quantity": "2.0000"
      +"total": "40.00000000"
    }
    5 => {#4201 ▼
      +"business_location_name": "Gaming Area"
      +"location_id": 19
      +"product_id": 528
      +"product_name": "قطار اطفال (مايكل)"
      +"variation_id": 676
      +"quantity": "4.0000"
      +"total": "40.00000000"
    }
    6 => {#4199 ▼
      +"business_location_name": "Lavandula Gym"
      +"location_id": 17
      +"product_id": 594
      +"product_name": "جم رجال يومى ع.د"
      +"variation_id": 742
      +"quantity": "1.0000"
      +"total": "30.00000000"
    }
    7 => {#4204 ▼
      +"business_location_name": "Lavandula Gym"
      +"location_id": 17
      +"product_id": 598
      +"product_name": "جم رجال شهرى ق.م"
      +"variation_id": 746
      +"quantity": "1.0000"
      +"total": "350.00000000"
    }
    8 => {#4205 ▼
      +"business_location_name": "Tiba Rose Gym"
      +"location_id": 16
      +"product_id": 615
      +"product_name": "رسم استخراج كارنيه اول مره"
      +"variation_id": 763
      +"quantity": "5.0000"
      +"total": "50.00000000"
    }
    9 => {#4206 ▼
      +"business_location_name": "Tiba Rose Gym"
      +"location_id": 16
      +"product_id": 688
      +"product_name": "جم رجال يومى ع.د"
      +"variation_id": 836
      +"quantity": "2.0000"
      +"total": "70.00000000"
    }
    10 => {#4207 ▼
      +"business_location_name": "Tiba Rose Gym"
      +"location_id": 16
      +"product_id": 690
      +"product_name": "جم رجال يومى مدنى"
      +"variation_id": 838
      +"quantity": "1.0000"
      +"total": "85.00000000"
    }
    11 => {#4208 ▼
      +"business_location_name": "Tiba Rose Gym"
      +"location_id": 16
      +"product_id": 691
      +"product_name": "جم رجال شهرى ع.د"
      +"variation_id": 839
      +"quantity": "3.0000"
      +"total": "750.00000000"
    }
    12 => {#4209 ▼
      +"business_location_name": "Tiba Rose Gym"
      +"location_id": 16
      +"product_id": 692
      +"product_name": "جم رجال شهرى ق.م"
      +"variation_id": 840
      +"quantity": "1.0000"
      +"total": "450.00000000"
    }
    13 => {#4210 ▼
      +"business_location_name": "Subscriptions"
      +"location_id": 20
      +"product_id": 763
      +"product_name": "حجزملعب س/ط س ن"
      +"variation_id": 911
      +"quantity": "4.0000"
      +"total": "560.00000000"
    }
    14 => {#4211 ▼
      +"business_location_name": "Subscriptions"
      +"location_id": 20
      +"product_id": 773
      +"product_name": "العاب ثابته"
      +"variation_id": 921
      +"quantity": "2.0000"
      +"total": "20.00000000"
    }
  ]
}

then I make this foreach loop to generate one array with the comparison

foreach($results_day_report as $result_day_report)
    {
        array_push($queries, (object)[
                'business_location_name' => $result_day_report->business_location_name,
                'location_id' => $result_day_report->location_id,
                'product_id' => $result_day_report->product_id,
                'product_name' => $result_day_report->product_name,
                'variation_id' => $result_day_report->variation_id,
                
                'quantity_report_date_same_year' => $result_day_report->quantity,
                'total_report_date_same_year' => $result_day_report->total,
                
                'quantity_report_date_year_before' => 0,
                'total_report_date_year_before' => 0,
                
                'quantity_date_range_same_year' => 0, 
                'total_date_range_same_year' => 0,
                
                'quantity_date_range_year_before' => 0,
                'total_date_range_year_before' => 0,
                
                'step_a' => '1',
            ]);
    }
    foreach($results_day_report_year_before as $result_day_report_year_before)
    {
        $collection = collect($queries);
        if(!$collection->contains('variation_id', $result_day_report_year_before->variation_id))
        {
            array_push($queries, (object)[
                'business_location_name' => $result_day_report_year_before->business_location_name,
                'location_id' => $result_day_report_year_before->location_id,
                'product_id' => $result_day_report_year_before->product_id,
                'product_name' => $result_day_report_year_before->product_name,
                'variation_id' => $result_day_report_year_before->variation_id,
                
                'quantity_report_date_same_year' => 0,
                'total_report_date_same_year' => 0,
                
                'quantity_report_date_year_before' => $result_day_report_year_before->quantity,
                'total_report_date_year_before' => $result_day_report_year_before->total,
                
                'quantity_date_range_same_year' => 0,
                'total_date_range_same_year' => 0,
                
                'quantity_date_range_year_before' => 0,
                'total_date_range_year_before' => 0,
                
                'step_b' => '1',
            ]);
        }
        else
        {
            $data = $collection->map(function ($item, $key) use ($result_day_report_year_before) {
                if($item->location_id == $result_day_report_year_before->location_id && $item->variation_id == $result_day_report_year_before->variation_id)
                {
                    $item->quantity_report_date_year_before = $result_day_report_year_before->quantity ;
                    $item->total_report_date_year_before = $result_day_report_year_before->total ;
                    $item->step_b = 2 ;
                }
                elseif($item->location_id != $result_day_report_year_before->location_id && $item->variation_id == $result_day_report_year_before->variation_id)
                {
                    array_push($queries, (object)[
                        'business_location_name' => $result_day_report_year_before->business_location_name,
                        'location_id' => $result_day_report_year_before->location_id,
                        'product_id' => $result_day_report_year_before->product_id,
                        'product_name' => $result_day_report_year_before->product_name,
                        'variation_id' => $result_day_report_year_before->variation_id,
                        
                        'quantity_report_date_same_year' => 0,
                        'total_report_date_same_year' => 0,
                        
                        'quantity_report_date_year_before' => $result_day_report_year_before->quantity,
                        'total_report_date_year_before' => $result_day_report_year_before->total,
                        
                        'quantity_date_range_same_year' => 0,
                        'total_date_range_same_year' => 0,
                        
                        'quantity_date_range_year_before' => 0,
                        'total_date_range_year_before' => 0,
                        
                        'step_b' => '3',
                    ]);
                }
                return $item;
            });
            
        }
    }

Now the result of final array ($queries) will be

enter image description here

This result isn't correct, the correct answer must be array with 34 object not 33 object Error at step of array push which contain 'step_b' => '3' , it return null not correct object

What's the problem ?



via Chebli Mohamed