MichalOravec

MichalOravec

Member Since 4 Years Ago

Prievidza, Slovakia

Experience Points
502,290
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
926
Lessons
Completed
Best Reply Awards
694
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 50
502,290 XP
Aug
11
18 hours ago
Activity icon

Replied to ->get() Not Considering Where Clauses

It should be

$results = Wantad::where('price', '<=', 20000)->get();

Docs: https://laravel.com/docs/7.x/eloquent#retrieving-models

Activity icon

Replied to Update Two Tables With If Condition

Thrown your project to the trash and start again. And don't ask why, because it's obvious.

Activity icon

Replied to Query Model When Column Not Null

$this->trips()->whereNotNull('date_to')->where('date_to', '<=', Carbon::parse($date)->toDateString())->get();
Activity icon

Replied to Order Data Debend On Value In Another Table

@ethar Same way how you do it before.

Orders::with(['users:id,fname,lname,telno', 'products', 'admins', 'address.city'])

I do it just for users. So you can see that it's same.

Activity icon

Replied to Order Data Debend On Value In Another Table

@ethar You can read this for example https://phptherightway.com/

But in your case model should be in singular form.

Why your method is orderssearch for me would be better if it's just search method in OrdersController.

Next you have $request->product but actually it's just type of order DESC or ASC, so why you named it product?

View is admin.orders.indexorder why not just admin.orders.index or at least admin.orders.index-order with dash, because it's unreadble. Or if would be in search method then admin.orders.search.

Activity icon

Replied to Call To Undefined Method StdClass::fullname() (View: C:\xampp\htdocs\crm\resources\views\ticketing\user\edit.blade.php)

@neeraj1005 If you have model for tbl_contacts use model. It's not necessary to do it in that way.

Activity icon

Replied to Order Data Debend On Value In Another Table

public function orderssearch(Request $request)
{
    $orders = Orders::with(['users', 'products', 'admins', 'address.city'])
        ->select('orders.*')
        ->join('products', 'products.id', '=', 'orders.products_id')
        ->when($request->product, function ($query, $by) {
            return $query->orderBy('products.num_sell', $by == 'sell_asc' ? 'asc' : 'desc');
        }, function ($query) {
            return $query->orderByDesc('orders.id');
        })->paginate(10);

    return view('admin.orders.indexorder', compact('orders'));
}

Docs: https://laravel.com/docs/7.x/queries#conditional-clauses

* But your naming of variables, models etc. is not good.

Activity icon

Replied to Call To Undefined Method StdClass::fullname() (View: C:\xampp\htdocs\crm\resources\views\ticketing\user\edit.blade.php)

When you work with DB::tableyou get collection of stdClass instead of model.

So change it to this

$contacts = Tbl_contacts::where('active',1)->where(function ($query) {
    $query->where('uid', Auth::user()->id)->orWhere('uid',0);
})->get();
Activity icon

Awarded Best Reply on Eager Loading Count Not Working

You can add this to your model

protected $withCount = ['favorites'];
Activity icon

Replied to Eager Loading Count Not Working

You can add this to your model

protected $withCount = ['favorites'];
Activity icon

Replied to How To Initialize A Global Variable Inside One Function And Access In Another Function Inside Controller

Use session for that

public function store(CheckoutRequest $request)
{
    // other code

    $request->session()->put('customerId', $customer->id);

    // other code
}

public function paymentDetails(Request $request)
{
    if ($request->session()->has('customerId')) {
        $customerId = $request->session()->get('customerId');
    }
}

Docs: https://laravel.com/docs/7.x/session

Activity icon

Replied to Cors Issue With Login From Localhost:3000 To Localhost:8000

@Camo It could be just

public function handle($request, Closure $next)
{
    $response = $next($request);

    $response->header('Access-Control-Allow-Origin', '*');

    return $response;
}

so without set

Activity icon

Replied to Automatically Pass Foreign Key When Create From Relationship

@j0wz The other way is doing it like this

$holding = Holding::create(['reference' => Str::uuid()]);

$user = $holding->users()->create([
    'firstname' => 'John',
    'lastname' => 'Doe',
    'email' => '[email protected]',
    'password' => bcrypt('password')
]);
Activity icon

Replied to Automatically Pass Foreign Key When Create From Relationship

@s4muel It would be work if he has hasMany relationship, but it's belongsTo.

Activity icon

Replied to Automatically Pass Foreign Key When Create From Relationship

Look on this

https://laravel.com/docs/7.x/eloquent-relationships#updating-belongs-to-relationships

$user = User::create([
    'firstname' => 'John',
    'lastname' => 'Doe',
    'email' => '[email protected]',
    'password' => bcrypt('password')
]);

$holding = Holding::create(['reference' => Str::uuid()]);

$user->holding()->associate($holding);

$user->save();
Aug
10
1 day ago
Activity icon

Awarded Best Reply on How To Make The Bank Name To Redirect To Edit Form

You have two parameters which are required in your route.

<a href="{{ route('bank.edit_form', ['bank_name' => $bankname, 'bank_id' => $bank[0]['bankId']]) }}" >{{ $bankname }}<a>

