zizi_ove

zizi_ove

Member Since 5 Months Ago

Experience Points
1,040
Total
Experience

3,960 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
5
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    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.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
1,040 XP
May
30
2 months ago
Activity icon

Replied to Using "with" After "hasMany"

@nakov Thank you so much for your help.

May
29
2 months ago
Activity icon

Replied to Using "with" After "hasMany"

@nakov Thank you for your reply, actually the code mentioned above is from exactly this blog post but I can't understand it.

Activity icon

Started a new Conversation Using "with" After "hasMany"

Hi there, Anybody knows what does mean when using "->with()" after "hasMany()" in the eloquent model? for example, suppose we have a model called Category, and in this model we define two methods like this:

class Category extends Model
{

    public function categories()
    {
        return $this->hasMany(Category::class);
    }

}

public function childrenCategories()
{
    return $this->hasMany(Category::class)->with('categories');
}

what does mean this line of code?

return $this->hasMany(Category::class)->with('categories');

Thank you.

May
27
2 months ago
Activity icon

Replied to Trait Vs Hepler In Laravel

Thanks a lot, @snapey for your great explanation.

Activity icon

Replied to Trait Vs Hepler In Laravel

Thank you all for your answers and helps.

May
26
2 months ago
Activity icon

Started a new Conversation Trait Vs Hepler In Laravel

How could we figure out when to use trait and when to use hepler in Laravel? what is the advantage and disadvantage of each?

any hint appreciated

Thanks

May
12
2 months ago
Activity icon

Replied to Remove Many To Many Polymorphic Relations (taggables)

Hi all, How about reverse of it? If we want to delete a specific tag and detach that tag with all related models from taggables table!

Is there any easy and clean way to do that

Thanks

May
02
3 months ago
Activity icon

Replied to Laravel Many To Many Polymorphic Query

Thank You very much @james_moore, It helped me a lot.

Activity icon

Started a new Conversation Laravel Many To Many Polymorphic Query

Suppose we have many to many polymorphic relationship same like Laravel documentation:

    posts
        id - integer
        name - string
    
    videos
        id - integer
        name - string
    
    tags
        id - integer
        name - string
    
    taggables
        tag_id - integer
        taggable_id - integer
        taggable_type - string

The main question is, how to check the existence of a specific record in taggables table if I have tag_id and taggable_id and taggable_type. How can I write this query?

Already I always make a model for taggables table in Laravel and find the specific record but I think this is not the right solution.

Any help will be appreciated, Thank you.

Apr
22
3 months ago
Activity icon

Replied to Query Builder Avg Method, Problem With Float Numbers

The problem is solved by using a raw query instead of avg() method:

        return $query->where('rateble_type', $type)
                     ->where('rateble_id', $id)
                     ->selectRaw('CAST(AVG(star) AS DECIMAL(2,1)) AS star_avg')->first()->star_avg;

hope it helps someone else.

Apr
21
3 months ago
Activity icon

Replied to Query Builder Avg Method, Problem With Float Numbers

@jlrdw Thank you for your suggestion, but I think it can not help to solve the problem. maybe I'm wrong. could you please explain more how it could be used in avg() query?

Thanks,

Activity icon

Started a new Conversation Query Builder Avg Method, Problem With Float Numbers

Trying to create a 5-star rating system in Laravel. a star rate is a float number in the range [1 to 5] and it stores successfully in the database. migration file for rates table in database. ( I've set data type of star column as float)

    public function up()
    {
        Schema::create('rates', function (Blueprint $table) {
            $table->id();
            $table->morphs('rateble');     //creates rateable_id  and  rateable_type

            $table->foreignId('user_id')->nullable()
			->constrained()
			->onUpdate('cascade')
			->onDelete('set null');

            $table->float('star',2, 1);    //star number is from 0 to 5
            $table->timestamps();
        });
    }

Then for averaging the rating for a specific product, I am using this query:

    public function scopeAverageRate($query, $type, $id)
    {
        return $query->where('rateble_type', $type)
                     ->where('rateble_id', $id)
                     ->avg('star');
    }

The problem is, it seems that the avg() method cast the result to integer! Is there any way to set this function to work with the float numbers?

e.g. assume there is only one rate for a specific product that equals "0.5" stars then the average rating is "0" instead of "0.5" !

How can I solve this problem?

Thank you in advance,

Apr
15
3 months ago
Activity icon

Replied to Is It Possible To Group Where Clauses In Eloquent?

It worked for me by this code:

public static function seachFiles($q, $categoryId)
{

    return static::where('category_id', '=' ,$categoryId)
                    ->where(function ($query) use ($q) {
                        $query->where('file_name', 'LIKE', "%$q%")
                                ->orWhere('file_code', 'LIKE', "%$q%")
                                ->orWhere('description', 'LIKE', "%$q%");
                    })
                    ->get();
}

hope this helps.

Apr
07
4 months ago
Activity icon

Replied to Make A Foreign Key Column Nullable In Migration File

@snapey I thought it is better for less data storage in database, maybe I'm wrong. but I think your solution is better than mine. Thank you for your help.

Activity icon

Replied to Make A Foreign Key Column Nullable In Migration File

@tray2 Thank you very much for your advice.

Activity icon

Replied to Problem With Unique Field Validation On Update

I think another solution in the update process is to make the input field related to email in the edit form, "disabled". in this way, the email is not passed anymore.

hope it helps.

Activity icon

Replied to Make A Foreign Key Column Nullable In Migration File

In my case, I have "user" table and in it, there is "gender_id" column. There is also another table named "gender" which has :

id=1 ==> name=woman, id=2 ==> name=man

so in "user" table, "gender_id" column refers to "gender" table (FK). but I made "gender_id" nullable because the gender field in the registration form is optional.

thank you all for your help.

Apr
06
4 months ago
Activity icon

Replied to Make A Foreign Key Column Nullable In Migration File

Hi all, fortunately I found the solution. for making a foreign key column nullable in laravel 7, just write "nullable()" before "constrained()" and it works! like this:

$table->foreignId('type_id')->nullable()->constrained()->onUpdate('cascade')->onDelete('set null');

Good luck.

Apr
05
4 months ago
Mar
26
4 months ago
Activity icon

Replied to Make A Foreign Key Column Nullable In Migration File

@jeevamugunthan could you please describe a little more, why I should index a foreign key column? indexing is necessary? Does it help to make a "foreign key column" nullable?

Thank you

Activity icon

Replied to Make A Foreign Key Column Nullable In Migration File

thanks to your reply.

Is "name" column defined as a foreign key?

Mar
25
4 months ago
Mar
24
4 months ago
Activity icon

Started a new Conversation Make A Foreign Key Column Nullable In Migration File

Hi, Is it possible to make a foreignId column in a migration file in laravel 7 as a nullable column? unfortunately it does not work for me.

thanks for any hint,

Mar
03
5 months ago
Activity icon

Replied to [L5] Validating Multiple File Input

this code solved my problem for validating array of images. (name of image field in form is : file)

    $request->validate([
        'product_code'  =>  'required|string',
        'product_name'  =>  'required|string',
        'product_price' =>  'required|string',

        'file'          =>  'nullable',                           //name of image field in form
        'file.*'          =>  'max:2048|image'        //name of image field in form
    ]);