Thank you for this video this is really helpful for me. Can you please guide me how can I modify this code. $maxId = LongTermContracts::UserById()->whereYear("created_at", date('Y'))->count() + 1; $maxId = str_pad($maxId, 5, 0, STR_PAD_LEFT); $request->request->add(['contract_no' => "LT" . date('Y') . "-" . $maxId, 'user_id' => auth()->user()->id]); $contract = LongTermContracts::create($request->all()); Thank you again.
@@LaravelDaily I just want to create a contract no when contract create and the number will be like LT20230001 so when I create a contract I need to create first this number and then create contract. So i need to do in a shorter way.
Not sure if that can be much optimized, maybe just not using some temporary variables, bu tthen lines would get longer. Just a few things. 1. Instead of auth()->user()->id you can use auth()->id() 2. Don't use $request->all() it's considered unsafe: laraveldaily.com/post/laravel-request-all-security-issue
//its better to make it work with the date range... if I am wrong correct me ///trait public function scopeRecent($query, $search, $column = 'created_at') { if (empty($search) || ! isset($search)) { return $query; } return $query->whereDate($this->getTable().'.'. $column, '>=', Carbon::parse(current(explode(' to ', $search)))->startOfDay()->toDateString()) ->whereDate($this->getTable().'.'.$column, '
Instead of concatenating $this->getTable . '.created_at' You can use $this->qualifyColumn('created_at') Its cleaner in my opinion Its not in laravel documentation, but this method exist in Model class
very useful thank sir
Thank you for videos, that is helpful. I begin my each work day with your video and know that i get some new and helpful information. Laravel is cool.
Veo tus videos antes y después de ir a dormir, estoy como JR de Laravel y ver tus videos me ayuda mucho
Saludos
very useful, thank you
As always very helpful.
धन्यवाद श्रीमान
It's very useful
Isn't it also possible to create a baseModel. And make your models extend this new BaseModel with the repeated code ?
Thank you for the great information, teacher. Can you show us how to dynamically translate the site from the database?
There are packages like Laravel translatable, please search my channel, I had videos about it
@@LaravelDaily Thank you very much😇
thks master
how about without using Traits?
Thank you for this video this is really helpful for me. Can you please guide me how can I modify this code.
$maxId = LongTermContracts::UserById()->whereYear("created_at", date('Y'))->count() + 1;
$maxId = str_pad($maxId, 5, 0, STR_PAD_LEFT);
$request->request->add(['contract_no' => "LT" . date('Y') . "-" . $maxId, 'user_id' => auth()->user()->id]);
$contract = LongTermContracts::create($request->all());
Thank you again.
Modify for what? What is the actual problem or goal to solve?
@@LaravelDaily the goal is to optimize this code to shorter way.
@@LaravelDaily I just want to create a contract no when contract create and the number will be like LT20230001 so when I create a contract I need to create first this number and then create contract. So i need to do in a shorter way.
Not sure if that can be much optimized, maybe just not using some temporary variables, bu tthen lines would get longer.
Just a few things.
1. Instead of auth()->user()->id you can use auth()->id()
2. Don't use $request->all() it's considered unsafe: laraveldaily.com/post/laravel-request-all-security-issue
@@LaravelDaily Thank you sir for your valuable time that you replied me. so Humble and Highly Appreciated.
//its better to make it work with the date range... if I am wrong correct me
///trait
public function scopeRecent($query, $search, $column = 'created_at')
{
if (empty($search) || ! isset($search)) {
return $query;
}
return $query->whereDate($this->getTable().'.'. $column, '>=', Carbon::parse(current(explode(' to ', $search)))->startOfDay()->toDateString())
->whereDate($this->getTable().'.'.$column, '
That probably may be more accurate, yes, the date accuracy was not the point of this video
Instead of concatenating $this->getTable . '.created_at'
You can use $this->qualifyColumn('created_at')
Its cleaner in my opinion
Its not in laravel documentation, but this method exist in Model class
this ☝
Thank you for sharing that usefullness!