MichalOravec

MichalOravec

Member Since 4 Years Ago

Prievidza, Slovakia

Experience Points
659,210
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
956
Lessons
Completed
Best Reply Awards
941
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
659,210 XP
Oct
29
12 hours ago
Activity icon

Replied to Translate Whoops! Something Went Wrong

It's from error 500.

So make a custom http error pages

https://laravel.com/docs/8.x/errors#custom-http-error-pages

And then use localization from Laravel to translate that message

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

Activity icon

Awarded Best Reply on Route Not Defined.

You have there same route more time

Route::get('books/{id}', [BooksController::class, 'destroy'])->name('books.destroy');

Problem is get here, it should be delete

https://laravel.com/docs/8.x/routing#available-router-methods

Route::delete('books/{id}', [BooksController::class, 'destroy'])->name('books.destroy');

By the way you can use resource controllers.

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

And look on this table, it shows you how it should look like

https://laravel.com/docs/8.x/controllers#actions-handled-by-resource-controller

Activity icon

Replied to Getting Array From Db

It should be

$table->json('value');

And then use casting in your model

Just an example

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'value' => 'array',
    ];
}

https://laravel.com/docs/8.x/eloquent-mutators#array-and-json-casting

Activity icon

Replied to Getting Array From Db

And what is this ['key' => 'value'] a string?! It's an array.

Activity icon

Awarded Best Reply on The Response Content Must Be A String Or Object Implementing __toString(), "object" Given.

What are you trying to get?

Data from visitors_information?

And post whole controller method.

Because the error is not from that query.

Activity icon

Replied to Route Not Defined.

You have there same route more time

Route::get('books/{id}', [BooksController::class, 'destroy'])->name('books.destroy');

Problem is get here, it should be delete

https://laravel.com/docs/8.x/routing#available-router-methods

Route::delete('books/{id}', [BooksController::class, 'destroy'])->name('books.destroy');

By the way you can use resource controllers.

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

And look on this table, it shows you how it should look like

https://laravel.com/docs/8.x/controllers#actions-handled-by-resource-controller

Activity icon

Replied to Routing Not Working As Intended

Set virtual host for your project in xampp.

Activity icon

Replied to Routing Fail After Changing View In Folder

Just profile because yu don't have user.profile route.

<a href="{{ route('profile') }}" class="dropdown-item notify-item">
Activity icon

Awarded Best Reply on Is It Possible To Trigger Child Observer When Parent Is Deleted?

Yes you can, for example

<?php

namespace App\Observers;

use App\Models\Tour ;

class TourObserver
{
    public function deleting(Tour $tour)
    {
        $tour->images->each->delete();
    }
}

Where images is relationship to TourImage model. And it calls an observer for TourImage

Activity icon

Replied to Hidden Artisan Command/option

I also checked the source code and I think it's not possible.

Activity icon

Awarded Best Reply on Create A HasOne Relations HELP

Create an account for an user during a registration.

Activity icon

Replied to Hidden Artisan Command/option

@sinnbeck Yeah exactly. It's a first hit on google.

Activity icon

Replied to Hidden Artisan Command/option

@paddy76 Do you know google? Try to use it sometimes.

Activity icon

Replied to Hidden Artisan Command/option

Add this to your own command.

protected $hidden = true;
Activity icon

Replied to Database Query Being Looped In Blade.

@foreach($survey->questions->where('category', 'Class') as $question)
    <section class="question class">
        <div class="flex justify-center text-2hxl text-gray-700 font-medium pb-6">
            <span class="text-center w-3/5">{{ $question->some_property }}</span>
        </div>
    </section>
@endforeach

But better if you filter data in the controller.

Oct
28
1 day ago
Activity icon

Awarded Best Reply on I Want To List My Subcategories In My Index With The Category Its Attached To

In the ideal world. Just one table for all categories.

Schema::create('categories', function (Blueprint $table) {
    $table->id();
    $table->foreignId('parent_id')->nullable()->constrained('categories')->onDelete('cascade');
    $table->string('name');
    $table->string('slug')->unique();
    $table->text('description')->nullable();
    $table->tinyInteger('status')->default(0);
});
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    public function children()
    {
        return $this->hasMany(Category::class, 'parent_id');
    }

    public function parent()
    {
        return $this->belongsTo(Category::class, 'parent_id');
    }
}
$categories = Category::with('children')->get();
Activity icon

