Member Since 3 Months Ago
930 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 QR Code Generator
use this package : simplesoftwareio/simple-qrcode and save image :
$fileNameCodeUnique = md5(time()); $qrcode = QrCode::size(512) ->format('svg') ->generate($request->code, base_path() . '/storage/app/public/qrproducts/qrcodes/' . $fileNameCodeUnique . '.svg');
Awarded Best Reply on Blade Formatter For Visual Studio Code.
I have already done all the answers to that post except one that needs modification for beautify. I did it now but it did not work for version 1.5. I solve my problem by using this gist : https://gist.github.com/maliouris/f84b7f3dcb2a71455e693716e76ce302
it's not perfect But there is no choice.
Replied to Blade Formatter For Visual Studio Code.
I have already done all the answers to that post except one that needs modification for beautify. I did it now but it did not work for version 1.5. I solve my problem by using this gist : https://gist.github.com/maliouris/f84b7f3dcb2a71455e693716e76ce302
it's not perfect But there is no choice.
Started a new Conversation Blade Formatter For Visual Studio Code.
recently I tried all formatters in the market place. But none of them work well. Please Introduce me a trusted formatter if you know.I'm exhausted :-(
Replied to How To Notify Comment Owner And Not Auth User
did you add $fillable=[]; fields in your models?
Replied to How To Update BelonsToMany (value)
well, i use $user->socials()->sync($socials); after saving user(when editing or creating).
Replied to Dynamically Retrieve A Model Based On It's Name And Id.
but you can add polymorphic relations to Models and used them with Eloquent. https://laravel.com/docs/8.x/eloquent-relationships#polymorphic-relationships
I use it for commenting posts, news, profiles, user walls. also, I use it for attachments for many models. you only need an additional two extra columns to table comments (one for model id and one for model type(Model class name)). and Eloquent automatically Recognizes Relevant models.
note: When you want to add a polymorphic type, add the full model address. This is not mentioned in the Laravel Document(ex: 'App\Models\Project').
Replied to How To Update BelonsToMany (value)
Sorry. Explain to me exactly what the value column is for? your definitions are wrong. drop the value column.and add bellow relations to your Models. in User.php :
public function socials() { return $this->belongsToMany(Social::class); }
in Social.php :
public function users() { return $this->belongsToMany(User::class); }
if you have timestamps in pivot table add ->withTimestamps() chain to belongsToMany.
Replied to How To Set Locale In Laravel Work With Moment.js?
read momentJS documentation.if you are using webpack with mixer You must write code to contain it. another simple way is Add it(CDN or file) to the blade layer with script tag.
Awarded Best Reply on How To Set Locale In Laravel Work With Moment.js?
Did you link to moment-with-locales.min.js?
Replied to How To Set Locale In Laravel Work With Moment.js?
Did you link to moment-with-locales.min.js?
Replied to How To Get Data From Relationship Table
do you add relations function to all Models that i wrote before? this is an array of details : Auth::User()->voucherdetails()->get(); you have three tables.first you must specify relations types.one-to-one or one-to-many. Then I can help you better.
Awarded Best Reply on How To Get Data From Relationship Table
1 - add foreign keys to your tables :
for companyregisters :
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
for voucherdetails:
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade'); $table->foreign('company_id')->references('id')->on('companyregisters')->onDelete('cascade')->onUpdate('cascade');
2 - change column type for user_id :
$table->unsignedBigInteger('user_id');
also look at your database if companyregisters table id and voucherdetails table id are big int(20) change theme too. 3 -php artisan migrate
4 - add Model Relationships : for User Model :
public function companyRegisters(){ return $this->hasMany(CompanyRegister::class); } public function voucherDetails(){ return $this->hasMany(VoucherDetail::class); }
for CompanyRegister Model :
public function user(){ return $this->belongsTo(User::class); } public function voucherDetails(){ return $this->hasMany(VoucherDetail::class); }
for VoucherDetail class :
public function user(){ return $this->belongsTo(User::class); } public function companyRegister(){ return $this->belongsTo(CompanyRegister::class); }
done.now you can access relations in controllers :
for User Model Objects: $companies=Auth::User()->companyRegisters()->get(); $voucherDetails=Auth::User()->voucherDetails()->get();
for CompanyRegister Model Objects: $user=$company->user; voucherDetails=$company->voucherDetails()->get();
for VoucherDetail Model Objects: $user=$VoucherDetail ->user; $company==$VoucherDetail ->companyRegister;
Replied to How To Get Data From Relationship Table
$id=Auth::id(); or $id=Auth::user()->id();
I assumed the relationship between the user and company is one-to-many. based on your tables: a user has many companies and a company belongs to one user. if you want to get Logged-in user companies Use the following code:
Auth::User()->companyRegisters()->get();
get all companies associated with the user.
*if your relation between user and company is one-to-one you must change companyRegisters() function in User Model Like the code below:
public function companyRegister(){ return $this->hasOne(CompanyRegister::class); }
then you can get user company by using code below :
$loggedInUserCompany=Auth::User()->companyRegister;
Replied to Strange Certification Question
only 4 is correct.also if option 3 was $user->purchase_date= new Carbon("2020-10-10 10:10:10"); It could be right. remember there is no such purchaseDate attribute in user model. it's just purchase_date. that's right 4 pass strings to attribute but set attribute triggered and convert string to Carbon.
Replied to How To Get Data From Relationship Table
1 - add foreign keys to your tables :
for companyregisters :
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
for voucherdetails:
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade'); $table->foreign('company_id')->references('id')->on('companyregisters')->onDelete('cascade')->onUpdate('cascade');
2 - change column type for user_id :
$table->unsignedBigInteger('user_id');
also look at your database if companyregisters table id and voucherdetails table id are big int(20) change theme too. 3 -php artisan migrate
4 - add Model Relationships : for User Model :
public function companyRegisters(){ return $this->hasMany(CompanyRegister::class); } public function voucherDetails(){ return $this->hasMany(VoucherDetail::class); }
for CompanyRegister Model :
public function user(){ return $this->belongsTo(User::class); } public function voucherDetails(){ return $this->hasMany(VoucherDetail::class); }
for VoucherDetail class :
public function user(){ return $this->belongsTo(User::class); } public function companyRegister(){ return $this->belongsTo(CompanyRegister::class); }
done.now you can access relations in controllers :
for User Model Objects: $companies=Auth::User()->companyRegisters()->get(); $voucherDetails=Auth::User()->voucherDetails()->get();
for CompanyRegister Model Objects: $user=$company->user; voucherDetails=$company->voucherDetails()->get();
for VoucherDetail Model Objects: $user=$VoucherDetail ->user; $company==$VoucherDetail ->companyRegister;