MichalOravec

MichalOravec

Member Since 4 Years Ago

Prievidza, Slovakia

Experience Points
490,320
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
674
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
490,320 XP
Aug
05
22 hours ago
Activity icon

Awarded Best Reply on Correct Way To Save/sync Relationships

You have pivot table so your relationship should follow this https://laravel.com/docs/7.x/eloquent-relationships#many-to-many

public function update(Request $request, Venue $venue)
{
    $venue->update($request->only('name'));

    $venue->services()-sync($request->service);

    // redirect somewhere with a message
}

Docs: https://laravel.com/docs/7.x/eloquent-relationships#updating-many-to-many-relationships (look for Syncing Associations)

But don't forget that you have to have set correct relationships.

Also you can use model binding https://laravel.com/docs/7.x/routing#route-model-binding

Don't forget to validation https://laravel.com/docs/7.x/validation#form-request-validation

Activity icon

Replied to Correct Way To Save/sync Relationships

@extjac First read those parts of documentation what I posted before.

Don't forget that you have many to many relationship.

Activity icon

Replied to Correct Way To Save/sync Relationships

You have pivot table so your relationship should follow this https://laravel.com/docs/7.x/eloquent-relationships#many-to-many

public function update(Request $request, Venue $venue)
{
    $venue->update($request->only('name'));

    $venue->services()-sync($request->service);

    // redirect somewhere with a message
}

Docs: https://laravel.com/docs/7.x/eloquent-relationships#updating-many-to-many-relationships (look for Syncing Associations)

But don't forget that you have to have set correct relationships.

Also you can use model binding https://laravel.com/docs/7.x/routing#route-model-binding

Don't forget to validation https://laravel.com/docs/7.x/validation#form-request-validation

Activity icon

Replied to Update Function Is Not Working Token Is Generated

Routes but you can probably use resource.

Route::prefix('admin')->name('admin.')->group(function () {
    Route::get('users', '[email protected]')->name('users.index');

    Route::put('users/{user}', '[email protected]')->name('users.update');

    Route::delete('users/{user}', '[email protected]')->name('users.destroy');
});

In controller

public function update(Request $request, User $user)
{
    $user->update($request->all());

    return redirect()->route('admin.users.index')->with('sucess', 'Data Updated');
}

In view

@foreach($users as $user)
    <form action="{{ route('admin.users.update', ['user' => $user]) }}" method="POST">
        @csrf

        @method('PUT')

        <div class="form-group">
            <label for="name-{{ $user->id }}">User Name</label>

            <input id="name-{{ $user->id }}" type="text" class="form-control" name="name" value="{{ $user->name }}">
        </div>

        <div class="form-group">
            <label for="email-{{ $user->id }}">Email</label>

            <input id="email-{{ $user->id }}" type="email" class="form-control" name="email" value="{{ $user->email }}">
        </div>

        <button type="submit" class="btn btn-primary">Update</button>
    </form>
@endforeach

Check this documentation about route groups: https://laravel.com/docs/7.x/routing#route-groups

Activity icon

Awarded Best Reply on SortByDesc

$threads = Thread::when(request()->query('popularity'), function ($query) {
    return $query->orderByDesc('replies_count');
})->get();

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

Activity icon

Awarded Best Reply on Update Function Is Not Working Laravel 6 I Am Using Resource Controller

Why your model is Categories and not in the singular form like Category?

Why do you allow to update id?!

In routes

Route::resource('categories', 'CategoriesController');

In controller

public function update(Request $request, Category $category)
{
    // validation without id

    $category->update($request->all());

    return redirect()->route('categories.index');
}

In view

<form action="{{ route('categories.update', ['category' => $category]) }}" method="POST">
     @csrf

     @method('PUT')

    <!-- inputs without id -->
</form>

Read this part of documentation: https://laravel.com/docs/7.x/controllers#resource-controllers

Activity icon

Replied to SortByDesc

$threads = Thread::when(request()->query('popularity'), function ($query) {
    return $query->orderByDesc('replies_count');
})->get();

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

Activity icon

Replied to Update Function Is Not Working Laravel 6 I Am Using Resource Controller

You have to think, when somebody give you an advice.

