MichalOravec

Member Since 4 Years Ago

Prievidza, Slovakia

Experience Points
1,024,000
Total
Experience

0 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
1077
Lessons
Completed
Best Reply Awards
1509
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.

  • Community Pillar

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

Level 50
1,024,000 XP
Apr
11
21 hours ago
Activity icon

Replied to Videos Will Not Load From Server In A For Each Loop (403 Error)

Use eager loading, instead of code what you are using.

https://laravel.com/docs/8.x/eloquent-relationships#eager-loading

public function showNewItem(Request $request, $id)
{
    $product = Product::with(['images', 'videos'])->findOrFail($id);

    $products = Product::all();
    
    return view('pages.whats_new', compact('product', 'products'));
}
@foreach($product->videos as $video)
    <div class="video--container__item">
        <video controls width="100%" height="auto" src="{{ asset("storage/product_video/{$video->video}") }}"></video>
    </div>
@endforeach

And move this piece of code $products = Product::all(); to the view composer.

https://laravel.com/docs/8.x/views#view-composers

Activity icon

Replied to Gate Define Not Working For Other Users Except Whose Role_id Is 1

Your code doesn't ake any sence.

You loop through $role->permissions and then you check if a permission exist in the same array.

How I said use that package what I posted above.

Activity icon

Replied to Gate Define Not Working For Other Users Except Whose Role_id Is 1

You have wrong order of parameters in in_array

if (in_array($permission, $role->permissions)) {
   //
}

Docs: https://www.php.net/manual/en/function.in-array.php

By the way I recommend to you use this package

https://github.com/spatie/laravel-permission

Activity icon

Replied to (Global) Scope In A Relationship ?

When you change

$quotations = $user->quotations;

to

$quotations = $user->quotations()->get();

Then I think it will work.

Activity icon

Replied to Laravel 8 Migration, Error : Specified Key Was Too Long

Remove this from AppServiceProvider

Schema::defaultStringLength(191);

And change this line

https://github.com/laravel/laravel/blob/8.x/config/database.php#L56

to

'collation' => 'utf8mb4_0900_ai_ci',

Of course run

php artisan config:clear
Activity icon

Commented on Make A Post Model And Migration

To create model and migration at once:

php artisan make:model Post -m

Docs: https://laravel.com/docs/8.x/eloquent#generating-model-classes

Apr
10
1 day ago
Activity icon

Awarded Best Reply on Mark Check Box Checked, Pivot Table

@foreach ($books as $book)
       <div class="form-check">
          <input type="checkbox" value="{{ $book->id }}" {{ $author->books->pluck('id')->contains($book->id) ? 'checked' : '' }}>

          <label>{{ $book->name }}</label>
      </div>
@endforeach

or with in_array it would be

{{ in_array($book->id, $author->books->pluck('id')) ? 'checked' : '' }}
Activity icon

Replied to Mark Check Box Checked, Pivot Table

@foreach ($books as $book)
       <div class="form-check">
          <input type="checkbox" value="{{ $book->id }}" {{ $author->books->pluck('id')->contains($book->id) ? 'checked' : '' }}>

          <label>{{ $book->name }}</label>
      </div>
@endforeach

or with in_array it would be

{{ in_array($book->id, $author->books->pluck('id')) ? 'checked' : '' }}
Activity icon

Replied to Store Unchecked State Of Checkbox

@chaudigv People (or beginners) usually don't think about a code, what is the biggest mistake about programming. They just copy the code and if it works, they use it all the time.

So when you gave them a code which works they don't take any effort how to do it better, or try to understand what's going on.

Which means that they stay on the same level for very long time.

So you are thinking it's better for them, but it's not.

Obviously not.

Activity icon

Replied to Store Unchecked State Of Checkbox

@chaudigv The word obviously is on the right place in your case and don't take it as an insult.

Your code is basically like this logic

$condition = true;

if ($condition == true) {
    $result = true;
} else {
    $result = false;
}

It's same as

$result = $condition;

In the end if somebody has a problem to understand to that logic, then programming is not for him.

Activity icon

Replied to Store Unchecked State Of Checkbox

