MichalOravec

Member Since 4 Years Ago

Prievidza, Slovakia

Experience Points
861,470
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
1050
Lessons
Completed
Best Reply Awards
1251
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
861,470 XP
Jan
18
8 hours ago
Activity icon

Replied to Laravel Form

It's same what you have in Form::checkbox

Activity icon

Replied to Recently Viewed Session Based

The first code what I gave you is about ids. If you have an array with ids then just use whereIn

$deals = Deal::whereIn('id', session()->get('deals.recently_viewed', []));
Activity icon

Replied to Laravel Form

@foreach($permission as $value)
    <input type="checkbox" name="permission[]" class="form-control name" value="{{ $value->id }}" {{ in_array($value->id, $rolePermissions) ? 'checked' : '' }}>
@endforeach
Jan
17
1 day ago
Activity icon

Awarded Best Reply on Search Results Pagination Works Not

You need to append a query string q to the url in pagination links

$posts = Post::where('title', 'like', $q = "%{$request->q}%")
    ->orWhere('description', 'like', $q)
    ->paginate(4)
    ->withQueryString();

Docs: https://laravel.com/docs/8.x/pagination#appending-query-string-values

Because you can see it here that it works.

Activity icon

Replied to WithCount Returning Null

It's not about where, if you check only id it;s better to use find() or findOrFail()

If you need to get a collection then use where

$raterTypeSchools = RaterTypeSchool::withCount('raterLists')->where('column', 'something')->get();
Activity icon

Replied to WithCount Returning Null

$raterTypeSchool = RaterTypeSchool::withCount('raterLists')->findOrFail(1);

$raterTypeSchool->rater_lists_count;
Activity icon

Awarded Best Reply on Classic 404, Kind Of Solved It. What's Wrong With This?

You need to add this route

Route::get('services/deleted', '[email protected]')->name('services.deleted');

before

Route::get('services/{service}', '[email protected]')->name('services.show');

So your routes order should be

Route::get('services', '[email protected]')->name('services.index');
Route::get('services/create', '[email protected]')->name('services.create');
Route::post('services','[email protected]')->name('services.store');

Route::get('services/deleted', '[email protected]')->name('services.deleted');
Route::get('services/{service}', '[email protected]')->name('services.show');
Route::get('services/{service}/edit', '[email protected]')->name('services.edit');
Route::patch('services/{service}','[email protected]')->name('services.update');
Route::delete('services/{service}', '[email protected]')->name('services.destroy');
Jan
16
2 days ago
Activity icon

Replied to Recently Viewed Session Based

Probably yes, I'm busy right now.

Activity icon

Replied to Recently Viewed Session Based

$dealIds = collect(session()->get('deals', []))->pluck('id');

if ($dealIds->contains($deal->getKey()) && $index = $dealIds->search($deal->getKey())) {
    session()->pull("deals.{$index}");
}

session()->push('deals', $deal);
Activity icon

Awarded Best Reply on Php Artisan Route:list -> Route Is Not Listed (Laravel 5.5)

Oh ok, you have same uri contact there in both routes. The second one replace the first one.

So change it

Route::get('contact', '[email protected]')->name('contact.index');
Route::get('contact'/create, '[email protected]')->name('contact.create');
Activity icon

Replied to Php Artisan Route:list -> Route Is Not Listed (Laravel 5.5)

Oh ok, you have same uri contact there in both routes. The second one replace the first one.

So change it

Route::get('contact', '[email protected]')->name('contact.index');
Route::get('contact'/create, '[email protected]')->name('contact.create');
Activity icon

Awarded Best Reply on WhereDoesntHave

You forget to add use to pass variable to the closure.

$post = Post::find(1);
    
return Category::whereDoesntHave('posts', function ($query) use ($post) {
    $query->where('id', $post->id);
})->get();
Activity icon

Replied to WhereDoesntHave

You forget to add use to pass variable to the closure.

$post = Post::find(1);
    
return Category::whereDoesntHave('posts', function ($query) use ($post) {
    $query->where('id', $post->id);
})->get();
Activity icon

