jeudi 1 octobre 2020

How can I easily identify lazy loaded property in Laravel

I am developing a large web application in Laravel-5.8. It contains many lazy loaded property. Now, I want to easily identify which property is lazy loaded and stop them.

I tried to use https://github.com/derkinderfietsen/laravel-disable-lazyload package but it only shows error if it finds any lazy loaded property. But I wat to identify the property too. Can anyone suggest me a good way?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2HM7Lcp
via IFTTT

Laravel websocket not working on live server?

I am using the pusher replacement package https://beyondco.de/docs/laravel-websockets/basic-usage/starting. This package is working fine on the localhost but working on a live server giving this error.

app.js:1 WebSocket connection to 'ws://IP-Addresss:3030/app/qwerty?protocol=7&client=js&version=7.0.0&flash=false' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT

I think because the server is Linux may there is a port issue. I run laravel WebSocket server on 3030 port but didn't get any success.

The server configuration is a little bit different. They have provided different server configurations but I don't know which will suit me.

https://beyondco.de/docs/laravel-websockets/basic-usage/ssl

Please, anybody, help me to know which configuration will suit on AWS ec2 instance. we are using an IP address not redirecting to any domain name. this is a nonsecure connection.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/36oGsiE
via IFTTT

Combine Multiple rows with same value

im trying to make like

id  name    qty
1   item a   3
2   item b   9 
3   item c   7

from

id  name    qty
1   item a   1
1   item a   2
2   item b   3 
2   item b   1 
2   item b   5
3   item c   3
3   item c   4

by using codes like this

$recapout = DB::table('tb_itemsout')
->select(DB::raw('sum(tb_itemsout.qty) as qty'),'tb_itemsout.id','tb_master_item.item_name','tb_itemsout.qty')
->groupBy('tb_itemsout.','tb_master_item.item_name','tb_itemsout.qty')
->join('tb_master_item','tb_itemsout.id','tb_master_item.id')
->orderBy('tb_master_item.id_item','DESC')
->get();

but it doesnt seem to work. it keeps shows up like

this

id  name    qty
1   item a   1
1   item a   2
2   item b   3 
2   item b   1 
2   item b   5
3   item c   3
3   item c   4


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2SvEtkF
via IFTTT

how to do not update value on update function?

i want this code should not be run if user call upate route code

if($getDistanceValue * 1000 > 300){
        if($chk_ord == 0)
        {
        $order->chk_ord_vst = 1;
        }
        elseif($chk_ord != 0){
        $order->chk_ord_vst = $chk_ord + 1;
        }
        }
        elseif($getDistanceValue * 1000 <= 300 ){
            if($chk_ord >= 4){
             $order->chk_ord_vst = 2;
            }
            elseif($chk_ord == 3){
             $order->chk_ord_vst = 2;
            }
            elseif($chk_ord == 2){
             $order->chk_ord_vst = 1;
            }
            elseif($chk_ord <= 1){
             $order->chk_ord_vst = 0;
            }   
        }

i am using a same fucntion to update or store order but on update i donot want to run above code i know it is very simple but i am a student and learning help me here it is controller function first user create order the if wants to update then we use get function to pass value to edit view and then pass again to stor function