Replied to I Want To List My Subcategories In My Index With The Category Its Attached To

In the ideal world. Just one table for all categories.

Schema::create('categories', function (Blueprint $table) {
    $table->id();
    $table->foreignId('parent_id')->nullable()->constrained('categories')->onDelete('cascade');
    $table->string('name');
    $table->string('slug')->unique();
    $table->text('description')->nullable();
    $table->tinyInteger('status')->default(0);
});
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    public function children()
    {
        return $this->hasMany(Category::class, 'parent_id');
    }

    public function parent()
    {
        return $this->belongsTo(Category::class, 'parent_id');
    }
}
$categories = Category::with('children')->get();
Activity icon

Replied to How Return Values From Function In Php And Laravel

Because you filter your data in the database and I don't think that you get a lot of categories after filtering with where.

Activity icon

Replied to How Return Values From Function In Php And Laravel

You don't need to use chunk at all in this case.

$categories = Category::where('category_name', 'like', $term = "%{$request->search}%")
    ->orWhere('description', 'like', $term)
    ->orWhere('keywords', 'like', $term)
    ->orWhere('content', 'like', $term)
    ->orWhere('path', 'like', $term)
    ->active()
    ->get(['id', 'category_name']);

$response = $categories->toArray();
Activity icon

Replied to Is It Possible To Trigger Child Observer When Parent Is Deleted?

@mo7sin No or...

With that you don't call the observer of child model.

Activity icon

Awarded Best Reply on $image_tmp = Input::file('image');

use Illuminate\Http\Request;

public function store(Request $request) 
{
    $image_tmp = $request->file('image');
}

https://laravel.com/docs/8.x/requests#files

Activity icon

Replied to Is It Possible To Trigger Child Observer When Parent Is Deleted?

Yes you can, for example

<?php

namespace App\Observers;

use App\Models\Tour ;

class TourObserver
{
    public function deleting(Tour $tour)
    {
        $tour->images->each->delete();
    }
}

Where images is relationship to TourImage model. And it calls an observer for TourImage

Activity icon

Replied to Create A HasOne Relations HELP

Create an account for an user during a registration.

Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'price' Cannot Be Null

I think it should be

$table->decimal('price', 15, 2)->default(0.00);
Activity icon

Replied to The Response Content Must Be A String Or Object Implementing __toString(), "object" Given.

Better to use broadcasting, but it's more complicated.

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

Cache data in the backend, otherwise, it's as if someone visited your site every 10 seconds. If you have a lot of traffic and slow server it could be a problem.

Activity icon

Replied to The Response Content Must Be A String Or Object Implementing __toString(), "object" Given.

Every 10 seconds you check the url visitors/info to get some info.

Activity icon

Replied to The Response Content Must Be A String Or Object Implementing __toString(), "object" Given.

If you want to return just id

Then

return $lastid->id;
Activity icon

Replied to The Response Content Must Be A String Or Object Implementing __toString(), "object" Given.

Use model instead of DB facade, because problem is with a response.

Or you can use

return response()->json([
    'lastid' => $lastid
]);
Activity icon

Replied to The Response Content Must Be A String Or Object Implementing __toString(), "object" Given.

@ricardo Implementation of first()

/**
 * Execute the query and get the first result.
 *
 * @param  array|string  $columns
 * @return \Illuminate\Database\Eloquent\Model|object|static|null
 */
public function first($columns = ['*'])
{
    return $this->take(1)->get($columns)->first();
}

So it's same what he had before.

Activity icon

Replied to The Response Content Must Be A String Or Object Implementing __toString(), "object" Given.

What are you trying to get?

Data from visitors_information?

And post whole controller method.

Because the error is not from that query.

Activity icon

Replied to Trying To Get Property 'max_rating' Of Non-object

@noblemfd Everytime you post unnecessary things. But not today. Try to think more what is important to show and what not...

Or better read a documentation finally.

Activity icon

Replied to Laravel Eloquent Problem

I've never use PostgreSQL, but you can find it in the documentation.