Replied to Target Class [1] Does Not Exist.

It doesn't matter if you have Laravel 8 or not. It's same on all Laravel versions.

The main point is the order of your routes.

https://laravel.com/docs/7.x/controllers#restful-supplementing-resource-controllers

Activity icon

Replied to Recently Viewed Session Based

Yes getKey() returns just primary key of your table, usually an id.

If you want to do that, just add $deal to the session, but then you need to use a collection to apply same logic in_array, array_search etc.

Activity icon

Awarded Best Reply on Recently Viewed Session Based

Don't use wildcard *, be more specific to which view you want to add it.

View::composer([
    'includes.interested.SOMETHING'
], InterestedComposer::class);

The code in the controller should be something like this

if (in_array($deal->getKey(), $deals = session()->get('deals.recently_viewed', []))) {
    $index = array_search($deal->getKey(), $deals);

    session()->pull("deals.recently_viewed.{$index}");
}

session()->push('deals.recently_viewed', $deal->getKey());
Activity icon

Replied to Target Class [1] Does Not Exist.

I think a problem is that you have other routes after resource controller

Docs: https://laravel.com/docs/8.x/controllers#restful-supplementing-resource-controllers

Activity icon

Replied to Recently Viewed Session Based

Don't use wildcard *, be more specific to which view you want to add it.

View::composer([
    'includes.interested.SOMETHING'
], InterestedComposer::class);

The code in the controller should be something like this

if (in_array($deal->getKey(), $deals = session()->get('deals.recently_viewed', []))) {
    $index = array_search($deal->getKey(), $deals);

    session()->pull("deals.recently_viewed.{$index}");
}

session()->push('deals.recently_viewed', $deal->getKey());
Activity icon

Replied to Search Results Pagination Works Not

You need to append a query string q to the url in pagination links

$posts = Post::where('title', 'like', $q = "%{$request->q}%")
    ->orWhere('description', 'like', $q)
    ->paginate(4)
    ->withQueryString();

Docs: https://laravel.com/docs/8.x/pagination#appending-query-string-values

Because you can see it here that it works.

Activity icon

Replied to Recently Viewed Session Based

In the service provider where you register your composer add this to register method

But it probably doesn't cause that problem.

/**
 * Register the application services.
 *
 * @return void
 */
public function register()
{
    $this->app->singleton(InterestedComposer::class);
}

And I guess you have to check existense of that id in deals.recently_viewed, if it exists there you have to remove it and add it to the end.

Activity icon

Replied to Add Validation Rule (one Of Both Required)

You don't have to mark me again. I saw it. If I knew an answer I would reply to you.

Activity icon

Awarded Best Reply on How To Use Translation Inside Function In Model

This should work

return $now->diffInDays($this->ends_at) . trans_choice('day|days', $now->diffInDays($this->ends_at));
Activity icon

Replied to How To Use Translation Inside Function In Model

This should work

return $now->diffInDays($this->ends_at) . trans_choice('day|days', $now->diffInDays($this->ends_at));
Jan
15
3 days ago
Activity icon

Replied to How To Save Dynamic Form In Laravel?

I recommend to you use template engine, for example Handlebars. Instead of concating html in js.

https://handlebarsjs.com/

Activity icon

Replied to Get Current Guard From A Middleware

Add ...$guards to the handle method in your middleware

public function handle(Request $request, Closure $next, ...$guards)
{
    // in $guards you have current guards
}
Activity icon

Replied to How To Save Dynamic Form In Laravel?

You have there an array, so it has to be like this

public function rules()
{
    return [
        'title.*' => 'required',
        'link.*' => 'required',
    ];
}

Docs: https://laravel.com/docs/8.x/validation#validating-arrays

Activity icon

Replied to How To Save Dynamic Form In Laravel?

Where is a validation? Add it and you avoid this problems.

https://laravel.com/docs/8.x/validation

Activity icon

Replied to How To Get Only Specific Year In Laravel

@devhoussam123 Why? You can't do it better.

Activity icon

