MichalOravec

Member Since 4 Years Ago

Prievidza, Slovakia

Experience Points
879,410
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
1279
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
879,410 XP
Jan
27
18 hours ago
Activity icon

Awarded Best Reply on Class 'Barryvdh\Debugbar\ServiceProvider' Not Found In \src\Illuminate\Foundation\ProviderRepository.php

Laravel uses package auto discovery, how I said just remove it from that provider array.

Activity icon

Replied to Class 'Barryvdh\Debugbar\ServiceProvider' Not Found In \src\Illuminate\Foundation\ProviderRepository.php

Laravel uses package auto discovery, how I said just remove it from that provider array.

Activity icon

Replied to Class 'Barryvdh\Debugbar\ServiceProvider' Not Found In \src\Illuminate\Foundation\ProviderRepository.php

Just remove Barryvdh\Debugbar\ServiceProvider::class, from providers array in config/app.php

Activity icon

Replied to SQL Gurus? How Can I Pivot This?

@phpmick Mark this thread as solved. Thanks.

Activity icon

Awarded Best Reply on Improve Search Functionality

You need a full text search for that, you can use this trait

<?php

namespace App\Traits;

trait FullTextSearch
{
    /**
     * Replaces spaces with full text search wildcards
     *
     * @param string $term
     * @return string
     */
    protected function fullTextWildcards($term)
    {
        // removing symbols used by MySQL
        $reservedSymbols = ['-', '+', '<', '>', '@', '(', ')', '~'];

        $term = str_replace($reservedSymbols, '', $term);

        $words = explode(' ', $term);

        foreach ($words as $key => $word) {
            if (strlen($word) >= 3) {
                $words[$key] = "{$word}*";
            }
        }

        return implode(' ', $words);
    }

    /**
     * Scope a query that matches a full text search of term.
     *
     * @param \Illuminate\Database\Eloquent\Builder $query
     * @param string $term
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeSearch($query, $term)
    {
        $columns = collect($this->searchable)->map(function ($column) {
            return $this->qualifyColumn($column);
        })->implode(',');

        $query->whereRaw("MATCH ({$columns}) AGAINST (? IN BOOLEAN MODE)", $this->fullTextWildcards($term));

        return $query;
    }
}

Example of Article model

<?php

namespace App\Models;

use App\Traits\FullTextSearch;
use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    use FullTextSearch;

    /**
     * The columns of the full text index
     */
    protected $searchable = [
        'title',
        'body'
    ];
}

Then you can use it like this

$articles = Article::search('some text for fulltext')->get();

Or course important things is that you have to add full text index in your migration

DB::statement('ALTER TABLE articles ADD FULLTEXT articles_title_body_fulltext (title, body)');
Activity icon

Replied to Improve Search Functionality

You need a full text search for that, you can use this trait

<?php

namespace App\Traits;

trait FullTextSearch
{
    /**
     * Replaces spaces with full text search wildcards
     *
     * @param string $term
     * @return string
     */
    protected function fullTextWildcards($term)
    {
        // removing symbols used by MySQL
        $reservedSymbols = ['-', '+', '<', '>', '@', '(', ')', '~'];

        $term = str_replace($reservedSymbols, '', $term);

        $words = explode(' ', $term);

        foreach ($words as $key => $word) {
            if (strlen($word) >= 3) {
                $words[$key] = "{$word}*";
            }
        }

        return implode(' ', $words);
    }

    /**
     * Scope a query that matches a full text search of term.
     *
     * @param \Illuminate\Database\Eloquent\Builder $query
     * @param string $term
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeSearch($query, $term)
    {
        $columns = collect($this->searchable)->map(function ($column) {
            return $this->qualifyColumn($column);
        })->implode(',');

        $query->whereRaw("MATCH ({$columns}) AGAINST (? IN BOOLEAN MODE)", $this->fullTextWildcards($term));

        return $query;
    }
}

Example of Article model

<?php

namespace App\Models;

use App\Traits\FullTextSearch;
use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    use FullTextSearch;

    /**
     * The columns of the full text index
     */
    protected $searchable = [
        'title',
        'body'
    ];
}

Then you can use it like this

$articles = Article::search('some text for fulltext')->get();

Or course important things is that you have to add full text index in your migration

DB::statement('ALTER TABLE articles ADD FULLTEXT articles_title_body_fulltext (title, body)');
Activity icon

Replied to SQL Gurus? How Can I Pivot This?

It doesn't matter in this case, CASE is better to use when you have more options.

Activity icon

Replied to POST Request

Don't use else part when you use return

public function checkImei(Request $request)
{
    $user = User::select('id', 'name', 'email')
        ->where('imei', $request->imei)->first();

    return $user ?? response()->json([
        'data' => ['Invalid Imei']
    ]);
}
Activity icon

Replied to POST Request

