MichalOravec

MichalOravec

Member Since 4 Years Ago

Prievidza, Slovakia

Experience Points
241,260
Total
Experience

3,740 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
682
Lessons
Completed
Best Reply Awards
283
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 49
241,260 XP
May
29
16 hours ago
Activity icon

Replied to Filter Foreach Loop

I don't know what is your $this->children

But you can use filter from collection

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

$filtered = collect($this->children)->filter(function ($value, $key) {
    return $value->created_at->year == now()->year;
});
Activity icon

Replied to Filter Foreach Loop

@marlonv Change your query to this

$payd = Payment::whereYear('created_at', now()->year)->whereUserId($id)->Totalbillyear()->sum('amount_payd');

Of course if you don't have column created_at use column where you store your date.

Activity icon

Replied to Multiple Query Is Giving Empty Data

@deepu07 And what do you have in your $departments?

Activity icon

Replied to Multiple Query Is Giving Empty Data

@deepu07 Post your whole code, because it's not possible what did you say.

Activity icon

Replied to Multiple Query Is Giving Empty Data

@deepu07 If you try this you should get your data or empty collection but not null

$languageDepartment = Department::with('students')->where('type', 'language')->get();

dd($languageDepartment);
Activity icon

Replied to BarryVDH Modification

@artisticre Change it to this

public function pdfview(Request $request, $id)
{
    // your code
}
Activity icon

Replied to Storing The 'Where' Clause In A Variable

@deepu07 Why do you want to store it in variable?

Just use Local Scopes if you have something more complex.

Documentation: https://laravel.com/docs/7.x/eloquent#local-scopes

For example

public function scopeOfType($query, $type)
{
    return $query->where('type', $type);
}

Then you can use it

$departmens = Departament::ofType('computers')->get();
Activity icon

Replied to Multiple Query Is Giving Empty Data

@deepu07 Why not just like this

$musicDepartment = Department::with('students')->where('type', 'music')->get();

$artDepartment = Department::with('students')->where('type', 'art')->get();

$languageDepartment = Department::with('students')->where('type', 'language')->get();
Activity icon

Replied to Pass A Collection Of Objects Between Controllers Through The Session

@rafaelmunoznl Or just save ids to session not whole objects.

Then just use

$items = Item::latest()->whereIn('id', $idsFromSession)->get();
Activity icon

Replied to Pass A Collection Of Objects Between Controllers Through The Session

@rafaelmunoznl Why you don't want to get it from database? And just sort it and limit it.

$items = Item::latest()->limit(10)->get();
Activity icon

Replied to How To Upload File On Another Url Folder

@vinubangs

https://laravel.com/docs/7.x/filesystem#storing-files

Here look for Copying & Moving Files

It should be relative path, not absolute.

Activity icon

Replied to How To Upload File On Another Url Folder

@vinubangs Next part of documentation what you can read

https://laravel.com/docs/7.x/requests#storing-uploaded-files

Please read both of them, and I think you can figure it out.

Main point is you can't upload files to external url directly.

Activity icon

Awarded Best Reply on How Do I Define The Relationship? Is There A Relationship? Is It One-to-one? If So, What Is The Reverse Side? Help :(

@xartos92

public function location()
{ 
    return $this->belongsTo(Location::class); 
}

Documentation: https://laravel.com/docs/7.x/eloquent-relationships#one-to-one

And look there for Defining The Inverse Of The Relationship

Activity icon

Replied to Fetch Data From Remote Database And Add/update To Local Database

@thinkingman It's up to you, what will be simplier for you and it will work.

Activity icon

Replied to SQL Auto Increment Attribute

@michaloravec You can add to your migration this

DB::update("ALTER TABLE table_name AUTO_INCREMENT = 100;");

Check https://stackoverflow.com/a/34196202

Activity icon

Replied to Fetch Data From Remote Database And Add/update To Local Database

@thinkingman So this is the problem with your Undefined index

Activity icon

Replied to Json Response To Blade

@jotiduli You can use data_get

https://laravel.com/docs/7.x/helpers#method-data-get

{{ data_get($data, '2020-05-29 - 2020-05-29.86xx3.revenue') }}
Activity icon

Replied to Error Class 'Illuminate\Html\HtmlServiceProvider' Not Found

@esaeng Actually it doesn't work with the newest version of Laravel. So just don't use it, from config/app.php remove everything related to that package.

Activity icon

Replied to I'm Not Able To Store My Image Data In Db.

@muhammadmaaz

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class products_image extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['product_id', 'image'];
}
Activity icon