https://www.postgresql.org/docs/current/functions-formatting.html

Activity icon

Replied to Laravel Eloquent Problem

Oh ok, it's because you use PostgreSQL, just find equivalent function to MySQL in PostgreSQL.

Probably to_char instead of date_format

In my prevois code change

selectRaw("date_format(created_at, '%Y-%m') as month, count(*) as count")

to

selectRaw("to_char(created_at, 'YYYY-MM') as month, count(*) as count")
Activity icon

Replied to Laravel Eloquent Problem

$start = now()->startOfYear();

for ($i = 0; $i < 12; $i++) {
    $months[] = $start->copy()->addMonths($i)->format('Y-m');
}

$months = collect($months);

$year = User::selectRaw("date_format(created_at, '%Y-%m') as month, count(*) as count")
     ->whereYear('created_at', now()->year)
     ->groupBy('month')
     ->get()->mapWithKeys(function ($item) {
         return [$item['month'] => $item['count']];
     });

$months->map(function ($month, $key) use ($year) {
    return $year->get($month, 0);
});

// in $months you have a data.
Activity icon

Awarded Best Reply on Converting Json To Xml

Yes, you have to pass there everything what you want to have it in the xml.

@php
    echo '<?xml version="1.0" encoding="UTF-8"?>';
@endphp

<configurations>
    @foreach ($data as $configuration)
        <configuration>
           <id>{{ $configuration->json['id'] }}</id>

           <name>{{ $configuration->json['name'] }}</name>
        </configuration>
    @endforeach
</configurations>
Activity icon

Replied to Converting Json To Xml

Yes, you have to pass there everything what you want to have it in the xml.

@php
    echo '<?xml version="1.0" encoding="UTF-8"?>';
@endphp

<configurations>
    @foreach ($data as $configuration)
        <configuration>
           <id>{{ $configuration->json['id'] }}</id>

           <name>{{ $configuration->json['name'] }}</name>
        </configuration>
    @endforeach
</configurations>
Activity icon

Replied to Trying To Get Property 'max_rating' Of Non-object

In GoalType model

public function ratingLimit()
{
    return $this->belongsTo(App\Models\RatingLimit);
}

Do you know Eager Loading?

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

$goals = Goal::with('goaltype.ratingLimit')->where('is_approved', 3)->get();
{{ $goal->goaltype->ratingLimit->max_rating }}

Your naming is really bad of everything.

Activity icon

Replied to Converting Json To Xml

Uou have to also add casts to the model.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Configuration extends Model
{
    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'json' => 'array',
    ];
}

Docs: https://laravel.com/docs/8.x/eloquent-mutators#array-and-json-casting

Activity icon

Replied to Converting Json To Xml

So use your indexes from the json column, or what you have there...

Activity icon

Awarded Best Reply on Query Through Tables

You can't use Has Many Through relationship with Many to Many.

$actor = Actor::find($actorId);

$shows = Show::whereHas('showDetails.actors', function ($query) use ($actor) {
    $query->where('id', $actor->id);
})->paginate(15);

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

If I was you I would change naming

Pivot table has to be singular so instead of actor_show_details it should be actor_show_detail

And relationship in Show model is better to have just detail because it's hasOne

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Show extends Model
{
    public function detail()
    {
        return $this->hasOne('App\Models\ShowDetail');
    }
}

But in my opinion is better to have many to many relationship between Show and Actor models.

Activity icon

Replied to Converting Json To Xml

@laradoel Under json column you don't have an array, so something like this.

@php
    echo '<?xml version="1.0" encoding="UTF-8"?>';
@endphp

<configurations>
    @foreach ($data as $configuration)
        <configuration>
           <something>{{ $configuration->json['something'] }}</something>

           <another>{{ $configuration->json['another'] }}</another>
        </configuration>
    @endforeach
</configurations>
Activity icon

Replied to Undefined Variable: Users

It's not a newbie problem, you just don't read documentation.

Activity icon

Replied to Undefined Variable: Users

@henrique_f But you have it under

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

Replied to Overriding Eloquent's Create Method Not Working

How @snapey said use observer for that. Or add your logic to the FormRequest. Or make a trait where you just use a create method. That's it.