Actually I don't know where you store your bank_name and bank_id in which variable.

Activity icon

Awarded Best Reply on How To Select Multiple Value From Dropdown

You <select> should have multiple attribute

For example

<select name="pets" multiple>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
</select>

Documentation: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select

<div class="form-group">
    <label for="campaign_provider">Client: </label>
    
    <select class="form-control" id="campaign_provider" name="campaign_provider" multiple disabled>
        @foreach($banks as $bank)
            <option value="{{ $bank['bank_id'] }}" {{ $campaign->contains('bank_id', $bank['bank_id'] ? 'selected="selected"' : '' }}
                {{ $bank['name'] }}
            </option>
        @endforeach
    </select>
</div>

For select multiple values you can use contains from collection.

Documentation: https://laravel.com/docs/7.x/collections#method-contains

Activity icon

Awarded Best Reply on How To Call Desired Values In Dropdown List

In controller filter only for those units

$units = $units->filter(function ($item) {
    return in_array($item->unit, ['g', 'kg']);
});

Docs: https://laravel.com/docs/7.x/collections#method-filter

Remove your part in @php instead of use this

<option value="{{ $unit->unit }}" {{ $unit->unit == old('weight_unit') ? 'selected' : '' }}>{{$unit->unit}}</option>
Activity icon

Replied to WantsJson Does Not Exist.

Not response() but request()

if (request()->wantsJson()) {
    //
}

And wantsJson() not wantJson(), you miss s there.

Activity icon

Replied to Cannot Display The Photo In The Storage File

I don't know what you have in $img->image->first()->url but it should be something like this

<img src="{{ asset('storage/'.$img->image->first()->url) }}">
Activity icon

Awarded Best Reply on How To Validate Two Combined Unique Column In Laravel Controller

use Illuminate\Validation\Rule;

$clientId; // your actual client id

$this->validate($request, [
    'email' => ['required', 'email', Rule::unique('customers')->where(function ($query) use ($clientId) {
        $query->where('client_id', $cliendId);
    })]
]);

Docs: https://laravel.com/docs/7.x/validation#rule-unique (look for Adding Additional Where Clauses)

Activity icon

Replied to Reference Relationship With Bracket And Without

Yes of course. But you can do what I posted before.

Activity icon

Replied to Adding A Global Scope To Count

@nickywan123 You have belongsTo relationship for creator. So count is everytime just one for creator.

Activity icon

Replied to How To Validate Two Combined Unique Column In Laravel Controller

use Illuminate\Validation\Rule;

$clientId; // your actual client id

$this->validate($request, [
    'email' => ['required', 'email', Rule::unique('customers')->where(function ($query) use ($clientId) {
        $query->where('client_id', $cliendId);
    })]
]);

Docs: https://laravel.com/docs/7.x/validation#rule-unique (look for Adding Additional Where Clauses)

Activity icon

Replied to Reference Relationship With Bracket And Without

@nickywan123 You need to do something like this

$thread = Thread::with(['creator', 'replies' => function ($query) {
    $query->latest();
}])->withCount('replies')->get();
{{ $thread->creator->name }}

@if ($thread->replies->isNotEmpty())
    @foreach ($thread->replies as $reply)
        <!-- show reply -->
    @endforeach
@endif

$thread->replies() and this $thread->creator() return query builder which you have to finish with get(), first() etc. to retrieve data from the database.

Your example should be

foreach($thread->replies()->get() as $reply)
Activity icon

Replied to Reference Relationship With Bracket And Without

Here you work with query builder

$thread->replies()->count();

but here with collection

$thread->replies->count();

Same here this return query builder

$thread->creator()

but this return a relationship

$thread->creator

https://laravel.com/docs/7.x/eloquent-relationships#relationship-methods-vs-dynamic-properties

Activity icon

Replied to Localization Issues

I recommend to you use this package

https://github.com/mcamara/laravel-localization

Activity icon

Awarded Best Reply on Delete Polymorphic Relationship

$reply->favorites()->delete();

$reply->delete();

Or if you want to run some events then

$reply->favorites->each->delete();

$reply->delete();
Activity icon

Replied to Delete Polymorphic Relationship

$reply->favorites()->delete();

$reply->delete();

Or if you want to run some events then

$reply->favorites->each->delete();

$reply->delete();
Aug
09
2 days ago
Activity icon

Awarded Best Reply on How To Hints Email Before Send Password Reset Link

Add this to your ForgotPasswordController

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

/**
 * Get the response for a successful password reset link.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  string  $response
 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
 */
protected function sendResetLinkResponse(Request $request, $response)
{
    // flash message or whatever here

    return $request->wantsJson()
                ? new JsonResponse(['message' => trans($response)], 200)
                : back()->with('status', trans($response));
}
Activity icon

Replied to JS - Reg Ex New Value In Str Replace

var oldValue = 'https://nl.wikipedia.org/wiki/Republikeinwever';

var newValue = oldValue.replace('wikipedia', 'm.wikipedia');
Activity icon

Replied to Check Whether The Json Value Is Empty Or Not

$configuration = json_decode(shop()->setting->whatsapp_configuration, true)->send_message_via ?? null;

Then just use if statement.

Activity icon

Awarded Best Reply on How Can I Get The Value Of `<a>` Tag From Blade Into `js` File Using JQuery?

In html

<div class="p-rating">
    <a data-value="1" class="btn RatingAjax1">
        <i class="fa fa-star-o"></i>
    </a>
    
    <a data-value="2" class="btn RatingAjax2">
        <i class="fa fa-star-o"></i>
    </a>
    
    <a data-value="3" class="btn RatingAjax3">
        <i class="fa fa-star-o"></i>
    </a>
    
    <a data-value="4" class="btn RatingAjax4">
        <i class="fa fa-star-o"></i>
    </a>
    
    <a data-value="5" class="btn RatingAjax5">
        <i class="fa fa-star-o fa-fade"></i>
    </a>
</div>

In js

$(function() {
    $(document).on('click', '.p-rating a', function(e) {
        e.preventDefault();

        var el = $(this);

        var value = el.data('value');

        alert(value);
    });
});

And then you get exact value.

Activity icon

Replied to How Can I Get The Value Of `<a>` Tag From Blade Into `js` File Using JQuery?

In html

<div class="p-rating">
    <a data-value="1" class="btn RatingAjax1">
        <i class="fa fa-star-o"></i>
    </a>
    
    <a data-value="2" class="btn RatingAjax2">
        <i class="fa fa-star-o"></i>
    </a>
    
    <a data-value="3" class="btn RatingAjax3">
        <i class="fa fa-star-o"></i>
    </a>
    
    <a data-value="4" class="btn RatingAjax4">
        <i class="fa fa-star-o"></i>
    </a>
    
    <a data-value="5" class="btn RatingAjax5">
        <i class="fa fa-star-o fa-fade"></i>
    </a>
</div>

In js

$(function() {
    $(document).on('click', '.p-rating a', function(e) {
        e.preventDefault();

        var el = $(this);

        var value = el.data('value');

        alert(value);
    });
});

And then you get exact value.

Aug
08
3 days ago
Activity icon

Awarded Best Reply on Get WithCount() Of Nested Relationship

@mallaury Try it like this

$departmentLessons = auth()->user()->myDepartmentLessons()->with(['lesson' => function ($query) {
    $query->withCount('documents');
}])->get();
Activity icon

Replied to Get WithCount() Of Nested Relationship

@mallaury Please consider marking the Best Reply above if your issue has been solved.

Activity icon

Replied to Get WithCount() Of Nested Relationship

@mallaury Try it like this

$departmentLessons = auth()->user()->myDepartmentLessons()->with(['lesson' => function ($query) {
    $query->withCount('documents');
}])->get();
Aug
07
4 days ago
Activity icon

Replied to Pagination

When you add this macro to your AppServiceProvider

use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;

Collection::macro('paginate', function ($perPage, $total = null, $page = null, $pageName = 'page') {
    $page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName);

    return new LengthAwarePaginator($this->forPage($page, $perPage), $total ?: $this->count(), $perPage, $page, [
        'path' => LengthAwarePaginator::resolveCurrentPath(),
        'pageName' => $pageName,
    ]);
});