Replied to I'm Not Able To Store My Image Data In Db.

@muhammadmaaz Add $fillable to your models.

Documentation: https://laravel.com/docs/7.x/eloquent#mass-assignment

Also I don't know why you don't follow standard Laravel naming convention...

Activity icon

Replied to How Do I Define The Relationship? Is There A Relationship? Is It One-to-one? If So, What Is The Reverse Side? Help :(

@xartos92

public function location()
{ 
    return $this->belongsTo(Location::class); 
}

Documentation: https://laravel.com/docs/7.x/eloquent-relationships#one-to-one

And look there for Defining The Inverse Of The Relationship

Activity icon

Replied to I'm Not Able To Store My Image Data In Db.

@muhammadmaaz And show me your ProductImage file.

Activity icon

Replied to I'm Not Able To Store My Image Data In Db.

Your model App\ProductImage exists as app/ProductImage.php?

Then your relationship should be

use App\ProductImage;

public function images()
{
    return $this->hasMany(ProductImage::class);
}
Activity icon

Replied to I'm Not Able To Store My Image Data In Db.

@muhammadmaaz What do you thing this is same?

$productdetails->images()->create([
    'image' => $filename
]);

as

$productdetails->images()->create([
    'image' => $filename
}

No, so use this

$productdetails->images()->create([
    'image' => $filename
]);
Activity icon

Replied to I'm Not Able To Store My Image Data In Db.

You don't understand at all...

You don't have to do this

 $productdetails= Product::with('images')->where(['id'=>$id])->first();

To create use this code

$productdetails->images()->create([
    'image' => $filename
]);
Activity icon

Replied to I'm Not Able To Store My Image Data In Db.

@muhammadmaaz Please read that part of documentation what I posted before.

This is same as before

products_image::create([
    'image' => $filename,
    'product_id' => $data['product_id']
]);
Activity icon

Replied to How To Group Multiple Orders As A Single Entity?

@nickywan123 Try to change your logic, of your view. I think @snapey tried to explain it to you before.

Activity icon

Replied to I'm Not Able To Store My Image Data In Db.

@muhammadmaaz Do you use relationships?

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

Because your products_image model has foreing key product_id, actually I don't know why you use name for it instead of ProductImage.

So your Product model should have this relationship

public function images()
{
    return $this->hasMany(App\ProductImage::class);
}

Please set your relationships and use Laravel naming convention for models and you avoid to more problems in the future.

Activity icon

Replied to Fetch Data From Remote Database And Add/update To Local Database

@thinkingman The structure of both of your tables are same?

Activity icon

Replied to Composer Is Not Working?

@laxman Please choose the best answer.

Activity icon

Replied to How To Use Parent Menu Join

@mkarakaya It's self join so

$category = DB::table('category')->select('category_description.name', 'parent_category_description.name as parent_name')
    ->join('category AS parent_category', 'parent_category.category_id', '=', 'category.parent_id')
    ->innerJoin('category_description', 'category_description.category_id', '=', 'category.category_id')
    ->innerJoin('category_description as parent_category_description', 'parent_category_description.category_id', '=', 'parent_category.category_id')
    ->get();
 
 return DataTables::of($category)->make(true);

Also add other fields what do you need inside select()

Activity icon

Replied to I'm Not Able To Store My Image Data In Db.

@muhammadmaaz Change your code to something like this

if ($request->hasFile('image')) {
    foreach($request->file('image') as $image) {
        $filename = Str::random(14).'.'.$image->getClientOriginalExtension();

        $largeImage = Image::make($image)->encode();

        Storage::disk('public')->put("images/backend_images/products/large/{$filename}", (string) $largeImage);

        $mediumImage = Image::make($image)->resize(600, 600)->encode();

        Storage::disk('public')->put("images/backend_images/products/medium/{$filename}", (string) $mediumImage);

        $smallImage = Image::make($image)->resize(300, 300)->encode();

        Storage::disk('public')->put("images/backend_images/products/small/{$filename}", (string) $smallImage);

        $productdetails->images()->create([
            'image' => $filename
        ]);
    }
}

$productdetails->images() just chnge to your relationship name.

Activity icon

Replied to How To Group Multiple Orders As A Single Entity?

@nickywan123 It's impossible what do you want. change your logic that you will have 5 orders in one table, and show all items for each order.

Activity icon

Awarded Best Reply on Setting Up SQLite

This is default

'sqlite' => [
    'driver' => 'sqlite',
    'url' => env('DATABASE_URL'),
    'database' => env('DB_DATABASE', database_path('database.sqlite')),
    'prefix' => '',
    'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],

So you just remove DB_DATABASE from your .env file

Activity icon

Replied to Setting Up SQLite

This is default

'sqlite' => [
    'driver' => 'sqlite',
    'url' => env('DATABASE_URL'),
    'database' => env('DB_DATABASE', database_path('database.sqlite')),
    'prefix' => '',
    'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],

So you just remove DB_DATABASE from your .env file

Activity icon

Replied to I'm Not Able To Store My Image Data In Db.

@muhammadmaaz

Check http://image.intervention.io/getting_started/formats

For WebP support GD driver must be used with PHP 5 >= 5.5.0 or PHP 7 in order to use imagewebp(). If Imagick is used, it must be compiled with libwebp for WebP support.

Activity icon

Replied to How To Prevent Page-break In The Last Table?

@nickywan123

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

And it's just math.

First step (parent index start with 0 and iteration start with 1)

1 + (0 * 5) = 1

2 + (0 * 5) = 2

3 + (0 * 5) = 3

4 + (0 * 5) = 4

5 + (0 * 5) = 5

Second step (parent index is now 1 and iteration start again with 1)

1 + (1 * 5) = 6

2 + (1 * 5) = 7

3 + (1 * 5) = 8

4 + (1 * 5) = 9

5 + (1 * 5) = 10

And so on.

Activity icon

Replied to How To Prevent Page-break In The Last Table?

@nickywan123 Remove your whole code with $iterationNo

And put there this

{{ $loop->iteration + ($loop->parent->index * 5) }}
Activity icon

Awarded Best Reply on How To Prevent Page-break In The Last Table?

@nickywan123 Try it like this

@if (! $loop->last)
    <div style="page-break-before:always;">
@endif
Activity icon

Replied to How To Prevent Page-break In The Last Table?

It means that you have that <div> eveytime in loop but not for last time.

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

Activity icon

Replied to How To Prevent Page-break In The Last Table?

@nickywan123 Try it like this

@if (! $loop->last)
    <div style="page-break-before:always;">
@endif
Activity icon

Replied to I'm Not Able To Store My Image Data In Db.

@muhammadmaaz Add name="image[]" to your input like

<input type="file" name="image[]" id="image" multiple="multiple">
May
28
1 day ago
Activity icon

Awarded Best Reply on SESSION_SECURE_COOKIE For?

@jonjie Nowadays is good to run all your website with HTTPS on production. In that case is good to set it to true.

When you develop your website on localhost it's better to have set in .env file as

SESSION_SECURE_COOKIE=false

Because on localhost you don't use HTTPS

Activity icon

Awarded Best Reply on Laravel Mix Version() Issue

@giacholari Real files will note have a hash after .js or .css. Check source code of your website and you will see those hashes on those files.

In your webpack.mix.js file put

if (mix.inProduction()) {
    mix.version();
}

And in your layouts (this is just for example)

<script src="{{ mix('js/app.js') }}"></script>

And that's it, everytime your visitor of your page will see up to date your styles or javascript code.

Maybe more info find here: https://laravel-mix.com/docs/5.0/versioning

Activity icon

Replied to Artisan Make:controller With Parent Option Not Working (Laravel 7.0)

@slamm Could you mark this thread as solved? Thanks.