Yeah I know, has() method return true or false.

But obviously people don't want to write a better code, like @chaudigv

$computer->is_deletion_required = $request->has('is_deletion_required');
Activity icon

Replied to Store Unchecked State Of Checkbox

@rokka I really don't understand what is different what I posted above...

Activity icon

Replied to Filtering The Model Based On A Relationship

You need to use whereHas because you want to filter categories by your relationships

https://laravel.com/docs/8.x/eloquent-relationships#querying-relationship-existence

Also you need to specify additional query conditions for the eager loading query, otherwise you get all data from relationships.

https://laravel.com/docs/8.x/eloquent-relationships#constraining-eager-loads

Since you have there where with or orWhereHas in this case, you need to use logical grouping because you have there an another where condition->where('user_id', $store->id)

https://laravel.com/docs/8.x/queries#logical-grouping

Activity icon

Awarded Best Reply on Filtering The Model Based On A Relationship

$categories = Category::with(['childrenCategories' => $childrenClosure = function ($query) use ($id) {
        $query->where('user_id', $id);
    }, 'products' => $productsClosure = function ($query) use ($id) {
        $query->where('auth_id', $id);
    }])
    ->where('user_id', $store->id)
    ->where(function ($query) use ($childrenClosure, $productsClosure) {
        $query->whereHas('childrenCategories', $childrenClosure)
            ->orWhereHas('products', $productsClosure);
    })
    ->latest()
    ->get();
Activity icon

Replied to Add Condition Along With Pagination For One To Many Relationsip.

$categorySlugs = [
    'current-affairs-2', 'current-events-2'
];

return Post::whereHas('categories', function ($query) use ($categorySlugs) {
        $query->whereIn('slug', $categorySlugs);
    })
     ->where('post_status', 'publish')
     ->whereYear('post_date','2019')
     ->whereMonth('post_date', '10')
     ->newest()
     ->paginate(10);
Activity icon

Replied to Filtering The Model Based On A Relationship

$categories = Category::with(['childrenCategories' => $childrenClosure = function ($query) use ($id) {
        $query->where('user_id', $id);
    }, 'products' => $productsClosure = function ($query) use ($id) {
        $query->where('auth_id', $id);
    }])
    ->where('user_id', $store->id)
    ->where(function ($query) use ($childrenClosure, $productsClosure) {
        $query->whereHas('childrenCategories', $childrenClosure)
            ->orWhereHas('products', $productsClosure);
    })
    ->latest()
    ->get();
Activity icon

Awarded Best Reply on Add Condition Along With Pagination For One To Many Relationsip.

 return $cat->posts()
    ->where('status', 'publish')
    ->whereDate('post_date','2021-03-03')
    ->paginate(10);

You don't need to have eager loading for posts on category.

Activity icon

Replied to Add Condition Along With Pagination For One To Many Relationsip.

So why do you have it here?

>with(['posts'=>function($q) {
                $q->where('status', 'publish')
					->whereDate('post_date','2021-03-03');
            }])-
Activity icon

Replied to Store Unchecked State Of Checkbox

For checkbox you need to use has()

public function update(UpdateComputerRequest $request, Computer $computer) 
{
    $copmuter->update($request->except('is_deletion_required') + [
        'is_deletion_required' => $request->has('is_deletion_required')
    ]);
}

Docs: https://laravel.com/docs/8.x/requests#determining-if-input-is-present

Activity icon

Replied to Add Condition Along With Pagination For One To Many Relationsip.

 return $cat->posts()
    ->where('status', 'publish')
    ->whereDate('post_date','2021-03-03')
    ->paginate(10);

You don't need to have eager loading for posts on category.

Activity icon

Commented on A Few Tweaks And Consideration

With null coalescing operator it could be just

public static function findOrFail($slug)
{
    return static::find($slug) ?? abort(404);
}

Docs: https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op

Activity icon

Replied to Upload Picture Does Not Work Anymore After Update..

You file input doesn't have a name attribute.

<input type="file" id="file_picture_input" name="picture_input">

and remove this hidden input.

<input type="hidden" id="picture_input" name="picture_input">
Activity icon