public function storeOrder(Request $request , $update = null , $customer_id){

    $order = !is_null($update) ? Order::find($update) : new Order();
    
    $cus_det = explode("-", $request->customer_id);

    $tt_amount = array_sum($request->amount) + $request->old_balance;
    if(is_null ($update))
    $balance = $tt_amount + $request->old_balance;
   
    $auth_id = Auth::id();
    if(Auth::user()->role == 4){
        $auth_id = Customer::where('user_id', $auth_id)->first()->created_by;
    }

    $order->customer_id = $cus_det[0];
    $order->user_id = Auth::id();
    $order->ot_id = !is_null($update) ? $order->ot_id : $auth_id;
    $order->unit = array_sum($request->unit);
    $order->amount = $tt_amount;
    $order->subtotal = array_sum($request->amount);
    $order->order_comments  = $request->order_comments;
    
    if( Auth::user()->role == 5){
        $order->location_url_ot = $request->location_url_ot;
    $order->received_amount = 0;
    }
    else{
        $order->received_amount = $request->received_amount;
        
    }
    $order->discount = $request->discount;
    $order->order_date= date('Y/m/d', strtotime($request->order_date));
    if($tt_amount >= $request->received_amount){
        $order->amount_left = ($tt_amount -  $request->received_amount - $request->discount);
    }
    else{
        $order->advance = $request->received_amount - $tt_amount;
        $order->amount_left = $request->old_balance -  $request->received_amount - $request->discount;
    }
    
    $checkB = $this->checkMinBalance($cus_det[0] , $order->amount_left);
    if($checkB){
        return redirect()->back()->with('error' , 'Customer Balance Limit Exceeded ( Limit is '.$checkB.' )');
    }
    if($request->has('important')){
        $order->is_important=1;
    }
    
     if($request->has('urgent')){
        $order->urgent = urgent ;
    }
    $getothomDistanceValue = ($this->getothomDistance($order) * 1.37);
    
    $getDistanceValue = ($this->getDistance($order) * 1.37);
    
    
    $old_order = Order::where('customer_id' , $order->customer_id)->orderBy('id' , 'desc')->get();
      $chk_ord = $old_order[0]->chk_ord_vst; 

    if($getDistanceValue * 1000 > 300){
        if($chk_ord == 0)
        {
        $order->chk_ord_vst = 1;
        }
        elseif($chk_ord != 0){
        $order->chk_ord_vst = $chk_ord + 1;
        }
        }
        elseif($getDistanceValue * 1000 <= 300 ){
            if($chk_ord >= 4){
             $order->chk_ord_vst = 2;
            }
            elseif($chk_ord == 3){
             $order->chk_ord_vst = 2;
            }
            elseif($chk_ord == 2){
             $order->chk_ord_vst = 1;
            }
            elseif($chk_ord <= 1){
             $order->chk_ord_vst = 0;
            }
            
            
        }

    $order->save();

    // set order if update is null
    if(is_null($update)){
        
        $getDistanceValue = ($this->getDistance($order) * 1.37);
        $succ = Order::where('id', $order->id)->update(['ot_customer_distance'=> $getDistanceValue]);
        
    }
    
    $order_id = $order->id;
    
    if(!is_null($update))
        $order->orderdetail()->delete();
    
    $orderData = $request->all();
    $total_ot_benefit = 0; $total_customer_benefit = 0;$p_amount = 0;
    for($counter = 0;$counter < sizeof($request->amount);$counter++){
        if(!empty($orderData['amount'][$counter]))
        {
            $orderDetails = new OrderDetail();
            $orderDetails->order_id = $order_id;
            $is_custom_price = CustomPrice::where(['customer_id' => $cus_det[0] , 'product_id' => $orderData['product_id'][$counter]])->first();
            
            $is_custom_ot_benefit = CustomOtBenefit::where(['ot_id' => $order->ot_id , 'product_id' => $orderData['product_id'][$counter]])->first();
            $is_default_price = Product::find($orderData['product_id'][$counter]);
           
            if($is_custom_price){
                $orderDetails->ot_benefit = (string)bcmul($is_custom_price->ot_benefit, $orderData['unit'][$counter]);
                $orderDetails->c_benefit = (string)bcmul($is_custom_price->c_benefit, $orderData['unit'][$counter]);
                $orderDetails->p_amount = (string)bcmul($is_custom_price->product->p_price, $orderData['unit'][$counter]);
            }
            else{
                $orderDetails->c_benefit = (string)bcmul($is_default_price->c_benefit, $orderData['unit'][$counter]);
                $orderDetails->p_amount = (string)bcmul($is_default_price->p_price, $orderData['unit'][$counter]);
                $orderDetails->ot_benefit = (string)bcmul($is_custom_ot_benefit->ot_benefit, $orderData['unit'][$counter]);
                
            }
            // exit;
            $orderDetails->product_id = $orderData['product_id'][$counter];
            $orderDetails->unit = $orderData['unit'][$counter];
            $orderDetails->amount = $orderData['amount'][$counter];
            $orderDetails->save();
        }
    }
  
    Order::where('id' , $order_id)->update(['ot_benefit' => (string)$order->orderdetail->sum('ot_benefit') , 'c_benefit' => (string)$order->orderdetail->sum('c_benefit') , 'p_amount' => $order->orderdetail->sum('p_amount')]);
    if(Auth::user()->role == 4){
        return redirect()->back()->with('success', 'Order Placed Successfully!');
    }

    return redirect()->route('unconfirmed.orders')->with('success' , 'Order Created');

}