<form action="{{ route('categories.update', ['category' => $category]) }}" method="POST">
    @csrf

    @method('PUT')

    <div class="form-group">
        <label for="name">Name</label>

        <input type="text" class="form-control" value="{{ $category->name }}" name="name">
    </div>

    <div class="form-group">
        <label for="status">Status</label>

        <input type="text" class="form-control" value="{{ $category->status }}"  name="status">
    </div>

    <button type="submit" class="btn btn-primary">Update</button>
</form>

This was just where you should paste your inputs...

<!-- inputs without id -->
Activity icon

Replied to Update Function Is Not Working Laravel 6 I Am Using Resource Controller

Where is the form? Why is there still input where you change id?

Put your code correctly.

On the top and bottom put ```

Activity icon

Replied to Update Function Is Not Working Laravel 6 I Am Using Resource Controller

Without your actual code we can't know what are you doing wrong.

Activity icon

Replied to Relationships Between Eloquent Models In Different Folders

Yes there is, you have to set foreign_key in hasMany and belongsTo

Docs: Check documentation https://laravel.com/docs/7.x/eloquent-relationships#one-to-many and https://laravel.com/docs/7.x/eloquent-relationships#one-to-many-inverse

If you have something like ProductDefaultDescriptionPropertyValue then it's something wrong with your design of database.

Activity icon

Replied to Relationships Between Eloquent Models In Different Folders

Change App\Product\Category to App\ProductCategory in app folder and it solve your problem.

And if you have problem that you have a lot models in the app directory you can move them for example to the app/Models folder

Activity icon

Replied to Update Function Is Not Working Laravel 6 I Am Using Resource Controller

@redroseamit If you change your code to what I recommended to you it will work.

Activity icon

Awarded Best Reply on About Route In Contact Form

Second has to be post

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

Replied to About Route In Contact Form

Second has to be post

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

Replied to Update Function Is Not Working Laravel 6 I Am Using Resource Controller

Why your model is Categories and not in the singular form like Category?

Why do you allow to update id?!

In routes

Route::resource('categories', 'CategoriesController');

In controller

public function update(Request $request, Category $category)
{
    // validation without id

    $category->update($request->all());

    return redirect()->route('categories.index');
}

In view

<form action="{{ route('categories.update', ['category' => $category]) }}" method="POST">
     @csrf

     @method('PUT')

    <!-- inputs without id -->
</form>

Read this part of documentation: https://laravel.com/docs/7.x/controllers#resource-controllers

Activity icon

Replied to How To Return All Content From Three Variables In One Function In Laravel?

@automica What is this?

Article::all()->get();

@bbmrw Please don't use it.

Activity icon

Replied to How To Return All Content From Three Variables In One Function In Laravel?

@bbmrw If your route is

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

So why you don't have it in the index method

public function index()
{
    $articles = Article::all();
 
    $users = User::all();
 
    $matches = Match::all();

    return view('dashboard.index', compact('articles', 'users', 'matches'));
}

Or if you want to have that getAll() method then

protected function getAll()
{
    return [
	Article::all(),
        User::all(),
        Match::all()
    ];
}

public function index()
{
    [$articles, $users, $matches] = $this->getAll();

    return view('dashboard.index', compact('articles', 'users', 'matches'));
}
Activity icon

Replied to Switching To Https Does Not Change Internal Urls

To your AppServiceProvider into the boot method add

if (App::environment('production')) {
    URL::forceScheme('https');
}

Also don't forget add to the top

use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\URL;
Activity icon

Replied to Update Return False

@timtom You want to help somehow, but you don't post any code snippet. And also what does it mean update request?

If you are trying to update data which don't exist in the database you everytime get false.

Aug
04
1 day ago
Activity icon

Awarded Best Reply on Adding A Column To Existing Database And Using Laravel To Fill In Field

Of course you can use query builder to update your data in database. It's up to you.

But this "if the current date is older than todays date it will set the status to 'p'" so it means that all organizers in your current database should have set status to p?

Then just update status to p in all rows of organizers.

Activity icon

Replied to Adding A Column To Existing Database And Using Laravel To Fill In Field

Of course you can use query builder to update your data in database. It's up to you.

But this "if the current date is older than todays date it will set the status to 'p'" so it means that all organizers in your current database should have set status to p?

Then just update status to p in all rows of organizers.

Activity icon

Replied to Adding A Column To Existing Database And Using Laravel To Fill In Field

What is your whole structure for organizers?

You can after migration just run sql update and change status to those organizers.

Activity icon

Replied to How To Link Checkbox Arrays

Use only one checkbox for that.

<input type="checkbox" name="required[{{ $skill->id }}]" value="1">
Activity icon

Replied to How To Display Unknown On The View Blade For Date_of_birth

By the way why did you make another thread for it?

https://laracasts.com/discuss/channels/laravel/2020-08-02-202738-productionerror-a-two-digit-day-could-not-be-found

@noblemfd And you have there almost same code what @sergiu17 gave you right now.

This

public function getDateOfBirthAttribute($input)
{
   return is_null($input) ? "None" : Carbon::parse($input)->format(config('app.date_format'));   
}

and this

public function getDateOfBirthAttribute($input)
{
   return $input ? Carbon::parse($input)->format(config('app.date_format')) : 'Unknown';
}

is same...

Activity icon

Replied to How To Display Unknown On The View Blade For Date_of_birth

Don't use getDateOfBirthAttribute instead of you can use

public function getFormattedDateOfBirthAttribute()
{
     $this->date_of_birth->format(config('app.date_format'));   
}

Then in the view

@if ($employee->date_of_birth)
    {{ $employee->formatted_date_of_birth }}
else
    Unknown
@endif

Of course don't forget set $dates in your model.

/**
 * The attributes that should be mutated to dates.
 *
 * @var array
 */
protected $dates = [
    'date_of_birth'
];
Activity icon

Awarded Best Reply on Store Eloquent Master Detail On Same Page

When you have relationship hasMany name it as details and not detail

class OrderController extends Controller
{
    public function store(Request $request)
    {
        $order = Order::create([
            'name' => $request->name
        ]);

        foreach ($request->items as $key => $item) {
            $order->details()->create([
                'item' => $item,
                'total' => $request->totals[$key]
            ]);
        }

        return redirect("order/{$order->id}")->with('message', 'Order created Successfully');
    }
}

Also if you have an array of items name it items[] and not item[]

Activity icon

Replied to Laravel: Give LongText Field A Default Value

In your migration with default like

$table->text('body')->default('Something default');
Activity icon

Replied to Syntax Error, Unexpected 'email' (T_STRING), Expecting ')'

Instead of that you can use

<div class="input-group no-border form-control-lg {{ $errors->first('email', 'has-danger') }}">

By the way your code seems to be ok, probably the error comes from different place.

Aug
03
2 days ago
Activity icon

Replied to Store Eloquent Master Detail On Same Page

When you have relationship hasMany name it as details and not detail

class OrderController extends Controller
{
    public function store(Request $request)
    {
        $order = Order::create([
            'name' => $request->name
        ]);

        foreach ($request->items as $key => $item) {
            $order->details()->create([
                'item' => $item,
                'total' => $request->totals[$key]
            ]);
        }

        return redirect("order/{$order->id}")->with('message', 'Order created Successfully');
    }
}

Also if you have an array of items name it items[] and not item[]

Activity icon

Awarded Best Reply on Eloquent : Scope WhereIn Matches All (relation)

public function scopeAvailableBetween(Builder $query, $dates): Builder
{
    $period = CarbonPeriod::create($dates[0], $dates[1]);

    $dates = collect($period->toArray())->map->format('Y-m-d')->toArray();

    return $query->with('roomAvailabilties')->whereHas('roomAvailabilties', function($query) use ($dates) {
        $query->distinct()->whereIn('date', $dates);
    }, '=', count($dates));
}

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

Activity icon

Awarded Best Reply on How To Merge All Models In Laravel

@oxbir I think it's not to hard when you read documentation.

$advertises = DB::table('advertises')->select('image')->whereNotNull('image');

$designStudios = DB::table('design_studios')->select('image')->whereNotNull('image');

$houses = DB::table('houses')->select('image')->whereNotNull('image');

$photographers = DB::table('photographers')->select('image')->whereNotNull('image');

$slideShows = DB::table('websites')->select('image')
            ->whereNotNull('image')
            ->union($advertises)
            ->union($designStudios)
            ->union($houses)
            ->union($photographers)
            ->get();
Activity icon

Replied to Eloquent : Scope WhereIn Matches All (relation)

public function scopeAvailableBetween(Builder $query, $dates): Builder
{
    $period = CarbonPeriod::create($dates[0], $dates[1]);

    $dates = collect($period->toArray())->map->format('Y-m-d')->toArray();

    return $query->with('roomAvailabilties')->whereHas('roomAvailabilties', function($query) use ($dates) {
        $query->distinct()->whereIn('date', $dates);
    }, '=', count($dates));
}

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

Activity icon

Replied to Adding Sharable Link For Facebook Throws Error?

@astro_369

config/shareable.php

<?php

return [
  
    'facebook' => [
        'app_id' => env('FACEBOOK_APP_ID')
    ]

];

Then in the code use it as config('shareable.facebook.app_id');

Activity icon

Replied to How To Merge All Models In Laravel

@oxbir I think it's not to hard when you read documentation.

$advertises = DB::table('advertises')->select('image')->whereNotNull('image');

$designStudios = DB::table('design_studios')->select('image')->whereNotNull('image');

$houses = DB::table('houses')->select('image')->whereNotNull('image');

$photographers = DB::table('photographers')->select('image')->whereNotNull('image');

$slideShows = DB::table('websites')->select('image')
            ->whereNotNull('image')
            ->union($advertises)
            ->union($designStudios)
            ->union($houses)
            ->union($photographers)
            ->get();
Activity icon

Awarded Best Reply on How To Store Image Without Path Laravel

Why do you want to save it in the root? It's better to save it at least to the posts folder.

$post = new Post();
$post->image = $request->file('image')->store('posts');
$post->save();

If you want to save it without path then this should work

$post->image = $request->file('image')->store('');
Activity icon

Replied to How To Store Image Without Path Laravel

Why do you want to save it in the root? It's better to save it at least to the posts folder.

$post = new Post();
$post->image = $request->file('image')->store('posts');
$post->save();

If you want to save it without path then this should work

$post->image = $request->file('image')->store('');
Activity icon

Replied to How To Store Image Without Path Laravel

Use asset helper

<img  class="lazy loaded" src="{{ asset("storage/{$post->image}") }}">

Docs: https://laravel.com/docs/7.x/helpers#method-asset

Activity icon

Replied to Where My DefaultLocale Comes From

With app()->getLocale() you get sk in this case.

Activity icon

Awarded Best Reply on Image Multiple Upload - Same Photos

time() return time in seconds so your foreach run during one second, this is the reason why you get same name.

$filename = 'img-'.Str::random(14).'.'.$photo->getClientOriginalExtension();
Activity icon

Awarded Best Reply on Maintenance Mode Banner ?

You can check it with

@if (app()->isDownForMaintenance())
    // your banner or whatever put here in the view
@endif
Activity icon

Replied to Maintenance Mode Banner ?

You can check it with

@if (app()->isDownForMaintenance())
    // your banner or whatever put here in the view
@endif
Activity icon

Replied to How To Search Result In Data Appended In Model ?

@princeoo7 env() helper use only in the config files. Here you can find the reason for that.

I don't know if your category_translations table use language_id or just locale, so just change this code little bit and it should work for you.

$currentLanguageId = 1;

$categories = Category::with(['translations' => function ($query) use ($currentLanguageId) {
    $query->where('language_id', $currentLanguageId);
}])->when($request->s, function ($query, $term) {
    return $query->whereHas('translations', function ($query) use ($term, $currentLanguageId) {
        $query->where('title', 'LIKE', "%{$term}%")->where('language_id', $currentLanguageId);
    });
})->paginate(config('app.rec_limit'));
Activity icon

Replied to How To Search Result In Data Appended In Model ?

@silencebringer env outside of config files? Are you sure?

Activity icon

Replied to Where My DefaultLocale Comes From

In config/app.php

/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/

'locale' => 'en',

/*
|--------------------------------------------------------------------------
| Application Fallback Locale
|--------------------------------------------------------------------------
|
| The fallback locale determines the locale to use when the current one
| is not available. You may change the value to correspond to any of
| the language folders that are provided through your application.
|
*/

'fallback_locale' => 'en',
Activity icon

Replied to Facing Issue When Customizing The Laravel Auth | Created The Custom Laravel Login Controller

@hadayat So what I posted before would be work. I said there what you have to change from original LoginController.

Activity icon

Replied to Image Multiple Upload - Same Photos

time() return time in seconds so your foreach run during one second, this is the reason why you get same name.

$filename = 'img-'.Str::random(14).'.'.$photo->getClientOriginalExtension();