2,220 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.
Replied to Add/Remove Input Fields Doesn't Store Into The Same Array Field
Only gets the first field
6:
name: "color[]"
value: "Black1"
__proto__: Object
length: 7
Replied to Add/Remove Input Fields Doesn't Store Into The Same Array Field
yes, there's a form in the parent of the colors div. Although I send it on a normal button click to a POST route instead of ajax sending
Started a new Conversation Add/Remove Input Fields Doesn't Store Into The Same Array Field
What I'm doing is to have an option of an item can have multiple colors. Problem is the dynamically added input fields doesn't save upon hitting the button.
<div class="wrapperColor">
<label for="color">Color/s</label>
<div class="row" style="padding: 1% 0;">
<div class="col-9 form-group">
<input type="text" name="color[]" class="form-control" placeholder="Black" required>
</div>
</div>
</div>
<button class="add_field_button btn btn-md text-dark">Add More Fields</button>
Then, for my jQuery code
$(document).ready(function() {
var wrapper = $(".wrapperColor"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e) { //on add input button click
e.preventDefault();
x++; //text box increment
var html = '';
html += '<div class="row form-group" style="padding: 1% 0;">';
html += '<div class="col-9">';
html += '<input type="text" name="color[]" class="form-control" placeholder="Black">';
html += '</div>';
html += '<div class="col-3">';
html += '<a href="#" class="remove_field"><i class="fas fa-times fa-lg" style="color: red;"></i></a>';
html += '</div>';
html += '</div>';
$(".wrapperColor").append(html);
});
$(".wrapperColor").on("click", ".remove_field", function(e) {
e.preventDefault();
$(this).parent('div').parent('div').remove();
x--;
})
});
Upon checking dd($request->all()) in the controller, it only retrieves the first item in the array (which is the base input)
"color" => array:1 [▼
0 => "Black"
]
If it's not a json, I could easily do eloquent to call $item->destination->name on the destination under an if statement (if $item->destination is a numeric), then do a one-time conversion from string to id
Started a new Conversation Changed The Way To Save A Data From String To Int After App Launch, Any Options To Retrieve Its String Equivalent?
So we now have a table column that's mixed up containing id numbers and strings of a cities table.
For reference:
Deliveries table
Delivery ID -------- destination
1 ---------------------- Buffalo
2 ---------------------- Syracuse
3 ---------------------- 5 (one-to-one relationship on Delivery-City models)
My issue is that since it has been changed, the JSON request we're doing also needs to update its syntax. Currently we have this:
$domesticsJson = DomesticDelivery::join('domestics', 'domestics.id', '=', 'domestic_deliveries.domestic_id')
->join('domestic_shipments', 'domestic_shipments.id', '=', 'domestic_deliveries.domestic_shipment_id')
->join('ref_cities', 'ref_cities.id', '=', 'domestic_deliveries.destination')
->select('domestic_shipment_id', 'domestics.customer', 'domestics.delivery_doc_num', 'domestic_shipments.type_id', 'destination', 'domestic_shipments.pod_return_date', 'domestic_shipments.status')
->where('domestic_shipments.status', 1)
->orderBy('domestic_deliveries.created_at', 'desc')
->get()
->toJson();
Trying to aim that id#3 would be converted into the name of the city instead of its id
Started a new Conversation Exclude Null Contents Into Request
I'm trying to do a table where there's a checkbox and a quantity count (if checked), and null contents are being sent. Is there a way to exclude that?
For reference:
<td>
<label class="checkbox deliveryNotesLabel">
<input type="checkbox" class="deliveryNotes" name="deliveryNotes[]" value="{{ $item->id }}"/>
<span></span>
</label>
</td>
<td>
<input type="number" min="0" max="100" name="vans[]" class="form-control">
</td>
this is what $request->all() retrieves when I try to pick 2nd and 3rd items:
array:3 [▼
"_token" => "DzGh2Q7fjhfbr4iexJ1c4AaTd8QlrA60zBphMgV7"
"vans" => array:4 [▼
0 => null
1 => "1"
2 => "2"
3 => null
]
"deliveryNotes" => array:2 [▼
0 => "8"
1 => "7"
]
]
Started a new Conversation Skip Unique Validation For Update()
Is there a workaround to skip validation for a variable uniqueness for update even though that variable isn't modified?
Eg:
public function update ($id, Request $req)
{
$req->validate([
'name' => 'unique:users|required',
'description' => 'required'
]);
// other code
}
If I've only update the description, this would throw an error that my $req->name already exists.
Replied to Getting The Hour Of A Created_at Time Stamp In Laravel
On query, your Carbon::now()->hour will only result to an integer of the current hour, querying created_at (or updated_at) typically uses datetime or timestamp.
$hourNow= Carbon::now()->format('Y-m-d H:00:00');
$items = Item::where('created_at', '>=', $hourNow)->get()->count();
Replied to Predetermined ID Number
Thanks @rodrigo.pedra and @jlrdw
Am using Hashids\Hashids to mask id number for the url of items, and needs to have an integer as input.
Although my app only has a single admin account, my next step is to have an auto-signout feature if account is logged in to another device/browser to prevent 2 admin accounts trying to use the predeterminedId and creating an error before creation.
Started a new Conversation Predetermined ID Number
Was wondering if Laravel can add a minor syntax to predetermine the latest ID number. To simplify this code:
$lastId = Model::select('id')->orderBy('id', 'desc')->first();
$predeterminedId = ++$lastId->id;
Replied to First Item On The List Doesn't Display Its Necessary <form> Tag
@sinnbeck tried, didn't work. however, i've tried to add a blank form tag and it pushed through. so the tr > td now looks like this
<tr><td> <form></form>
<form method="POST" action="/mobolist/{{ $mobo->id }}/add-to-build" enctype="multipart/form-data">
@csrf
<input type="hidden" name="auditId" value="snipped">
<input type="hidden" name="specsId" value="snipped">
<button type="submit" class="btn btn-dark btn-sm">Add</button>
</form>
</td></tr>
Replied to First Item On The List Doesn't Display Its Necessary <form> Tag
hi @sinnbeck , those were datatables.js classes for sorting
Started a new Conversation First Item On The List Doesn't Display Its Necessary <form> Tag
All of my items/index pages have this bug where the first item of the loop doesn't have the form tag. Have no idea why or how it does that.
@foreach($mobos as $mobo)
<tr><td>
<form method="POST" action="/mobolist/{{ $mobo->id }}/add-to-build" enctype="multipart/form-data">
@csrf
<input type="hidden" name="auditId" value="snipped">
<input type="hidden" name="specsId" value="snipped">
<button type="submit" class="btn btn-dark btn-sm">Add</button>
</form>
</td></tr>
@endforeach
dev console on browser where it doesnt display the first item https://i.stack.imgur.com/19lGF.png
however on the succeeding lines, it displays the form https://i.stack.imgur.com/pIKP6.png