public function getOrder($id){
    $added = [];
    $order = Order::find($id);
    $customPrices = CustomPrice::where('customer_id' , $order->customer_id)->get();
    
    if(sizeof($customPrices)){
        foreach($order->orderdetail as $d){
            foreach($customPrices as $custom){
                if($custom->product_id == $d->product_id){
                    $d->product->price = $custom->price;
                    $d->product->c_benefit = $custom->c_benefit;
                }
            }
            $added[] = $d->product_id;
        }
    }
    if(Auth::user()->role == 5)
        $user_id = Auth::user()->ot_of;
    else if(Auth::user()->role == 3)
        $user_id = Auth::user()->seller_of;
    else
        $user_id = Auth::user()->id;
    $products = Product::whereNotIn('id' , $added)->where('user_id' , $user_id)->get();
    foreach($products as $product){
        foreach($customPrices as $custom){
            if($custom->product_id == $product->id){
                $product->price = $custom->price;
                $product->c_benefit = $custom->c_benefit;
            }
        }
    }
      $old_order = Order::where('customer_id' , $order->customer_id)->orderBy('id' , 'desc')->get();
      $amount_left=$old_order[0]->amount_left - $old_order[0]->subtotal + $old_order[0]->received_amount + $old_order[0]->discount; 
     
    $old_balance = 0;
    if(sizeof($old_order) > 1){
        $old_balance = $old_invoices[1]->amount_left;
    }
    return view('orders.edit' , compact('order' , 'products' , 'old_balance','amount_left' , 'discount'));
}


public function updateOrder(Request $request , $id){
     $request->hid;
    $conditions = ['id' => $id];
    $order = Order::where($conditions)->get();
     $request->amount;
    if(sizeof($order)){
        if($request->amount_left_input){
            $amount_left = $order[0]->amount_left + $order[0]->received_amount + $order[0]->discount;
            
            $order = Order::where($conditions)
            ->update(['amount_left' => $amount_left - $request->amount_left_input + $order[0]->received_amount,
             'received_amount' => $order[0]->received_amount + $order[0]->discount,
             'discount' => $order[0]->discount + $request->amount_left_input,  'chk_ord_vst' => $request->chk_ord_vst,
             
            ]
            );
            return Common::Message("Order" , 2);
    }
    
    else{
         
        Order::where('id' , $id)->update(['amount_left' => $order[0]->amount_left + $order[0]->received_amount , 'received_amount' => $order[0]->received_amount + $order[0]->discount , 'discount' => $order[0]->discount + $request->amount_left_input , 'urgent' => $request->urgent , 'location_url_ot' => $request->location_url_ot , 'chk_ord_vst' => $request->chk_ord_vst , ]);
        $this->storeOrder($request , $order[0]->id);
        
        

        return redirect()->route('unconfirmed.orders')->with('success' , 'Order Updated');
        }
    }
    else{
        return Common::Message("Order");
    }
}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2GeDoLe
via IFTTT

i want to resize single image to multiple resolution and store in diffrent folder in laravel

I want to crop and resize image and save into multiple folder. But only single image is saving in folder(firstone) Please fix this need help urgent...

public function update(Request $request)
{
      $image = $request->file('file');
      $name = time().''.mt_rand(100, 200).'_1280x768.'.$image->getClientOriginalExtension();
      $name1 = time().''.mt_rand(100, 200).'_320x240.'.$image->getClientOriginalExtension();
      $image1= $image->move('public/storage/uploadimage/main', $name);
      $image2= $image->move('public/storage/uploadimage/thumb', $name1);



      $img = Image::make($imagename);
      $img->fit(1280, 768, function ($constraint) {
          $constraint->upsize();
      });
      $img->insert('https://kafesta.com/public/images/kafesta-10.png', 'center');
      $img->save($imagename);

      $img1 = Image::make($imagename1);
      $img1->fit(320, 240, function ($constraint) {
          $constraint->upsize();
      });
      $img1->insert('https://kafesta.com/public/images/kafesta-10.png', 'center');
      $img1->save($imagename1);

}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2GfUV5J
via IFTTT

How to fix incorrect naming when importing goods

Good day to all The task was to import goods from the 1C program for accounting to the site Faced with the problem of incorrect generation of the name on the site At the moment the site displays the name as Cover-battery WK-DESIGN WP-020 iphone 7 (golden)