Replied to Laravel DOMPDF

How do you import css? With asset()? Use public_path() instead.

Apr
09
2 days ago
Activity icon

Commented on Make A Route And Link To It

You can still use Laravel/UI and it will work in all future new versions of Laravel.

Activity icon

Commented on Include CSS And JavaScript

<head> and </head> tags as well.

Activity icon

Awarded Best Reply on Query Builder ->whereMonth('created_at', 'based On User Choice?')

<form action="{{ route('chart') }}" method="GET">
    //
</form>
->whereMonth('created_at', $request->month)
Activity icon

Replied to Query Builder ->whereMonth('created_at', 'based On User Choice?')

<form action="{{ route('chart') }}" method="GET">
    //
</form>
->whereMonth('created_at', $request->month)
Activity icon

Replied to Query Builder ->whereMonth('created_at', 'based On User Choice?')

<select name="month">
    @foreach (range(1, 12) as $month)
        <option value="{{ $month }}">{{ date("F", mktime(0, 0, 0, $month, 1)) }}</option>
    @endforeach
</select>
->whereMonth('created_at', $request->month)
Activity icon

Replied to Problem With A One-to-many Relationship ...

Remove that row from database and create it again.

Activity icon

Replied to Problem With A One-to-many Relationship ...

Always write a code in English and database tables and columns as well.

Activity icon

Replied to Problem With A One-to-many Relationship ...

Why do you have in the select velos?

select * from velos where id = '53ca6f30-5a39-11ea-9fd6-d930c5b6158c';
Activity icon

Replied to API Routes Messed Up - Unable To Post To: Https://mydomain.com/api/allartworks

It has to be

Route::resource('allartworks', 'ArtworkController');

or if you want only one route then

Route::get('allartworks', '[email protected]');
Activity icon

Replied to Problem With A One-to-many Relationship ...

$quotations = Quotation::doesntHave('bicycle')->get();

So with that you retrieve a quotation or quotations with bicycle_id which doesn't exist in bicycles table in column id of course.

Activity icon

Replied to Problem With A One-to-many Relationship ...

It's not a problem with relationship, but with your data.

That's very strange because all datas are ok in the database.

Obviously they are not ok.

$quotations = Quotation::doesntHave('bicycle')->get();

// or

$quotations = Quotation::whereNull('bicycle_id')->get();

With that you will see what is wrong and then fix your data in the database.

Activity icon

Awarded Best Reply on Creating An Assoc. Array Of Next 5 Years

No, this is enough

@include('semesters.partials.form', [
    'years' => ['Please Choose A Year'] + array_combine($years = range(now()->year, now()->year + 5), $years)
])
Activity icon

Replied to Creating An Assoc. Array Of Next 5 Years

No, this is enough

@include('semesters.partials.form', [
    'years' => ['Please Choose A Year'] + array_combine($years = range(now()->year, now()->year + 5), $years)
])
Activity icon

Replied to Creating An Assoc. Array Of Next 5 Years

[
    'years' => ['Please Choose A Year'] + array_combine($years = range(now()->year, now()->year + 5), $years)
]
Activity icon

Replied to Creating An Assoc. Array Of Next 5 Years

What does years have to do with other arrays?

Activity icon

Replied to Creating An Assoc. Array Of Next 5 Years

Why?

Just change your blade file, that's it.

And use $loop variable to detect the first item in the array.

Activity icon

Replied to Creating An Assoc. Array Of Next 5 Years

[
    'years' => ['Please Choose A Year'] + range(now()->year, now()->year + 5)
]
Activity icon

Replied to Creating An Assoc. Array Of Next 5 Years

<select name="year">
    <option>Please Choose A Year</option>

    @foreach (range(now()->year, now()->year + 5) as $year)
        <option value="{{ $year }}">{{ $year }}</option>
    @endforeach
</select
Activity icon

Replied to Config Filesystem To Upload To The Public Folder

@datlechin

<img src="{{ asset("storage/{$file->path}") }}" alt="Image">

In $file->path has to be stored only images/filename.png.

And mark this thread as solved. Thanks.

Community Pillar

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