Member Since 1 Year Ago
3,780 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
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.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Earned once your experience points ranks in the top 10 of all Laracasts users.
@wazirhashmi@yahoo.com , where did i get my app password because am using gmail
Started a new Conversation How To Get Collection Without Duplicates In Laravel
how can i select my collection without duplication data
$data = DB::table('sales')
->select('users.name as nametag','teams.*','locations.*','sales.*','devices.*',\DB::raw("group_concat(devices2.Devicenumber SEPARATOR '\n') as slavename"),'sales.created_at as created_at_sale',\DB::raw('COUNT(slave_id ) as totalslave'))
// ->leftJoin('customers','customers.id','=','sales.client_id')
->leftjoin('teams','teams.id','=','sales.tag_id')
->leftJoin('users','users.id','=','sales.user_id')
->leftjoin('locations','locations.id','=','sales.borderName')
->leftjoin('devices','devices.id','=','sales.unit_issue_id')
->leftjoin("devices as devices2",\DB::raw("FIND_IN_SET(devices2.id,sales.slave_id)"),">",\DB::raw("'0'"))
->where([
['sales.sale_type',1],
['sales.tag_id',$team]
])
->groupBy('sales.bill_number')
->orderBy('sales.created_at', 'DESC')
->DISTINCT()
->get();
i tried like this but does not works
Devicenumber
and other details are duplicate with different bill_number
Started a new Conversation Select2 Basic Example Not Working
js-example-basic-single
does not works when i want to add append div, but in html it works well.
<script type="text/javascript">
$(document).ready(function() {
$(".js-example-basic-single").select2();
});
$('.addRow').on('click',function(){
addRow();
});
function addRow()
{
var div=
'<div class="form-group ">'+
'<div class="input-group">'+
'<span class="input-group-addon remove3"><span class="glyphicon glyphicon-minus-sign" aria-hidden="true"></span></span>'+
'<select name="slave_ID[]" class="form-control js-example-basic-single" required="" data-live-search="true">'+
'<option value=" ">[SELECT SLAVE]</option>'+
'@foreach($Slave as $key=>$dt)'+
'@if($dt->devicetype ==2)'+
'<option value="{{$dt->unit_id}}">{{$dt->Devicenumber}}</option>'+
'@endif'+
'@endforeach'+
'</select>'+
'</div>'+
'</div>' ;
$('#slaveID').append(div);
};
$('.remove').live('click',function(){
var last=$('#tdy tr').length;
if(last==1){
alert("you can not remove last row");
}
else{
$(this).parent().parent().remove();
}
});
what could be the error here, kindly help me
Replied to How To Show Multiple Selected Data While Editing In Drop Down
@apexleo ,
can we show selected value without to compare it,
because this query can not compare with selected value because the unit_id
has not found due to its status is 1 while unselected value has the status =0
Replied to How To Show Multiple Selected Data While Editing In Drop Down
@apexleo , can i show my data please?
Replied to How To Show Multiple Selected Data While Editing In Drop Down
am get the error
in_array() expects parameter 2 to be array,
Started a new Conversation How To Show Multiple Selected Data While Editing In Drop Down
I want to display selected items on my edit form, i have tried to on my code below but did not show selected items but i can see unselected items.
My controller.
$Slave = DB::table('my_stocks')->leftjoin('devices', 'devices.id','=','my_stocks.unit_id')->where('my_stocks.status',0)->get();
$bill2 = DB::table('sales')->WHERE('sale_type', 1)->WHERE("sales.bill_number", $bill_number)->get();
My blade view
@if($bill->slave_id)
@foreach($bill2 as $data)
<div id="box6" class="form-group col-md-4 ">
<div class="input-group">
<span class="input-group-addon">SLAVE</span>
<select name="slave_ID[]" class="form-control" data-live-search="true" >
<option value="" >[SELECT SLAVE]</option>
@foreach($Slave as $key=>$dt)
@if($dt->devicetype ==2)
<option value="{{$dt->unit_id}}" @if($dt->unit_id == $data->slave_id) selected="true" @endif>{{$dt->Devicenumber}}</option>
@endif
@endforeach
</select>
</div>
</div>
@endforeach
@endif
Started a new Conversation How To Pass Two Variable To Generate The QrCode
am using the Package to generate the qr code , i want to pass two or more variable to generate it,
this is what am tried but get the error, someone can help me
file_put_contents(2002503476 2002503326): failed to open stream: No such file or directory (View: C:\xampp\htdocs\equalpoint\resources\views\sales\printreceiptcredit.blade.php)
My blade view
<?php $master=$billsale->Devicenumber; $slave=$billsale->slavename;?>
<td style="text-align: center;"> {!! QrCode::size(70)->generate( $master, $slave); !!}</td>
Replied to How To Generate Qrcode In My Blade
i tried like this it works when i pass one variable $master
but when i put two variable am get this error
file_put_contents(2002503476 2002503326): failed to open stream: No such file or directory (View: C:\xampp\htdocs\equalpoint\resources\views\sales\printreceiptcredit.blade.php)
my blade code
<?php $master=$billsale->Devicenumber; $slave=$billsale->slavename;?>
<td style="text-align: center;"> {!! QrCode::size(70)->generate( $master,$slave ); !!}</td>
Started a new Conversation How To Generate Qrcode In My Blade
i have the controller which return data
so i want to create Qr code, in my blade view
My controller
public function print_sales_bill_credit($bill_number){
// sorry can you wait 1 sec pls
$billsale=DB::table('sales')
->leftJoin('customers','customers.id','=','sales.client_id')
->leftJoin('teams','teams.id','=','sales.tag_id')
->leftJoin('users','users.id','=','sales.user_id')
->leftJoin('locations','locations.id','=','sales.borderName')
->leftJoin('devices','devices.id','=','sales.unit_issue_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.bill_number',$bill_number]
])
->first(['customers.*','users.*','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("count(*) as totalslave")]);
// return json_encode(array('data'=>$billsale));
$result_arr = array();
array_push($result_arr, $billsale);
return view('sales.printreceiptcredit',compact('result_arr'));
}
my blade view
<table cellspacing="0">
@if($billsale->slavename ==null)
<tr>
<td>Master#</td>
<td>:</td>
<td></td>
<td style="text-align:right"><h4><strong>{{$billsale->Devicenumber}}</strong></h4></td>
</tr>
@else
<tr>
<td>Master#</td>
<td>:</td>
<td style="text-align:right" ><h4><strong>{{$billsale->Devicenumber}}</strong></h4></td>
</tr>
<tr>
<td>Slaves#</td>
<td>:</td>
<td style="width:12px">*{{$billsale->slavename}}</td>
</tr>
@endif
</table>
so i want to create my qr code with {{$billsale->slavename}}
and {{$billsale->Devicenumber}}
am installed this Packaged in my project but i did not managed to make the qr code.
composer require simplesoftwareio/simple-qrcode
Replied to Pass Data-id Into A Controller
@ep!sode yes i mean that
also you can see this line in above code
if(data[count].untag_status == "1")
{
var received_btn='<button class="btn-xs">RECEIVED</button>';
}
else
{
received_btn='<a class="btn btn-success btn-xs activate_btn" id="activate_btn" data-id='+data[count].bill_number+' >RECEIVE</a>';
}
Started a new Conversation Pass Data-id Into A Controller
I have display my data well, but i want to takes data-id
and pass to controller , i tried like this but does not works,
Kindly can you help me where i did wrong
$(document).ready(function(){
fetch_bill_data();
function fetch_bill_data(query = '')
{
$.ajax({
url:"{{route('intransit.unit') }}",
method:"POST",
data:{query:query,
_token:'{{ csrf_token() }}'
},
dataType:'json',
success:function(data)
{
console.log(data);
var output = '';
var amount=0;
var i=1;
for(var count = 0; count < data.length; count++)
{
if(data[count].untag_status == "1")
{
var received_btn='<button class="btn-xs">RECEIVED</button>';
}
else
{
received_btn='<a class="btn btn-success btn-xs activate_btn" id="activate_btn" data-id='+data[count].bill_number+' >RECEIVE</a>';
}
output += '<tr style="font-size:0.78em;">';
output += '<td>' + i++ + '</td>';
output += '<td>'+received_btn+'</td>';
output += '<td>' +data[count].bill_number + '</td>';
output += '</tr>';
}
$('tbody').html(output);
}
});
}
$(document).on('keyup', '#searchdata', function(){
var query = $(this).val();
// var token = $("meta[name='csrf-token']").attr("content");
fetch_bill_data(query);
});
});
i call my data-id like this but does not works
$("#receive_btn").click(function (e) {
if(!confirm("Do you want to Received this?")) {
return false;
}
e.preventDefault();
var billnumber= $(this).data("id");
// alert(id);
var token = $("meta[name='csrf-token']").attr("content");
$.ajax({
url: "/ack_unit/" + billnumber,
type: "POST",
data: {
'billnumber': billnumber,
"_token": token,
},
dataType: "json",
success: function (data) {
console.log('SUCCESS: ', data);
// alert("Added successfully");
location.reload();
return false;
},
error: function (data) {
console.log("ERROR: ", data);
location.reload();
return false;
},
});
});
Replied to Htmlspecialchars() Expects Parameter 1 To Be String, Object Given
No error now am set like this
</div>
<div id="" class="form-group col-md-4">
<div class="input-group">
<span class="input-group-addon">{{$editbillinfo->deviceNumb->Devicenumber}}</span>
<select name="unit_id" class=" form-control js-example-basic-single" data-live-search="true" >
@foreach($master as $key=>$dt)
<option value="{{$key}}" @if($key == $bill->unit_issue_id) selected @endif>{{$key}}</option>
@endforeach
</select>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
<div class="input-group">
<span class="input-group-addon"></span>
<select name="slave_ID[]" class=" form-control js-example-basic-single">
<option value="">[SELECT SLAVE]</option>
@foreach($Slave as $key=>$dt)
<option value="{{$key}}" @if($key == $bill->slave_id) selected @endif>{{$dt}}</option>
@endforeach
</select>
</div>
</div>
</div>
controller
public function refercancellbill_credit($bill_number)
{
//
$team=Auth::user()->team_id;
$editbillinfo=Sales::with('deviceNumb')->where('bill_number',$bill_number)->first();
$countslave=Sales::select(DB::raw('COUNT(slave_id ) as totalslave'))->where('bill_number',$bill_number)->first();
$bill = DB::table('sales')->WHERE("sales.bill_number", $bill_number)->first();
$Slave=DB::table('my_stocks')->leftjoin('devices', 'devices.id','=','my_stocks.unit_id')->where('my_stocks.status',0)
->where('devices.devicetype',2)
->pluck('Devicenumber','unit_id');
$master=DB::table('my_stocks')->leftjoin('devices', 'devices.id','=','my_stocks.unit_id')->where('my_stocks.status',0)
->where('devices.devicetype',1)
->pluck('Devicenumber','unit_id');
return view('sales.referbillcredit',compact('editbillinfo','bill','master','Location','Slave','countslave'));
}
it display the new instead of old value which is found in database
i want to display and have the new one to change it
Replied to Htmlspecialchars() Expects Parameter 1 To Be String, Object Given
does not works, @marianomoreyra
Started a new Conversation Htmlspecialchars() Expects Parameter 1 To Be String, Object Given
I tried to create my edit form and update the data when i want to display the value am get this error in my edit form
My controller
public function refercancellbill_credit($bill_number)
{
//
$team=Auth::user()->team_id;
$editbillinfo=Sales::with('deviceNumb')->where('bill_number',$bill_number)->first();
$Location=Location::pluck('Lname','id');
$Slave=DB::table('my_stocks')->leftjoin('devices', 'devices.id','=','my_stocks.unit_id')->where('my_stocks.status',0)->get();
$customer_name=Customer::pluck('compy_name','id');
return view('sales.referbillcredit',compact('editbillinfo','customer_name','Location','Slave','countslave'));
}
My blade view
<div id="" class="form-group col-md-4">
<div class="input-group">
<span class="input-group-addon">{{$editbillinfo->deviceNumb->Devicenumber}}</span>
<select name="unit_id" class=" form-control js-example-basic-single" data-live-search="true" >
@foreach($Slave as $key=>$dt)
@if($dt->devicetype ==1)
<option value="{{$key}}" @if($key == $editbillinfo->unit_issue_id) selected @endif>{{$dt}}</option>
@endif
@endforeach
</select>
</div>
</div>
<div class="form-group col-md-4">
<div class="input-group">
<span class="input-group-addon"></span>
<select name="slave_ID[]" class=" form-control js-example-basic-single">
<option value="">[SELECT SLAVE]</option>
@foreach($Slave as $key=>$dt)
@if($dt->devicetype ==2)
<option value="{{$key}}" @if($key == $bill->slave_id) selected @endif></option>
@endif
@endforeach
</select>
</div>
</div>
Kindly assist me where i did wrong
Replied to Laravel Redirect With Post Method
@automica , i need to get the alert on the same route to show successfully
Replied to Laravel Redirect With Post Method
the button
<td> <button class="btn btn-succes audit" data-id="{{$dt->bill_number}}">AUDIT BILL</button></td>
$(document).ready(function(){
$(".audit").click(function (e) {
var bill_number = $(this).data("id");
if(!confirm("Do you really want to Audit this?")) {
return false;
}
e.preventDefault();
var token = $("meta[name='csrf-token']").attr("content");
$.ajax({
url: "/audit_bill/"+bill_number,
type: "POST",
data:{bill_number:bill_number,
token:token,
},
dataType: "json",
success: function (data) {
console.log('SUCCESS: ', data);
// location.reload();
return false;
},
error: function (data) {
console.log("ERROR: ", data);
// location.reload();
return false;
},
});
});
});
Started a new Conversation Laravel Redirect With Post Method
i have the route
which fetch the data when i send the request,
with that data in the blade view i have the button to select the ID and update
it update well but am get this error
The GET method is not supported for this route. Supported methods: POST
In my web
//fetch data
Route::post('sales_reports_by_team','[email protected]')->name('reports.team');
//select bill_number and update the status=1
Route::post('/audit_bill/{bill_number}','[email protected]')->name('audit.bill');
My controller
public function auditbillnumber(Request $request,$bill_number)
{
DB::table('sales')->where('sales.bill_number', $bill_number)->update(['audit_status'=>1]);
return redirect()->back()->with('alert','Bill has been updated Successfully');
}
Replied to Avoid Duplication
i was tried this sir but still the same i don't know where i did wrong when i using firstOrCreate
Replied to Avoid Duplication
yes your correct @michaloravec , how can i avoid that bill_number to increment with the same request
because we will have many duplicate data
Replied to Avoid Duplication
@michaloravec , it create data well, but when i refresh the browser it create new request with new bill_number, and the same request
Replied to Avoid Duplication
public function store(Request $request)
{
$now = now();
$bill_no = DB::table('sales')
->selectRaw('max(right(bill_number, 4)) as bill_no')
->whereDate('updated_at', $now->format('Y-m-d'))
->value('bill_no');
foreach (Arr::wrap($request->slave_ID ?? 'no_slave_id') as $value) {
Sales::create($request->only([
'customer_agent', 'payment_method', 'borderName', 'tag_area',
'cargo_type', 'chasisNo', 'ITNo', 'driverName', 'License',
'driverPhone', 'subT1', 'TruckNo', 'amount', 'discount',
'sale_type', 'currency'
]) + [
'bill_number' => $bill_number = "E{$now->format('dmy')}".Str::padLeft($bill_no, 4, '0'),
'user_id' => Auth::user()->id,
'tag_id' => Auth::user()->team_id,
'unit_issue_id' => $request->unit_id,
'TrailerNo' => $request->trailerNo,
'container_no' => $request->containerNo,
'comments' => $request->comment,
'created_at' => $request->backdate ?? now()->format('Y-m-d H:i:s'),
'slave_id' => $value == 'no_slave_id' ? null : $value
]);
}
Mystock::where('unit_id',$request->unit_id)
->update([
"status"=>1,
]);
if($request->slave_ID){
Mystock::whereIn('unit_id',$request->slave_ID)
->update([
"status"=>1,
]);
}
return $this->print_sales_bill_cash($bill_number); //here to h..
}
Replied to Avoid Duplication
Oky thanks and how can i use in public function?
Do you think can not duplicate
Replied to Avoid Duplication
Yes i changed, but the it duplicate the slave_id and the bill_no does not increment
Bill is the same but slaveId is duplicated, but if i there is not slaveId it does not duplicate unit_id
Replied to Avoid Duplication
ok seen, but
Call to a member function value() on array
on this
$bill_no = (int) DB::select("SELECT max(right(bill_number, 4)) as bill_no from sales WHERE date(updated_at) = '{$now->format('Y-m-d')}'")->value('bill_no') + 1;
Replied to Avoid Duplication
am get this error
Trying to get property 'bill_no' of non-object
on this line 'bill_number' => $bill_number = "E{$now->format('dmy')}".Str::padLeft((int) $no->bill_no + 1, 4, '0'),
Replied to Avoid Duplication
Both, if test with slave it duplicate and if i did attached slave it duplicate when i refresh the page
Replied to Avoid Duplication
From here am checks if the request has slave_ID then it will save with slave_id
And if not it will save on slave_id as null
That is my logic
Replied to Avoid Duplication
my request is created well with this code good
array:22 [▼
"_token" => "eMicRSunxukf6D5as37h43Impw4mwNqBFF76Ls7D"
"unit_id" => "6"
"sale_type" => "1"
"backdate" => null
"customer_agent" => "ABCG"
"payment_method" => "1"
"currency" => "1"
"amount" => "70"
"discount" => "7"
"tag_area" => "DEPOT DALBIT"
"borderName" => "1"
"cargo_type" => "2"
"TruckNo" => "T678 TTY"
"trailerNo" => "T 566 ABD"
"chasisNo" => null
"ITNo" => null
"container_no" => "TTGHBRT6564"
"driverName" => "FEKRR"
"License" => "4000231136"
"driverPhone" => "0754262956"
"subT1" => "TZS466676767"
"comment" => "OK"
]
when i refresh the page the same data is created again with new bill_number
i tested the changes of bill_number but it created the same.
this bill_number has the same data when i refresh it
E2101217422
E2101217425
Replied to Avoid Duplication
ok @tray2 , so the code will be like this?
$no = DB::select("SELECT max(right(bill_number,4)) as bill_no from sales WHERE date(updated_at)='$tgl'");
foreach ($no as $idnx) {
$noo = (int) $idnx->bill_no;
}
$tambah = $noo + 1;
$bill_number = 'E' . Carbon::now()->format('dmy') . str_pad($tambah, 4, '0', STR_PAD_LEFT);
Replied to Avoid Duplication
@tray2 i tested it still duplicate,
the problem here is bill_number
after save the data, when i refresh the page, its takes the same and save as new data with new bill_number
I think that the billnumber is create as new because it check the last and create new one as the same data
Replied to Avoid Duplication
@tray2, this $data or $date ?
Check this line
$date['slave_id'] =$request->slave_ID[$key],
Sales::create($data);
Replied to Avoid Duplication
Am using switch
switch(true) { case $tambah < 10: $bill_number = "E" . Carbon::now()->format('dmy') . "000" . $tambah; break; case $tambah < 100: $bill_number = "E" . Carbon::now()->format('dmy') . "00" . $tambah; break; case $tambah < 1000: $bill_number = "E" . Carbon::now()->format('dmy') . "0" . $tambah; break; case $tambah < 10000: $bill_number = "E" . Carbon::now()->format('dmy') . $tambah; break; default: $bill_number = 'severe'; break; }
Replied to Avoid Duplication
i want try like this
$date = $request->filled('backdate') ? request('backdate') : Carbon::now()->format('Y-m-d H:i:s');
// if($request->filled('backdate')) {
// $date = request('backdate');
// } else {
// $date = Carbon::now()->format('Y-m-d H:i:s');
// }
if ($request->slave_ID) {
foreach ($request->slave_ID as $key => $value) {
Sales::updateOrCreate(
['bill_number' => $bill_number,'customer_agent' => $request->customer_agent],
['tag_id' => Auth::user()->team_id ],[
'bill_number' => $bill_number,
'user_id' => Auth::user()->id,
'unit_issue_id' => $request->unit_id,
'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,
'amount' => $request->amount,
'discount' => $request->discount,
'sale_type' => $request->sale_type,
'currency' => $request->currency,
'created_at'=>$date,
'slave_id'=>$request->slave_ID[$key],
]); // Sales::create($data);
}
}else{
Sales::updateOrCreate(
['bill_number' => $bill_number,'customer_agent' => $request->customer_agent],
['tag_id' => Auth::user()->team_id ],[
// 'tag_id' => Auth::user()->team_id,
'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,
'amount' => $request->amount,
'discount' => $request->discount,
'sale_type' => $request->sale_type,
'currency' => $request->currency,
'created_at'=>$date,
'slave_id'=> ($request->has('slave_ID') && count($request->slave_ID) > 0)? count($request->slave_ID) : null,
]);
// Sales::create($data2);
}
am get this error
Trying to get property 'bill_number' of non-object
Replied to Avoid Duplication
Oky let me try,
And how about create($data) to avoid duplicate
Can i use this bill_number as to check and updateOrCreate
Help me on this @prasadchinwal5
Replied to Avoid Duplication
how can i write switch there?
and how can i avoid that duplication because am using bill_number
as unique
Started a new Conversation Avoid Duplication
Hello ,
How can i avoid duplication here?
$tgl = Carbon::now()->format('Y-m-d');
$no = DB::select("SELECT max(right(bill_number,4)) as bill_no from sales WHERE date(updated_at)='$tgl'");
foreach ($no as $idnx) {
$noo = (int) $idnx->bill_no;
}
$tambah = $noo + 1;
if ($tambah < 10) {
$bill_number = "E" . Carbon::now()->format('dmy') . "000" . $tambah;
} else if ($tambah < 100) {
$bill_number = "E" . Carbon::now()->format('dmy') . "00" . $tambah;
} else if ($tambah < 1000) {
$bill_number = "E" . Carbon::now()->format('dmy') . "0" . $tambah;
} else if ($tambah < 10000) {
$bill_number = "E" . Carbon::now()->format('dmy') . $tambah;
}
if($request->filled('backdate')) {
$date = request('backdate');
} else {
$date = Carbon::now()->format('Y-m-d H:i:s');
}
if ($request->slave_ID) {
foreach ($request->slave_ID as $key => $value) {
$data =[
'bill_number' => $bill_number,
'user_id' => Auth::user()->id,
'tag_id' => Auth::user()->team_id,
'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,
'amount' => $request->amount,
'discount' => $request->discount,
'sale_type' => $request->sale_type,
'currency' => $request->currency,
'created_at'=>$date,
'slave_id'=>$request->slave_ID[$key],
];
Sales::create($data);
}
}else{
$data2 =[
'bill_number' => $bill_number,
'user_id' => Auth::user()->id,
'tag_id' => Auth::user()->team_id,
'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,
'amount' => $request->amount,
'discount' => $request->discount,
'sale_type' => $request->sale_type,
'currency' => $request->currency,
'created_at'=>$date,
'slave_id'=> ($request->has('slave_ID') && count($request->slave_ID) > 0)? count($request->slave_ID) : null,
];
Sales::create($data2);
}
return $this->print_sales_bill_cash($bill_number);
My code is works file to create but when i refresh the page it duplicate the data with new bil_number
Replied to Count Days From Created_at In The Blade View
am set like this
<?php $now = Carbon::now();?>
@foreach($iddleintransit as $key=>$dt)
<?php $days_count = $dt->created_at_sale->diffInDays($now); ?>
<tr>
<td>{{++$key}}</td>
<td>{{$dt->bill_number}}</td>
<td>{{$dt->Devicenumber}}</td>
<td>[{{$dt->totalslave}}]={{$dt->slavename}}</td>
<td>{{$dt->Lname}}</td>
<td>{{$dt->created_at_sale}}</td>
<td>$days_count</td>
</tr>
@endforeach
am get this error
Class 'Carbon' not found
Started a new Conversation Count Days From Created_at In The Blade View
i want to count the day/ to show the date from created_date
this is my blade
<td>{{$dt->created_at_sale}}</td> // 2021-01-14 12:32:22
so i want to count that date till now is how many days
How can i do here
Replied to Count In Collection
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
}
]
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
Replied to How To Avoid Duplicates Entry
yes,it works now i was forget to add user_id to model thanks
Replied to How To Avoid Duplicates Entry
sorry both are return
$userId=Auth::user()->id; = 7
,
dd($request->user()->id); = 7