And it should be so Cover battery for iPhone 7 WK-DESIGN WP-020 (golden) 2400 mAh

Here is a piece of code from the xml file that appears when exchanging data between the server and 1C

<Описание>Накладка-аккумулятор WK-DESIGN WP-020 iphone 7 (золотистый)</Описание> !!!!
                <ЗначенияСвойств>
                    <ЗначенияСвойства>
                        <Ид>548370ee-3a90-11e3-9566-00144f9b870d</Ид>
                        <Значение>WK-DESIGN</Значение>                          !!!
                    </ЗначенияСвойства>
                    <ЗначенияСвойства>
                        <Ид>548370f0-3a90-11e3-9566-00144f9b870d</Ид>
                        <Значение>Аксессуары</Значение>
                    </ЗначенияСвойства>
                    <ЗначенияСвойства>
                        <Ид>548370f2-3a90-11e3-9566-00144f9b870d</Ид>
                        <Значение>WP-020</Значение>                             !!!
                    </ЗначенияСвойства>
                    <ЗначенияСвойства>
                        <Ид>548370f4-3a90-11e3-9566-00144f9b870d</Ид>
                        <Значение>Чехол</Значение>
                    </ЗначенияСвойства>
                    <ЗначенияСвойства>
                        <Ид>33432d98-3b06-11e3-9566-00144f9b870d</Ид>
                        <Значение>Чехол аккумулятор для iPhone 7 WK-DESIGN WP-020 </Значение>
                    </ЗначенияСвойства>
                    <ЗначенияСвойства>
                        <Ид>c6ed7052-3e67-11e3-9567-00144f9b870d</Ид>
                        <Значение>(золотистый) 2400 mAh</Значение>              !!!
                    </ЗначенияСвойства>
                    <ЗначенияСвойства>
                        <Ид>18faa0b4-de76-11e6-80ff-d017c2adc088</Ид>
                        <Значение>Да</Значение>
                    </ЗначенияСвойства>
                    <ЗначенияСвойства>
                        <Ид>ba09b430-334a-11e7-8102-d017c2adc088</Ид>
                        <Значение>Золотистый</Значение>
                    </ЗначенияСвойства>
                </ЗначенияСвойств>

Here is the import method in php file

protected function product()
    {
        $name = $this->importProduct->Наименование;

        foreach ($this->importProduct->ЗначенияРеквизитов->ЗначениеРеквизита as $item) {
            switch ($item->Наименование){
                case 'Вес':
                    $weight = $item->Значение;
                    break;
                case 'ВесБрутто':
                    $grossWeight = $item->Значение;
                    break;
                case 'Ширина':
                    $width = $item->Значение;
                    break;
                case 'Длина':
                    $length = $item->Значение;
                    break;
                case 'Высота':
                    $height = $item->Значение;
                    break;
                case 'Доп Характеристика':
                    $attr = $item->Значение;
                    break;
                case 'НовыйТовар':
                    $is_new = $item->Значение == 'Нет' ? 0 : 1;
                    break;
                
            }
        }

        if (! $this->importProduct->{'Группы'}) {
            Log::info('empty_groups');
            return false;
        }

        $this->product = Product::updateOrCreate([
            'id_1c' => $this->importProduct->Ид,
        ], [
            'name' => trim($name),
            'category_id'   => $this->getCategoryId(),
            'weight'        => $weight ?? '',
            'grossWeight'   => $grossWeight ?? '',
            'width'         => $width ?? '',
            'length'        => $length ?? '',
            'height'        => $height ?? '',
            'attr'          => $attr ?? '',
            'is_new'        => $is_new ?? '',
        ]);

        if (!$this->product->description) {
            $this->product->update(['description' => $this->importProduct->Описание]);
        }

        return true;
    }


Maybe someone knows or has encountered a similar problem, I will be grateful for any information



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3l0MdHp
via IFTTT

How to check a specific data exists in an array of data

$vehicleNo=strip_tags(trim(Input::get('vehcleNumber1'))) . '-' . strip_tags(trim(Input::get('vehcleNumber2')));

its an vehicle no typed in textfield and i want to check this data already exist in $vehicles(array of data of vehicles no) or not

$date = Carbon::today()->subDays(1);
$vehicles = Customer_details::select('vechicle_no')->where('branch_id',$branchId)
           ->where( 'entry_date', '>=', $date)
           ->get()->toArray();


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/36o0KZO
via IFTTT