I recently read (and now I can’t find it) an article that claimed it was bad practice to use a DocBlock comment to typehint the return value of Model::first(). If I recall, the article was a code style guide used by a project.
Does anyone happen to know what article I’m talking about?
Here’s the specific thing I recall. They claimed that this was not best practice: /** @var User $user */ $user = User::first();
There was something else they did that allowed the IDE to know that $user was a User type.
Without the comment, my IDE (PhpStorm) can’t do any code-completion for my $user object. Is there something I should be doing so the IDE recognizes $user as a User besides this comment?
Thanks for any help!
Edit: I have the Laravel Idea plugin enabled, and I also use the ide-helpers plugin, but PhoStorm still doesn’t recognize the model in my example. submitted by /u/mtmo
[link] [comments]
27 May, 2023
26 May, 2023
Telegraf save only last line of csv input
Programing Coderfunda
May 26, 2023
No comments
I have a script that print a result like that:
somename,bps,running_time
AAA,1886,01:35
BBB,6235,01:35
CCC,2532,01:35
Here is my telegraf config :
[[inputs.exec]]
commands = [ "bash /opt/latency/test.sh" ]
timeout = "5s"
name_override = "latency"
data_format = "csv"
csv_header_row_count = 1
csv_trim_space = true
csv_column_names = ["somename","bps","running_time"]
csv_column_types = ["string","int","string"]
csv_skip_errors = true
csv_comment = ""
csv_skip_rows = 0
When I check on grafana which variables are put on the influxdb, there is only the last line aka with somename=CCC.
How can I add three lines into influxdb and not only last one?
25 May, 2023
On Click Submit Button Save Data by Ajax Laravel
Programing Coderfunda
May 25, 2023
Ajax, Laravel
No comments
View Page blade page
<div class="button like" value="{{ $color->id}}">
<div class="icon" icon="like"></div>
<span> {{ isset($color->likecount) ? $color->likecount : Null }}</span>
</div>
<script>
$('.like').on('click',function(e){
let likeid = $(this).attr('value');
$(".like").removeClass('active');
$(this).addClass('active');
$.ajax({
url: "{{url('/like')}}",
type:"POST",
data:{
"_token": "{{ csrf_token() }}",
likeid:likeid,
},
success:function(response){
$(".like.active span").text(response);
}
});
});
</script>
Web.php
URL
Route::post('/like',[MainSettingController::class, 'likebtn']);
Controller :
public function likebtn(Request $request){
$like = Color::where('id', $request->likeid)->first();
if(empty($like)){
$oldcount = 1;
// $oldcount = $like->likecount;
$statusid = $oldcount+1;
$ab = Color::where('id', $request->likeid)->update(['likecount'=>$statusid]);
}else{
$oldcount = $like->likecount;
$statusid = $oldcount+1;
$ab = Color::where('id', $request->likeid)->update(['likecount'=>$statusid]);
}
$totallike = Color::where('id', $request->likeid)->first();
return $totallike->likecount;
}
Example : https://colorshunt.com/palette/ffebbc5da7ae543d46292830
Working with OS process in PHP
Programing Coderfunda
May 25, 2023
No comments
24 May, 2023
Remix.run useLoaderData returns type any
Programing Coderfunda
May 24, 2023
No comments
I was just trying this new thing remix.run and came across this. Everywhere in cos for this framework they are using const data = useLoaderData() to have type of data variable inferred. But for me this is not working:
import { json } from "@remix-run/node";
import type { LoaderFunction, LoaderArgs } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { getUsers } from "~/models/users.server";
export const loader: LoaderFunction = async (args: LoaderArgs) => {
const users = await getUsers();
return json({ users: users });
};
export default function Users() {
const { users } = useLoaderData();
return (
{users.map((u) => (
{u.username}
))}
);
}
My VSCode says that variable users has any type and there is a squiggly line red line bellow u in map...what is wrong?
package.json:
"@remix-run/css-bundle": "^1.16.0",
"@remix-run/node": "^1.16.0",
"@remix-run/react": "^1.16.0",
"@remix-run/serve": "^1.16.0",
23 May, 2023
Observability vs monitoring
Programing Coderfunda
May 23, 2023
No comments
Is observability the same as monitoring? What is the difference between observation and monitoring? What is the right tool for each specific monitoring problem? Read on to find out!
The post Observability vs monitoring appeared first on Laravel News.
Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.
---
22 May, 2023
Database revision vs Event sourcing for tracking changes of entity changes
Programing Coderfunda
May 22, 2023
No comments
We are developing a platform where there is the possibility of booking hotels. The booking process can consist of various operations: creation, change of dates, cancellation, confirmation, and so on. We need to have access to the history of booking changes to display this on the front end (for now, only for displaying, who knows what might happen in the future).
One of the ways to use this history of changes: Created a booking -> changed the dates -> we show the user the previous dates and current ones.
The entity of Booking: { checkInDate: string, checkOutDate: string, amount: number ... +30 fields }
Found two approaches:
First approach: Versioning the entity at the database level.
If our entity is updated, then a copy of the entity is automatically created, but with new fields. In the case of changing the dates of a just created booking, the client will return an array of bookings, each will have all the fields of the booking and an additional field with the status (created, changed dates etc).
Pros of this approach:
*
Faster backend implementation, changes are mostly required at the database level.
*
One familiar Booking model is used.
*
Ability to configure rollbacks.
*
Good performance.
Cons:
* Difficult to set up auto migration.
* The database stores a lot of excess data, which will be returned to the client who does not need them.
Second approach: Event-driven architecture
There is a described list of possible events that can occur with a booking. An event is created for each operation, which can contain a payload with the data that has changed. In the case of changing the dates of a just created booking, the client will return a booking with an array of events, each of which contains a list of data that has changed. The changed-dates event may contain the previous dates and current ones.
Pros:
*
Only necessary data is stored in the database and returned to the front.
*
Having a list of described events, the flow becomes transparent, which improves the understanding of the code.
*
In the event payload, you can add any data, even those not related to the previous booking change. Easier to expand functionality.
*
Business logic is kept on the backend, the front simply displays the data, business logic does not penetrate the database level.
Cons:
*
Many additional types are added, which need to be used on the front.
*
More complex backend implementation.
Could you suggest which solution is better to choose? Maybe you have a better option?
21 May, 2023
How would you structure a system with multiple bussiness "regions"?
Programing Coderfunda
May 21, 2023
No comments
For example, an e-commerce site, where there are a "region" for the sellers, with feature align to managing products or selling analytic. And a front-facing "region" for regular clients to browse the products, have a cart, bookmark or follow products or brands.
When there are 2 (or more) distinct regions for different functionality and client. How would you structure your Laravel project? Would you follow DDD? Microservices? Or something else?
To be clear it is not strictly e-commerce, but any systems that had multiple regions like that. A travel agency where there are region for hotel owner to register and manage their hotel versus a region for everyone to search and book hotel. A streaming app where everyone can browser their favorite streamer but the streamers have their own managing place as well as analytic... Also count submitted by /u/Lumethys
[link] [comments]