@eliekhazzaka This is the best reply in this thread so far.

I would return it directly instead of save it to the user variable.

Activity icon

Replied to SQL Gurus? How Can I Pivot This?

$data = DB::table('table_name')
    ->selectRaw('date, SUM(IF(event = "click", count, 0)) as click-count, SUM(IF(event = "open", count, 0)) as open-count')
    ->groupBy('date')
    ->get();
Jan
26
1 day ago
Activity icon

Replied to Button Not Working.

Button doesn't have href attribute.

<a class="btn btn-success" href="/admin/test/editquestions/{{ $test->id }}">Questions</a>
Activity icon

Awarded Best Reply on Laravel Get Json Response Using Ajax

In controller

return response()->json(['price' => $total]);

In js

$("#totalPrice").text(data.price);

By the way queries in the controller could be

$priceA = PriceA::findOrFail($a_id)->price;

$priceB = PriceB:::findOrFail($b_id)->price;
Activity icon

Replied to Model Not Being Found.

You have to import that class

So add this to the top of your controller.

use App\Question;

And Question.php file has to be in app directory.

Activity icon

Replied to Laravel Get Json Response Using Ajax

In controller

return response()->json(['price' => $total]);

In js

$("#totalPrice").text(data.price);

By the way queries in the controller could be

$priceA = PriceA::findOrFail($a_id)->price;

$priceB = PriceB:::findOrFail($b_id)->price;
Activity icon

Awarded Best Reply on Insert Data Into Database

Yes exactly

In the example below I use 1, 2, 3, 4 as options for jobChances, so you have to have the column with 4 options as last.

$data = [];

foreach ([1, 2, 3, 4] as $value) {
    for ($i = 0; $i < pow(2, 6); $i++) {
        $data[] = array_combine([
            'content', 'presence', 'structure', 'reputation', 'location', 'distance', 'jobChances'
        ], str_split(str_pad(decbin($i), 6, 0, STR_PAD_LEFT)) + [
            6 => $value
        ]);
    }
}

DB::table('s_g1_s')->insert($data);
Activity icon

Replied to Insert Data Into Database

Yes exactly

In the example below I use 1, 2, 3, 4 as options for jobChances, so you have to have the column with 4 options as last.

$data = [];

foreach ([1, 2, 3, 4] as $value) {
    for ($i = 0; $i < pow(2, 6); $i++) {
        $data[] = array_combine([
            'content', 'presence', 'structure', 'reputation', 'location', 'distance', 'jobChances'
        ], str_split(str_pad(decbin($i), 6, 0, STR_PAD_LEFT)) + [
            6 => $value
        ]);
    }
}

DB::table('s_g1_s')->insert($data);
Activity icon

Replied to Insert Data Into Database

$columns = [
    'content', 'presence', 'structure', 'reputation', 'location', 'distance', 'jobChances'
];

$data = [];

for ($i = 0; $i < pow(2, 7); $i++) {  
    $values = str_split(str_pad(decbin($i), 7, 0, STR_PAD_LEFT));

    $data[] = array_combine($columns, $values);
}

DB::table('s_g1_s')->insert($data);

Or a little bit shorter

$data = [];

for ($i = 0; $i < pow(2, 7); $i++) {
    $data[] = array_combine([
        'content', 'presence', 'structure', 'reputation', 'location', 'distance', 'jobChances'
    ], str_split(str_pad(decbin($i), 7, 0, STR_PAD_LEFT)));
}

DB::table('s_g1_s')->insert($data);
Activity icon

Replied to How To Query Where Pivot Table Ids Equal Given Value ?

Logic in your example is opposite, but other way how to do it is to use joins, which is better for performance.

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

Activity icon

Replied to How To Define Name For Slug?

You have a problem with the basics so watch this series https://laracasts.com/series/laravel-6-from-scratch

Please don't ask for help any more on this forum without watching that series.

Activity icon

Replied to How Ti Create Simple Page?

Good point about the laravel from scratch series.

Jan
25
2 days ago
Activity icon

Replied to Get Json Values

Post or page ids are two different things which have nothing to do with each other. So why do you want to compare it?

Activity icon

Replied to Get Json Values

Exactly the same what you did before.

Activity icon

Replied to Get Json Values

public function getPost($id)
{
    return response()->json([
        'pages' => Page::latest()->get(),
        'posts' => Post::latest()->get()
    ]);
}

Then in ajax success method

success: function(data) {
    data.pages; // here you have pages

    data.posts; // here you have posts
}
Activity icon

Replied to From Query

@www888 Better if you do it in the database directly

$locations = Location::distinct()->orderBy('name')->pluck('name');
Activity icon

Replied to Undefined Variable

With eloquent it will be just like this

$questions = Question::with('answers')->where('testid', $id)->get();