Replied to How To Get Only Specific Year In Laravel

@devhoussam123 I really don't know what you were thinking about when you had the correct answer in your question...

Activity icon

Replied to Add Validation Rule (one Of Both Required)

Just add nullable and required_without there.

'bannUntil' => 'nullable|required_without:permanentBan|date_format:d.m.Y H:i',
'permanentBan' => 'nullable|required_without:bannUntil|accepted',
Activity icon

Awarded Best Reply on How To Order By Relationship ?

@godzilaravel You need to add another join with alias name, because it's same table.

Certificate::select('certifications.*')
    ->join('users', 'users.id', '=', 'certifications.user_id')
    ->join('users as directors', 'directors.id', '=', 'users.director_id')
    ->orderBy('directors.first_name')
    ->get();
Jan
14
4 days ago
Activity icon

Replied to How To Order By Relationship ?

@godzilaravel You need to add another join with alias name, because it's same table.

Certificate::select('certifications.*')
    ->join('users', 'users.id', '=', 'certifications.user_id')
    ->join('users as directors', 'directors.id', '=', 'users.director_id')
    ->orderBy('directors.first_name')
    ->get();
Activity icon

Replied to How To Order By Relationship ?

It's same way, just use directory_id

Activity icon

Awarded Best Reply on Function For Subtract All Column Records?

$result = DB::table('table_name')->sum('star_value');

Just replace table_name with your table from database.

Activity icon

Replied to Function For Subtract All Column Records?

$result = DB::table('table_name')->sum('star_value');

Just replace table_name with your table from database.

Activity icon

Replied to How To Order By Relationship ?

You need to use joins for that

Certificate::select('certifications.*')
    ->join('users', 'users.id', '=', 'certifications.user_id')
    ->orderBy('users.first_name')
    ->get();

Docs: https://laravel.com/docs/8.x/queries#joins

Activity icon

Replied to Are Route Resources Best Practice For My Application?

For API I'd use Route::apiResource, it's without create and edit method.

Docs: https://laravel.com/docs/8.x/controllers#api-resource-routes

Activity icon

Replied to Collections 'remove' Method ?

@sr57 What do you want to say with a link to another thread?

Activity icon

Replied to Blade Checkbox Returns Null When Unchecked

@vincej I would use ternary operator instead of if in checkbox.

<input type="checkbox" name="staff" value="1" {{ $child->staff ? 'checked' : '' }}>
Jan
13
5 days ago
Activity icon

Awarded Best Reply on Eager Loading Used But I Still Get So Many Queries

I guess you need to do nested eager loading

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

You don't know a loop variable?

https://laravel.com/docs/8.x/blade#the-loop-variable

And those queries are not related to the code you showed.

Activity icon

Replied to Eager Loading Used But I Still Get So Many Queries

It has to be something else, because this code is correct.

public function index()
{
    $jobs = Job::with(['company', 'location',  'category', 'tags'])
        ->orderByDesc('updated_at')
        ->where('active', 1)
        ->paginate(15);

    return view('job.index', compact('jobs'));
}
@foreach ($jobs as $job)
    {{ $job->title }}

    {{ $job->company->name }}

    {{ $job->location->name }}
@endforeach
Activity icon

Replied to Eager Loading Used But I Still Get So Many Queries

What do you have in job.index.blade.php

Because your main problem is locations table. And in your code is nothing with that table.

Activity icon

Replied to Eager Loading Used But I Still Get So Many Queries

Seriously? How can we help you without code? Even in the OP you have different query...

Activity icon

Replied to Eager Loading Used But I Still Get So Many Queries

How I said Those queries are not related to the code you showed.

Activity icon

Replied to Laravel Blade How To Concatenate Youtube Iframe Youtube Id From Database In Blade

That key is real video.

<iframe width="580" height="360" src="https://www.youtube.com/embed/QRfj1VCg16Y"></iframe>

So

<iframe width="580" height="360" src="https://www.youtube.com/embed/{{ $key }}"></iframe>

Where is a variable where you have code from youtube, use your variable.

Community Pillar

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