Then you can paginate on the collection.

Activity icon

Replied to Datatable Alternatives

You can use partials view there, for example

->editColumn('some-column', function ($item) {
    return view('partials.datatable.link', [
        'link' => route('some-route'),
        'text' => $iten->text
    ]);
})

View in views/partials/datatable/link.blade.php

<a href="{{ $link }}" target="{{ $target ?? '_self' }}">{{ $text }}</a>
Activity icon

Replied to Laravel 7 Redirect Away Shows Redirect Url On White Page

@wahidulalam Which editor do you use?

If you have Sublime Text there you can save file just with UTF-8 without BOM.

And also you can search there with regular expression where you can put this

\s+<\?php

and it will search for all spaces before <?php

In toolbar Find -> Find in Files

https://www.youtube.com/watch?v=b0m_opKVpa8

Activity icon

Replied to Laravel 7 Redirect Away Shows Redirect Url On White Page

Probably problem will be with UTF-8 with BOM. You have to save your files withou BOM.

Or check if you don't have space before <?php in your app.

It has to be on the first line of each php file without space there.

Activity icon

Replied to Laravel 7 Redirect Away Shows Redirect Url On White Page

Yes, I so it. It looks like your server is really slow.

Also try to set your app to production.

Which version of Laravel do you use?

Or you don't use any middleware or package? Or you have something in the js?

Or you have set something wrong in the Apache server.

Activity icon

Replied to Laravel 7 Redirect Away Shows Redirect Url On White Page

I tried this on windows 10 with browser chrome 84 and it works without showing that message.

public function index(Request $request)
{
    return redirect()->away('https://www.google.com');
}
Activity icon

Awarded Best Reply on Laravel 7 Redirect Away Shows Redirect Url On White Page

So it's probably behaviour on the mobile phone. On pc or mac your don't see that message.

Which means you can't change it with code.