Watch section 7 of this series https://laracasts.com/series/laravel-6-from-scratch

And read the docs:

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

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

Jan
24
3 days ago
Activity icon

Awarded Best Reply on Can't Get Full Url In

@vahidmarali It's imposible to get the fragmet (something after #) on the server side.

Activity icon

Replied to Method App\Http\Requests\MarketRequest::move Does Not Exist.

In your case

$file->move(public_path('images/markets'), $fullName);

By the way use file storage.

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

Activity icon

Awarded Best Reply on How Call Local Scopes In Controller With One To Many Relationship

You forget to add parenthesis.

public function postsByTopic($id)
{
    $topic = Topic::findOrFail($id);

    $latest = $topic->posts()->latest()->get();

    $published = $topic->posts()->published()->get();
}
Activity icon

Replied to How Call Local Scopes In Controller With One To Many Relationship

You forget to add parenthesis.

public function postsByTopic($id)
{
    $topic = Topic::findOrFail($id);

    $latest = $topic->posts()->latest()->get();

    $published = $topic->posts()->published()->get();
}
Activity icon

Awarded Best Reply on Argument 1 Passed To Milano\Payment\Repositories\PaymentRepo::getDailySummery() Must Be An Instance Of

Which class do you import in PaymentRepo as Collection?

It has to be

use Illuminate\Support\Collection;
Activity icon

Awarded Best Reply on Error Call To A Member Function Sluggable() On String

You need to have agent_slug in fillable array of AgentBalance model.

Activity icon

Replied to Error Call To A Member Function Sluggable() On String

You need to have agent_slug in fillable array of AgentBalance model.

Activity icon

Replied to Argument 1 Passed To Milano\Payment\Repositories\PaymentRepo::getDailySummery() Must Be An Instance Of

Which class do you import in PaymentRepo as Collection?

It has to be

use Illuminate\Support\Collection;
Activity icon

Replied to Error Call To A Member Function Sluggable() On String

Just use helper

use Illuminate\Support\Str; // add this to the top

$manager = AgentBalance::create([
    'agent_slug'  => Str::slug($request->input('username'))
]);

https://laravel.com/docs/8.x/helpers#method-str-slug

Activity icon

Replied to Cache::get() Not Working As Expected

It works as expected:

You may even pass a closure as the default value. The result of the closure will be returned if the specified item does not exist in the cache.

With get() you just retrieve data from cache, but you have nothing in cache right now, so just return result from closure.

Activity icon

Replied to Cache::get() Not Working As Expected

The cache with key keyA doesn't exist, so everytime in your case run that callback.

$keyA = Cache::remember('keyA', now()->addMinutes(5), function () {
    return (new ExternalHelper)->fetchData();
});

Docs: https://laravel.com/docs/8.x/cache#retrieve-store

Activity icon

Awarded Best Reply on Problem While Using Links() And Nav Tabs : Redirecting To Page 2 Of Other Tabs While It Does Not Exist

You have to set different page name with third parameter in paginate()

This is just an example.

$users = User::paginate(10, ['*'], 'users');

$posts = Post::paginate(10, ['*'], 'posts');

Then you will see ?users=2 or ?posts=2 in the url instead of ?page=2.

https://laravel.com/api/8.x/Illuminate/Database/Eloquent/Builder.html#method_paginate

Activity icon

Replied to Problem While Using Links() And Nav Tabs : Redirecting To Page 2 Of Other Tabs While It Does Not Exist

You have to set different page name with third parameter in paginate()

This is just an example.

$users = User::paginate(10, ['*'], 'users');

$posts = Post::paginate(10, ['*'], 'posts');

Then you will see ?users=2 or ?posts=2 in the url instead of ?page=2.

https://laravel.com/api/8.x/Illuminate/Database/Eloquent/Builder.html#method_paginate

Jan
23
4 days ago
Activity icon

Awarded Best Reply on Update A Form With Different Inputs By Having A Specific Schema In The Db Table

foreach ($request->all() as $key => $value) {
    Settings::where('name', $key)->update([
        'value' => $value
    ]);
}
Activity icon

Replied to Update A Form With Different Inputs By Having A Specific Schema In The Db Table

foreach ($request->all() as $key => $value) {
    Settings::where('name', $key)->update([
        'value' => $value
    ]);
}
Activity icon

Replied to How To Save User_id With Request All?

@iroxbir Sorry it has to be auth()->id(), I fixed it.

Activity icon

Replied to How To Save User_id With Request All?

If you use form request like in this case, it's really ok.

Jan
22
5 days ago
Activity icon

Replied to How To Save User_id With Request All?

I guess that it has to be an authenticated user.

public function store(CategoryRequest $request)
{
    Category::create($request->all() + [
        'user_id' => auth()->id()
    ]);
    
    return redirect()->route('categories.index');
}

Community Pillar

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