EMfinanga

Member Since 1 Year Ago

Experience Points
10,320
Total
Experience

4,680 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.

  • Community Pillar

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

Level 3
10,320 XP
Jan
12
5 days ago
Activity icon

Replied to Count In Collection

yes, how can i get the result like that

Activity icon

Replied to Count In Collection

@tray2

I have the sql query like this but return

               $data=DB::select(
                  DB::raw("SELECT
                (select count(*) from devices where devices.id=issue_to_sales.unit_id and devicetype=1) as master,
                (select count(*) from devices where devices.id=issue_to_sales.unit_id and devicetype=2) as slave
                FROM issue_to_sales where issue_no='$issue_no'"));

dd()

          array:3 [▼
          0 => {#1454 ▼
            +"master": 1
            +"slave": 0
          }
          1 => {#1451 ▼
            +"master": 0
            +"slave": 1
          }
          2 => {#1447 ▼
            +"master": 1
            +"slave": 0
          }
        ]
Activity icon

Started a new Conversation Count In Collection

My query does not count correect, in the device table i have column devicetype which differentiate unit_id

so i want to count unit_id from issue_to_sale table so in this issue_no=IBCH2112200002 it contain slave=1 and master=2 but on the dd(data1) return wrong

result after dd()

         #items: array:1 [▼
0 => {#1479 ▼
  +"issue_no": "IBCH2112200002"
  +"team_name": "TEAM IT"
  +"req_by": "Innocent Lema"
  +"TotalALL": 3
  +"master": 3
  +"slave": null
}

]

my controller

       $data1=DB::table('issue_to_sales')
                                        ->SELECT('issue_no','teams.team_name as team_name','users.name as req_by',DB::raw('count(unit_id) as TotalALL'),DB::raw('(select count(unit_id) from devices where devices.id=issue_to_sales.unit_id and devicetype=1) as master'),DB::raw('(select count(unit_id) from devices where devices.id=issue_to_sales.unit_id and devicetype=2) as slave'))
                                        ->leftJoin("teams", "teams.id","=","issue_to_sales.team_id")
                                        ->leftJoin("users", "users.id","=","issue_to_sales.req_by")
                                        ->leftJoin("devices", "devices.id","=","issue_to_sales.unit_id")
                                           ->where('issue_no',$issue_no)
                                              ->groupBy('issue_no')
                                           ->get();

how can get this result

          +"issue_no": "IBCH2112200002"
  +"team_name": "TEAM IT"
  +"req_by": "Innocent Lema"
  +"TotalALL": 3
  +"master": 2
  +"slave": 1
Jan
11
6 days ago
Activity icon

Replied to How To Avoid Duplicates Entry

yes,it works now i was forget to add user_id to model thanks

Activity icon

Replied to How To Avoid Duplicates Entry

sorry both are return $userId=Auth::user()->id; = 7 ,

               dd($request->user()->id); = 7
Activity icon

Replied to How To Avoid Duplicates Entry

does not duplicate now but $request->user()->id still insert 0 instead of current user_id

Activity icon

Replied to How To Avoid Duplicates Entry

where is this $value

             ['unit_id' => $value, 'status' => 0], or i can use `$id`?
Activity icon

Started a new Conversation How To Avoid Duplicates Entry

I tried this code my it duplicate data when i click button twice or more and "user_id"=>$request->user()->id, insert as 0 instead of user->id

Kindly where i did wrong

                $idsString=$request->input('ids');
                $idsArray=explode(",",trim($idsString,','));

          foreach ($idsArray as $value) {
                    Mystock::where('status',0)->updateOrCreate(array(
                        
                              "unit_id"=>$value,
                              "team_id"=>$request->user()->team_id,
                              "user_id"=>$request->user()->id,
                          ));
              

              Issue_to_sale::whereIn('unit_id',$idsArray)
                  ->update([
                     'ack_status'=>1,
                    ]);

                      }
Jan
08
1 week ago
Activity icon

Replied to How To Save Two Different Data In One Column.

@michaloravec thanks very much, it works when you have unit_id and slave_id

but when slave_id =null it get this error

              Integrity constraint violation: 1048 Column 'unit_id' cannot be null

suppose you have like this

                     id   billno        unit_issue_id  slave_id 
                     1      A001            2                 NULL
Activity icon

Replied to How To Save Two Different Data In One Column.

@tisuchi , but i dont have this slave_id column in the second table as you can see my structure above.

Activity icon

Started a new Conversation How To Save Two Different Data In One Column.

I have the table like this

                id   billno        unit_issue_id  slave_id 
                 1      A001            2                 100
                 1      A001            2                 101
                  1      A001            2                 102

I want to select billno=A001 and takes unit_issue_id and slave_id into another table

            unit_id     user_id  team_id
              2               2               7
              100               2               7
               101              2               7
                102              2               7

I tried the following code but it insert only slave_id instead of unit_issue_id and slave_id

             public function cancel_bill_cash_store(Request $request){

                    $selectdata= Sales::select('unit_issue_id','slave_id')
                                      ->where('bill_number',$request->bill_number)->get();

                       foreach ($selectdata as  $value) {

                   
                      $data= New Mystock;
                      $data->unit_id=$value->unit_issue_id;
                      $data->unit_id=$value->slave_id;

                      $data->user_id=Auth::user()->id;
                      $data->team_id=Auth::user()->team_id;
                      $data->save();

               //        $data2= New Mystock;
               //        $data2->user_id=Auth::user()->id;
               //        $data2->team_id=Auth::user()->team_id;
               //        $data2->save();
       
                      
                       }

Kindly can you help me,

Jan
06
1 week ago
Activity icon

Started a new Conversation Create Array With Array In Database

In my code the slave_ID is save one instead of 2 slave_ID

dd($data)

  array =[
              'unit_id'=2

        'slave_ID' =>array=[
                      '0'=67,  
                      '1'=67,    
                      ]
          ]

but it insert one, slave_ID instead of two array

am expect to insert all requested slave_ID, and if not, then insert unit_id

             $data2 = [

                          'bill_number' => $bill_number,
                              'user_id'=>Auth::user()->id,
                              'tag_id'=>Auth::user()->team_id,
                             // 'client_id'=>$request->client_name,
                             'unit_issue_id'=>$request->unit_id,
                             'client_id'=>$request->customer_name,
                             // 'TruckNo_id'=>$request->customer_truck_number,
                             'borderName'=>$request->borderName,
                             'tag_area'=>$request->tag_area,
                             'cargo_type'=>$request->cargo_type,
                             'subT1'=>$request->subT1,
                             'comments'=>$request->comment,
                             'container_no'=>$request->container_no,
                             'sale_type'=>$request->sale_type,
                             'chasisNo'=>$request->chasisNo,
                             'ITNo'=>$request->ITNo,
                             'driverName'=>$request->driverName,
                             'License'=>$request->License,
                             'driverPhone'=>$request->driverPhone,
                             'TruckNo'=>$request->TruckNo,
                             'TrailerNo'=>$request->trailerNo,
                             'created_at'=>$date,
                             'slave_id'=> ($request->has('slave_ID') && count($request->slave_ID) > 0)? count($request->slave_ID) : null,

                      ];

                     Sales::create($data2);
Jan
02
2 weeks ago
Activity icon

Replied to Error Undefined Offset: 1

@tray2 sorry sir , may be i can show via TeamViewer or zoom

Activity icon

Started a new Conversation Override Created_at

How can i save request->date instead of created_at automatically base on my condition

this is what i have tried but does not works

	   if($request->backdate !==null){

               $date=$request->backdate;
                }else{
                         //here, if not null created_at as normal(automatically)

                  }

                  $data=[
                               'created_at'=$date,
                              ]
                    Sales::create($data);
Activity icon

Replied to Update Match Row

@michaloravec , can you assist on this?

Activity icon

Replied to Error Undefined Offset: 1

unit_id can have more than one slave_id

Activity icon

Replied to Error Undefined Offset: 1

@tray2 , how can i write in a good way there

Activity icon

Replied to Update Match Row

@michaloravec , it doing the same,

Activity icon

Replied to Error Undefined Offset: 1

this 'tag_id'=>Auth::user()->team_id, is not must to update we can ignore them,

           $slave_ID=$request->get('slave_ID');

                foreach ($slave_ID as $key => $value) {
                  Sales::where('id', $request->get('sid'))
                                          ->update([
                                                  'slave_id'=>$value,
                                          ]);
                }
Activity icon

Started a new Conversation Update Match Row

I want to update the row which has input data, but in my code it update the first row instead of match row,

i don't know where i did wrong

My controller

                    elseif($request->unit_id==null){

                      $stocks = Sales::whereIn('id', $request->sid)->get();

                      // dd($stocks);

                      $slave_ID=$request->get('slave_ID');

                foreach ($slave_ID as $key => $value) {
                  Sales::where('id', $request->get('sid'))
                                          ->update([
                                                  'user_id'=>Auth::user()->id,
                                                  'tag_id'=>Auth::user()->team_id,
                                                  'slave_id'=>$value,
                                          ]);
                } 
                                          Mystock::whereIn('unit_id',$request->slave_ID)
                                                              ->update([
                                                                    "status"=>1,
                                                              ]);
       
      }

My blade view

                      @foreach($editbilldata as $data)
                @if($countslave->totalslave <=0)
                <div class="row">
                    
                </div>
                @else
                 <div class="row">
                 <input type="hidden" readonly="" value="{{$data->id}}" class="form-control" name="sid[]">

                	<div   class="form-group col-md-4">
                		<div class="input-group">
                		<span class="input-group-addon">{{$data->slaveID}}</span>
                			<select name="slave_ID[]" class=" form-control  selectpicker" multiple  data-live-search="true" >
                             
                			
                					@foreach($Slave as $key=>$dt)
                					@if($dt->deviceNumb->devicetype ==1)
                                    <option value="{{$dt->unit_id}}" >{{$dt->deviceNumb->Devicenumber}}</option>
                				@endif
                				@endforeach

                			</select>
                		</div>
                </div>

                 </div>
                @endif

                 @endforeach

kindly Help me

Activity icon

Replied to Error Undefined Offset: 1

@tykus , can help me on this?

Activity icon

Replied to Error Undefined Offset: 1

@tykus how can i compare it?

because i have this hidden <input type="hidden" readonly="" value="{{$data->id}}" class="form-control" name="sid">

am try to using like this but it does no update the specific row it update the last row while i want to update may be id=3 so it going to update id=5

               foreach ($request->slave_ID as  $value) { 
                            Sales::where('bill_number', $bill_number)
                               
                                ->where('id', $request->sid)
                                ->update([
                                        'user_id'=>Auth::user()->id,
                                        'tag_id'=>Auth::user()->team_id,
                                        'slave_id'=>$value,
                                ]);
     
           
                }

and this is the data i want to update

                   "bill_number" => "CX301220000"
                "unit_id" => null
                "sale_type" => "1"
                "sid" => array:6 [▼
                  0 => "26"
                  1 => "27"
                  2 => "28"
                  3 => "29"
                  4 => "30"
                  5 => "31"
                ]
                "slave_ID" => array:2 [▼
                  0 => "14"
                  1 => "14"
                ]
              ]
Jan
01
2 weeks ago
Activity icon

Started a new Conversation Error Undefined Offset: 1

i dont know why get this error Undefined offset: 1

My data want to update

  array:6 [▼
        "_token" => "E2tAaDFsSmktvpWulSWlr6tySyZsFOW5tVHGaDEe"
        "bill_number" => "CX301220000"
        "unit_id" => null
        "sale_type" => "1"
        "sid" => "31"
        "slave_ID" => array:2 [▼
          0 => "100"
          1 => "6"
        ]
      ]

my blade view

      @foreach($editbilldata as $data)
                @if($countslave->totalslave <=0)
                <div class="row">
                    
                </div>
                @else
                 <div class="row">
                 <input type="hidden" readonly="" value="{{$data->id}}" class="form-control" name="sid">

                	<div   class="form-group col-md-4">
                		<div class="input-group">
                		<span class="input-group-addon">{{$data->slaveID}}</span>
                			<select name="slave_ID[]" class=" form-control  selectpicker" multiple  data-live- search="true" >
                             
                			
                					@foreach($Slave as $key=>$dt)
                					@if($dt->deviceNumb->devicetype ==1)
                                    <option value="{{$dt->unit_id}}" >{{$dt->deviceNumb->Devicenumber}}</option>
                				@endif
                				@endforeach

                			</select>
                		</div>
                </div>

                 </div>
                @endif
                 @endforeach

My controller

           $stocks = Sales::where('bill_number', $bill_number)->get();
        $i=0;
            foreach ($stocks as $stock) {  
                            Sales::where('bill_number', $bill_number)
                               
                                ->where('id', $stock->id)
                                ->update([
                                        'user_id'=>Auth::user()->id,
                                        'tag_id'=>Auth::user()->team_id,
                                        'slave_id'=>$request->slave_ID[$i],
                                ]);
        $i++;
           
                }
                                Mystock::whereIn('unit_id',$request->slave_ID)
                                                    ->update([
                                                          "status"=>1,
                                                    ]);
Activity icon

Replied to Old Values Are Not Works

No, i want to edit my data, if i create wrong data

Activity icon

Started a new Conversation Old Values Are Not Works

I want to update my data, so i want to select the old() data that collection and able to change the new one and update.

this code does now show the old data but it show the new data which i can change. and if i change it works fine, but problem comes to get old data and if i want to change one of them i can update as well.

My form blade

       	</div>
                        	<div id=""  class="form-group col-md-4">
                        		<div class="input-group">
                        		<span class="input-group-addon"><span class="glyphicon glyphicon-book" aria-hidden="true"></span></span>
                        			<select name="unit_id" class=" form-control selectpicker" data-live-search="true"  >
                        				<option value=" ">[SELECT MASTER]</option>
                        					@foreach($Slave as $key=>$dt)
                        					@if($dt->deviceNumb->devicetype ==1)
                        				<option value="{{$dt->unit_id}}">{{$dt->deviceNumb->Devicenumber}}</option>
                        				@endif
                        				@endforeach

                        			</select>
                        		</div>
                        </div>
                        </div>

                        @foreach($editbilldata as $data)
                        @if($countslave->totalslave <=0)
                        <div class="row">
                            
                        </div>
                        @else
                         <div class="row">

                        	<div   class="form-group col-md-4">
                        		<div class="input-group">
                        		<span class="input-group-addon"><span class="glyphicon glyphicon-plus-sign addRow" aria-hidden="true"></span></span>
                        			<select name="slave_ID[]" class=" form-control  selectpicker" multiple data-live-search="true" >
                        			
                        					@foreach($Slave as $key=>$dt)
                        					@if($dt->deviceNumb->devicetype ==1)
                                            <option value="{{$dt->unit_id}}" {{(old('editbilldata',$data->deviceNumb->Devicenumber)) ? "selected": null}}>{{$dt->deviceNumb->Devicenumber}}</option>
                        				@endif
                        				@endforeach

                        			</select>
                        		</div>
                        </div>

                         </div>
                        @endif
                         @endforeach

My controller

             $stocks = Sales::where('bill_number', $bill_number)->get();


            $i = 0;

            foreach ($stocks as $stock) {  
                Sales::where('bill_number', $bill_number)
                    ->where('id', $stock->id)
                    ->update([
                            'user_id'=>Auth::user()->id,
                            'tag_id'=>Auth::user()->team_id,
                                         'unit_issue_id'=>$request->unit_id,
                                         'slave_id'=>$request->slave_ID[$i],
                                         // 'sale_type'=>$request->sale_type,
                    ]);

                    $i++;


                        Mystock::where('unit_id',$request->unit_id)
                                        ->update([
                                              "status"=>1,
                                        ]);

                        Mystock::whereIn('unit_id',$request->slave_ID)
                                        ->update([
                                              "status"=>1,
                                        ]);
            }

Help me on this

Dec
31
2 weeks ago
Activity icon

Replied to Invalid Argument Supplied For Foreach() In Controller

@michaloravec , i write the code well but when i save the data does not create new one it return the last bill data

i dont know what is the issue here

Activity icon

Replied to Invalid Argument Supplied For Foreach() In Controller

It works, but the problem comes if there is not slave_ID array and get this error,

        Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given, called in 

dd()

                 array:21 [▼
      "_token" => "U9nuNfzzZE3JuRfnWcTrKiiGVIdfqTQOrqCvNaCS"
      "unit_id" => "2"
      "sale_type" => "1"
      "customer_agent" => "saild"
      "payment_method" => "[PAYMENT METHOD]"
      "currency" => "1"
      "amount" => "30"
      "discount" => null
      "tag_area" => null
      "borderName" => null
      "cargo_type" => null
      "TruckNo" => null
      "trailerNo" => null
      "chasisNo" => null
      "ITNo" => null
      "container_no" => null
      "driverName" => null
      "License" => "678999977979"
      "driverPhone" => null
      "subT1" => "T466676767"
      "comment" => "OK"
    ]

in my blade

               	<select name="slave_ID[]" class=" form-control selectpicker" multiple data-live-search="true"  >
			
				@foreach($Slave as $key=>$dt)
				@if($dt->deviceNumb->devicetype ==1)
			<option value="{{$dt->unit_id}}">{{$dt->deviceNumb->Devicenumber}}</option>
			@endif
			@endforeach

		</select>

but if you check there dd() you can not see slave_ID request i dont know why is not comes, but if i select that slave_ID it comes in request

Activity icon

Replied to Invalid Argument Supplied For Foreach() In Controller

Error

    syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting '('
Activity icon

Started a new Conversation Invalid Argument Supplied For Foreach() In Controller

I want to create this data, but am get the error,

Error

     Invalid argument supplied for foreach() in Controller

My request data

       array:22 [▼
          "_token" => "U9nuNfzzZE3JuRfnWcTrKiiGVIdfqTQOrqCvNaCS"
          "unit_id" => "4"
          "sale_type" => "1"
          "customer_agent" => "ABC"
          "payment_method" => "1"
          "currency" => "1"
          "amount" => "30"
          "discount" => "5"
          "tag_area" => "DEPOT ENGINE"
          "borderName" => "1"
          "cargo_type" => "4"
          "TruckNo" => null
          "trailerNo" => null
          "chasisNo" => null
          "ITNo" => null
          "container_no" => null
          "driverName" => "FEKRR"
          "License" => "678999977979"
          "driverPhone" => "07890877"
          "subT1" => "T466676767"
          "slave_ID" => array:1 [▼
            0 => "4"
            1=> "2"
          ]
          "comment" => "wewd"
        ]

My controller

                 $slave_ID=$request->slave_ID;
    foreach ($slave_ID as  $value) {
      
           $data2=([

                           'bill_number' => $bill_number,
                              'user_id'=>Auth::user()->id,
                              'tag_id'=>Auth::user()->team_id,
                             // 'client_id'=>$request->client_name,
                             'unit_issue_id'=>$request->unit_id,
                             'customer_agent'=>$request->customer_agent,
                             'payment_method'=>$request->payment_method,
                             'borderName'=>$request->borderName,
                             'tag_area'=>$request->tag_area,
                             'cargo_type'=>$request->cargo_type,
                             'chasisNo'=>$request->chasisNo,
                             'ITNo'=>$request->ITNo,
                             'driverName'=>$request->driverName,
                             'License'=>$request->License,
                             'driverPhone'=>$request->driverPhone,
                             'subT1'=>$request->subT1,
                             'TruckNo'=>$request->TruckNo,
                             'TrailerNo'=>$request->trailerNo,
                             'container_no'=>$request->containerNo,
                             'comments'=>$request->comment,
                             'slave_id'=>$slave_ID[$value],
                             'amount'=>$request->amount,
                             'discount'=>$request->discount,
                             'sale_type'=>$request->sale_type,
                             'currency'=>$request->currency,
                 ]);
                 }
                Sales::create($data2); 

            Mystock::where('unit_id',$request->unit_id)
                            ->update([
                                  "status"=>1,
                            ]);

            Mystock::whereIn('unit_id',$request->slave_ID)
                            ->update([
                                  "status"=>1,
                            ]);

help me to correct the error

Activity icon

Replied to How To Add Sql Query In Collection

@spyworld both does not works sir

Dec
30
2 weeks ago
Activity icon

Replied to How To Add Sql Query In Collection

no, i have the column slave_id which has 0 value so i want to count this column but when i right that query it count as 1 while me am expect to count as 0 instead of 1

Activity icon

Replied to How To Add Sql Query In Collection

@faizali2152 kindly can you correct me here?

Activity icon

Replied to How To Add Sql Query In Collection

am using union but am get this error

          Cardinality violation: 1222 The used SELECT statements have a different number of columns (SQL:


                           $countSlave=DB::table('sales')->select(DB::raw('COUNT(`slave_id`) as totalslave'))
                                           ->where([
                                                 ['sale_type',2],
                                                 ['tag_id',$team]
                                                 ])
                                        ->where('slave_id','!=',0)
                                        ->groupBy('bill_number');

// dd($t);

                          $data=DB::table('sales')
                                    ->select('users.name as nametag','customers.*','teams.*','locations.*','customer__orders.*','sales.*','devices.*',\DB::raw("group_concat(devices2.Devicenumber SEPARATOR '\n') as slavename"),'sales.created_at as created_at_sale')
                                     ->leftJoin('customers','customers.id','=','sales.client_id')
                                     ->leftJoin('teams','teams.id','=','sales.tag_id')
                                     ->leftJoin('locations','locations.id','=','sales.borderName')
                                     ->leftJoin('devices','devices.id','=','sales.unit_issue_id')
                                     ->leftJoin('users','users.id','=','sales.user_id')
                                     ->leftJoin('customer__orders','customer__orders.id','=','sales.TruckNo_id')

                                     ->leftJoin("devices as devices2",\DB::raw("FIND_IN_SET(devices2.id,sales.slave_id)"),">",\DB::raw("'0'"))
                                      ->where([

                                      ['sales.sale_type',2],
                                      ['sales.tag_id',$team]
                                       ])
                                   ->union($countSlave)

                                   ->groupBy('sales.bill_number')
                                   ->get();
Activity icon

Replied to How To Add Sql Query In Collection

this is Works separately

  $countSlave=DB::table('sales')->select(DB::raw('COUNT(`slave_id`) as totalslave'))
                                           ->where([
                                                 ['sales.sale_type',2],
                                                 ['sales.tag_id',$team]
                                                 ])
                                        ->where('slave_id','!=',0)
                                        ->groupBy('bill_number')
                                ->get();
Activity icon

Started a new Conversation How To Add Sql Query In Collection

I want to to add this sql to my DB:: SELECT COUNT(slave_id) FROM salesWHEREslave_id!=0 GROUP BYbill_number`

I tried to add like this but when i run does not return any collection data, because i want to count this column slave_id

      $data=DB::table('sales')
                                    ->select('users.name as nametag','customers.*','teams.*','locations.*','customer__orders.*','sales.*','devices.*',\DB::raw("group_concat(devices2.Devicenumber SEPARATOR '\n') as slavename"),'sales.created_at as created_at_sale',\DB::raw('(SELECT COUNT(`slave_id`) FROM `sales` WHERE `slave_id` !=0 GROUP BY `bill_number`) as totalslave'))
                                     ->leftJoin('customers','customers.id','=','sales.client_id')
                                     ->leftJoin('teams','teams.id','=','sales.tag_id')
                                     ->leftJoin('locations','locations.id','=','sales.borderName')
                                     ->leftJoin('devices','devices.id','=','sales.unit_issue_id')
                                     ->leftJoin('users','users.id','=','sales.user_id')
                                     ->leftJoin('customer__orders','customer__orders.id','=','sales.TruckNo_id')

                                     ->leftJoin("devices as devices2",\DB::raw("FIND_IN_SET(devices2.id,sales.slave_id)"),">",\DB::raw("'0'"))
                                      ->where([

                                      ['sales.sale_type',2],
                                      ['sales.tag_id',$team]
                                       ])
                                   ->groupBy('sales.bill_number')->get();
Dec
28
2 weeks ago
Activity icon

Started a new Conversation Return Multiple Variables To Ajax

I want to return two variable in my blade i have tried this but dont get the data

                     $data=DB::table('my_stocks')
              ->select('devices.*','users.*','teams.*','my_stocks.*','my_stocks.created_at as created_at')
             ->join('devices', 'devices.id','=','my_stocks.unit_id')
             ->join('users', 'users.id','=','my_stocks.user_id')
             ->join('teams', 'teams.id','=','my_stocks.team_id')
             ->where([
             ['my_stocks.team_id',$team],
               ['my_stocks.status',0]
             ])->get();

      $countDevice=MyStock::with('deviceNumb','team','user')
             ->where([
               ['user_id',$team],
               ['status',0]
             ])->count();

     return response()->json(['data'=>$data, 'countDevice'=>countDevice])

but does not works,

Dec
19
4 weeks ago
Activity icon

Awarded Best Reply on Syntax Error, Unexpected 'if' (T_IF)

am got the answer sir no worries :)

        foreach($data as $row)
   {
 $printbill='/api/sales_bill_info/'.$row->bill_number;
    $cancelbill='/cancel_bill_cash/'.$row->bill_number;
    $referbill='/editbill/'.$row->bill_number;

    if($row->activated_status == 1)
    {
     $activatestatus='<button class="btn-xs">ACTIVATED</button>';
    }
    else{
         
        }
Activity icon

Replied to Syntax Error, Unexpected 'if' (T_IF)

am got the answer sir no worries :)

        foreach($data as $row)
   {
 $printbill='/api/sales_bill_info/'.$row->bill_number;
    $cancelbill='/cancel_bill_cash/'.$row->bill_number;
    $referbill='/editbill/'.$row->bill_number;

    if($row->activated_status == 1)
    {
     $activatestatus='<button class="btn-xs">ACTIVATED</button>';
    }
    else{
         
        }
Activity icon

Replied to Syntax Error, Unexpected 'if' (T_IF)

is not possible to use from there ?

Activity icon

Replied to Syntax Error, Unexpected 'if' (T_IF)

i just search my data from controller and return those data in html table

Activity icon

Replied to Syntax Error, Unexpected 'if' (T_IF)

@sr57 , kindly help what is the correct syntax

Activity icon

Started a new Conversation Syntax Error, Unexpected 'if' (T_IF)

am get the error while i use if condition and url in my controller with HTML code

           $total_row = $data->count();
  if($total_row > 0)
  {
   foreach($data as $row)
   {
    $output .= '
             <tr>
                 
                 <td>'.$row->bill_number.'</td>
                 <td>'.
                    if($row->activated_status == 1)
                    .'<button class="btn-xs">ACTIVATED</button>'
                    . else.'
                  <a href="{{url('/api/sales_bill_info',$dt->bill_number)}}"  class="btn btn-info btn-xs activate_btn" id="activate_btn" data-id='.$row->bill_number.' >CONFORM ACTIVATION</a>
                   '.endif.'
                 </td>
Dec
18
4 weeks ago
Activity icon

Replied to Convert PHP Code Into Laravel Code

brother can you guide me well, kindly help me

emma4082@gmail.com

Activity icon

Started a new Conversation Convert PHP Code Into Laravel Code

this is the php code and i want to write this code in model Laravel

   <?php

                class devicesModel {

                    private $result;
                    protected $conn;
                    protected $db;

                    function __construct() {
                        $this->db = new Config();
                        $this->conn = $this->db->getConnection();
                    }

                    function verifyIfDeviceNumberValid($devicenumber) {
                        try {
                            $sqlQuery = "select id from devices where Devicenumber=$devicenumber";
                            $stmt = $this->conn->prepare($sqlQuery);
                            $stmt->execute();
                            $row2 = $stmt->fetch();
                            if (!empty($row2['id'])) {
                                return true;
                            }
                        } catch (PDOException $ex) {
                            $this->result = " Process failed unexpectedly";
                        }
                        return false;
                    }

                    function saveDeviceDetails($cartitems) {
                        try {
                            for ($i = 0; $i < count($_SESSION['verified']); $i++) {

                                $sqlQuery = "INSERT INTO `cartitems`(`devicenumber`) VALUES(" . $_SESSION['verified'][$i] . ")";
                                $stmt = $this->conn->prepare($sqlQuery);
                                $stmt->execute();
                            }
                            return TRUE;
                        } catch (PDOException $ex) {
                            $this->result = " Process failed unexpectedly".$ex->getMessage();
                        }
                        return false;
                    }

                    //Accesors and Mutators
                    function getResult() {
                        return $this->result;
                    }

                    function setResult($result) {
                        $this->result = $result;
                    }

                }
Dec
14
1 month ago
Activity icon

Started a new Conversation Validation Form When The Input Field Is Visible And Empty

I want to validate the input which are visible here is my code

   $(document).ready(function() {

		  $('#cash_form').submit(function(e) {
		    e.preventDefault();
		    var truck = document.getElementById("truck");
		if(truck.style.visibility == "visible"){
			   if ($('#truck').is(':empty')){
		    alert("The text filed is visible !!");
		  return false; 
		}

		 }
                )}

but does not works why?

Dec
11
1 month ago
Activity icon

Replied to Apply Calculation On Controller Instead On Blade View

@michaloravec i want to find the total amount In USD and TZS all data are found the the issues here is comes as collection so i can not able to use as {{$Usd}} in my blade