xiolog

Member Since 5 Months Ago

Experience Points
10,300
Total
Experience

4,700 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
87
Lessons
Completed
Best Reply Awards
0
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 3
10,300 XP
Apr
11
5 days ago
Activity icon

Awarded Best Reply on Get The Value Of The Cookie From The Javascript And Output It To The Blade.

I have resolved this issue.

/**
 * The names of the cookies that should not be encrypted.
 *
 * @var array
 */
protected $except = [
    'saunaFavorites',
];

In the App\Http\Middleware\EncryptCookies

Activity icon

Replied to Get The Value Of The Cookie From The Javascript And Output It To The Blade.

I have resolved this issue.

/**
 * The names of the cookies that should not be encrypted.
 *
 * @var array
 */
protected $except = [
    'saunaFavorites',
];

In the App\Http\Middleware\EncryptCookies

Activity icon

Replied to Get The Value Of The Cookie From The Javascript And Output It To The Blade.

Favorites should stay with the user for a long time. We have over 700,000 daily visits to the site. We are afraid of the high load on the database.

Apr
06
1 week ago
Activity icon

Started a new Conversation Get The Value Of The Cookie From The Javascript And Output It To The Blade.

Hi all. I need your help. This is the first time I am facing this task.

When I click on an icon in a product card, I get the id of that product and store it in a cookie. That is, I save the product in Favorites.

And if this product is a customer's favorite, then I change the color of the icon for adding it to favorites.

I have javascript code in which I create a handler that saves data to cookies.

$('.like').on('click', function () {
	let saunaId = $(this).attr('data-saunaid');
let saunas = [];

    if(typeof getCookies('saunaFavorites') !== 'undefined') {
    	saunas = $.parseJSON(getCookies('saunaFavorites'));
    }

   let item = $.grep(saunas, function(item) {
   		return item.id === saunaId;
   });

   if(!item.length) {
        saunas.push({ 'id': saunaId });
    }

   setCookie('saunaFavorites', saunas);
});

Then in blade I try to get this cookie, but I get null.

@php
debug(Cookie::get('saunaFavorites'));
@endphp

What am I doing wrong and how can I get the data from the cookie?

Or maybe you can suggest an easier way to create favorite products?

Apr
03
1 week ago
Activity icon

Replied to How Can I Refactor This Code?

This is not an option. I need Cyrillic

Activity icon

Replied to How Can I Refactor This Code?

I see. Thanks a lot. :)

Activity icon

Replied to How Can I Refactor This Code?

@bugsysha, @kodyxgen Thanks a lot. I will use this solution. I changed the best answer. You are the best. I wouldn't have thought of it myself. :)

Activity icon

Replied to How Can I Refactor This Code?

@bugsysha, @kodyxgen Thanks, guys. The problem turned out to be my Cyrillic encoding :)

How is $city[0] better than Str::limit($city, 1, '')?

Activity icon

Replied to How Can I Refactor This Code?

I'm looking for the right solution :)

Activity icon

Replied to How Can I Refactor This Code?

@bugsysha, @kodyxgen This code:

$cities = City::pluck('title', 'id')->sort()->unique()
->groupBy(function (string $city): string {
	return strtolower(trim($city)[0]);
}, true);

I get:

Illuminate\Support\Collection {#1713 ▼
  #items: array:1 [▼
    b"Ð" => Illuminate\Support\Collection {#1607 ▶}
  ]
}
Activity icon

Replied to How Can I Refactor This Code?

The problem is because of this part of the code:

return strtolower($title[0]);

I use the Cyrillic alphabet. Maybe because of that.

Activity icon

Replied to How Can I Refactor This Code?

I'm implementing that right now. Your solution didn't work for me the first time. There is only 1 element of the array left.

Activity icon

Replied to How Can I Refactor This Code?

Thanks for the idea of converting the case of letters in an array. I will make a check.

Activity icon

Replied to How Can I Refactor This Code?

This is the best solution. Only the "pluck" method already creates the collection and there is no need to reuse the "collect" method.

Activity icon

Started a new Conversation How Can I Refactor This Code?

Hi all.

I have a table of cities in the database.

I need to generate an array of the following form:

[
	['A'] => [
		18 => 'Alexandria',
		24 => 'Antioch',
		1679 => 'Akron',
		1875 => 'Atlanta',
		2713 => 'Abilene',	
	],
	['B'] => [
		28 => 'Bakersfield',
		154 => 'Billings',
		1495 => 'Bridgeport',
		2150 => 'Baltimore',
		4117 => 'Bend',	
	]
]

I tried to write the code myself, but it turned out to be big. I'm sure there is a more succinct solution.

$cities = City::pluck('title', 'id');

$letters = $cities->sort()->map(function($value) {
	return Str::limit($value, 1, '');
})->unique()->flatten();

$lettersArray = [];

foreach ($letters as $letter) {
	foreach($cities as $key => $city) {
		if ($letter == Str::limit($city, 1, '')) {
			$lettersArray[$letter][$key] = $city;
		}
	}
}

How can I refactor it?

And I also need to sort the cities by name within the array. I don't understand how to do it. sort() doesn't work.

Apr
02
2 weeks ago
Activity icon

Replied to Get Items From Column With Values Separated By Commas

Snapey, thanks. I found a best solution. :)

Activity icon

Replied to Get Items From Column With Values Separated By Commas

An elementary solution, it turns out. Thank you so much :)

Activity icon

Replied to Get Items From Column With Values Separated By Commas

I started working with a PostgreSQL database recently.

Can I use this query

select * 
from folder
where '8' = ANY (string_to_array(some_column,','))

in eloquent?

Activity icon

Replied to Get Items From Column With Values Separated By Commas

No. I use PostgreSQL. This solution didn't work for me.

Activity icon

Replied to Get Items From Column With Values Separated By Commas

I get an error:

SQLSTATE[42883]: Undefined function: 7 ERROR: function find_in_set(unknown, character varying) does not exist LINE 1: select * from "banner" where FIND_IN_SET('79',city) ^ HINT: No function with given name and argument types was found. Maybe you should add an explicit type conversion. (SQL: select * from "banner" where FIND_IN_SET('79',city))

I use PostgreSQL

Activity icon

Replied to Get Items From Column With Values Separated By Commas

It's too bad I can't rate two people :)

Activity icon

Replied to Get Items From Column With Values Separated By Commas

needs to match ,7 but not ,78 and not 87

Activity icon

Replied to Get Items From Column With Values Separated By Commas

Please read my question one more time.

Activity icon

Started a new Conversation Get Items From Column With Values Separated By Commas

Hi all.

I have a table "banners" in my database. In it, the "city" column stores the id values of the cities, separated by commas. Like this:

49,54,16,78

or

all

I have two models: "City" and "Banner". How can I get all the banners that have either "city id" or "all" in the "city" field?

Mar
31
2 weeks ago
Activity icon

Replied to Retrieving Items From A Database With A Filter

Thank you very much. It worked. The more I do Laravel, the less I understand it. :)

Activity icon

Started a new Conversation Retrieving Items From A Database With A Filter

Hi all. I need a help. Again :)

I have "types" fields in my database (it lists types of saunas) that stores a string in the form of:

(there are six lines below)

Russian, With brooms
Finnish
With brooms, Finnish
With brooms
Russian
Russian, Finnish 

And I have an array that comes from the filter:

$types = [
	'Russian',
	'Finnish'
]

I need to retrieve from the database saunas, which have words from the array in the string.

For example, I need to get, according to the array, the following saunas:

Russian, With brooms
Finnish
With brooms, Finnish
Russian
Russian, Finnish

As you can see, the string "With brooms" is not included in the database output.

I tried to do it like this:

if($request->has('types')) {
	foreach ($request->input('types') as $type) {
		$saunasQuery->where('type', 'LIKE', '%' . $type . '%');
	}
}	

But I get saunas with all the words from the array in the string. And that's not what I need.

How can I make a proper query?

Mar
16
1 month ago
Activity icon

Replied to Using Where And OrWhere

The solution was easy. Thank you very much! :)

Activity icon

Started a new Conversation Using Where And OrWhere

Hi all. I have a problem.

I have a table "saunas" in a database that contains two columns: "station" and "busstation". Each of these columns can have values: empty, null or string.

Each sauna belongs to a certain city. As a result, there are 96 saunas in a particular city.

I want to write an Eloquent query in which I want to select rows in which there are non-empty fields "station" and/or "busstation".

If I just do a "where" query on the "station" field, it works fine. It outputs 54 saunas.

If I do an additional query orWhere in the field "busstation", it outputs all the saunas that are in the database. And there are more than 5000 of them.

What is my mistake?

My relation in the model City.php:

/**
* @return HasMany
*/
public function saunas(): HasMany
{
    return $this->hasMany(Sauna::class);
}
     	

My controller SaunasController.php

public function show(City $city)
{
    $stations = $city->saunas()
        ->where(function($query) {
            $query->where('station', '<>', '')->whereNotNull('station');
        })
         ->orWhere(function($query) {
            $query->where('busstation', '<>', '')->whereNotNull('busstation');
        })
        ->get(['city_id', 'title', 'station', 'busstation']);
}
Mar
02
1 month ago
Activity icon

Replied to Show Additional Information When The Mouse Is Over It

I solved it with AlpineJS :)

Activity icon

Replied to Show Additional Information When The Mouse Is Over It

Thank you, I got it. I know css. I couldn't figure out how to implement it with Tailwind. :)

Activity icon

Replied to Show Additional Information When The Mouse Is Over It

Your Russian is almost good. Good job. Thanks for this :) I understood.

Activity icon

Replied to Show Additional Information When The Mouse Is Over It

How can I change the code to make it work?

Activity icon

Replied to Show Additional Information When The Mouse Is Over It

It don`t work for me :( Do I have a mistake?

<div class="shadow-lg rounded-lg overflow-hidden relative">

    <div class="z-0">
        <div class="h-56 bg-gray-200"></div>
        <div class="py-2.5 text-purple-700 text-center">
            {{ $card->name }}
        </div>
    </div>

    <div class="bg-purple-700 absolute bottom-0 z-10 w-full h-full bg-opacity-90 p-10 justify-center items-center hidden hover:block">
        <div class="text-sm text-purple-100">{{ Str::limit($card->description, 180, '...') }}</div>
        <a href="{{ route('frontend.category', $card->id) }}" class="text-sm text-yellow-500 font-semibold mt-6 inline-block self-start">
            Перейти
        </a>
    </div>
</div>
Activity icon

Replied to Show Additional Information When The Mouse Is Over It

Hi, Snapey. I don`t understand how can I do it. Can you help me?

Are you talking about this?

<div class="bg-purple-700 absolute bottom-0 z-10 w-full h-full bg-opacity-90 p-10 justify-center items-center hidden hover:flex hover:flex-col">
    <div class="text-sm text-purple-100">{{ Str::limit($card->description, 180, '...') }}</div>
    <a href="{{ route('frontend.category', $card->id) }}" class="text-sm text-yellow-500 font-semibold mt-6 inline-block self-start">
            Перейти
    </a>
</div>
Activity icon

Replied to Show Additional Information When The Mouse Is Over It

My code:

<div class="shadow-lg rounded-lg overflow-hidden relative">

    <div>
        <div class="h-56 bg-gray-200"></div>
        <div class="py-2.5 text-purple-700 text-center">
            {{ $category->name }}
        </div>
    </div>

    <div class="bg-purple-700 absolute bottom-0 right-0 z-10 w-full h-full bg-opacity-90 p-10 flex flex-col justify-center items-center hidden">
        <div class="text-sm text-purple-100">{{ Str::limit($category->description, 180, '...') }}</div>
        <a href="#" class="text-sm text-yellow-500 font-semibold mt-6 inline-block self-start">Перейти</a>
    </div>
</div>
Activity icon

Replied to Show Additional Information When The Mouse Is Over It

Your second link is broken

Activity icon

Replied to Show Additional Information When The Mouse Is Over It

Default card

Default card

Hovered card

Default card

Mar
01
1 month ago
Activity icon

Replied to Show Additional Information When The Mouse Is Over It

I don't understand yet how to include image here

Activity icon

Started a new Conversation Show Additional Information When The Mouse Is Over It

Hello. I need a help.

I have a card. I want to show additional information when the mouse is over it. How can I do that?

Feb
11
2 months ago
Activity icon

Awarded Best Reply on Get Roles WithCount Users Trouble

Very strange.

If I use this in the Roles component:

<?php

namespace App\Http\Livewire\Backend;

use Livewire\Component;
use Spatie\Permission\Models\Role;

class Roles extends Component
{
    public function render()
    {
//        $roles = Role::with('permissions')->withCount('users')->get();
        $roles = Role::with('permissions')->get();

        return view('livewire.backend.roles', compact('roles'));
    }
}

and this in the roles.blade.php:

@foreach($roles as $role)
	<tr class="text-sm">
		<td class="py-1">{{ $role->label ?: '-' }}</td>
		<td class="py-1 text-center">{{ $role->name }}</td>
		<td class="py-1 text-center">{{ $role->permissions->pluck('name')->implode(', ') ?: 'Без ограничений' }}</td>
		<td class="whitespace-nowrap py-1 text-center">{{ $role->users->count() }}</td>
</tr>
@endforeach
                	

all works fine.

Feb
09
2 months ago
Activity icon

Replied to Get Roles WithCount Users Trouble

Very strange.

If I use this in the Roles component:

<?php

namespace App\Http\Livewire\Backend;

use Livewire\Component;
use Spatie\Permission\Models\Role;

class Roles extends Component
{
    public function render()
    {
//        $roles = Role::with('permissions')->withCount('users')->get();
        $roles = Role::with('permissions')->get();

        return view('livewire.backend.roles', compact('roles'));
    }
}

and this in the roles.blade.php:

@foreach($roles as $role)
	<tr class="text-sm">
		<td class="py-1">{{ $role->label ?: '-' }}</td>
		<td class="py-1 text-center">{{ $role->name }}</td>
		<td class="py-1 text-center">{{ $role->permissions->pluck('name')->implode(', ') ?: 'Без ограничений' }}</td>
		<td class="whitespace-nowrap py-1 text-center">{{ $role->users->count() }}</td>
</tr>
@endforeach
                	

all works fine.

Feb
08
2 months ago
Activity icon

Replied to Get Roles WithCount Users Trouble

This is a response from tinker:

Spatie\Permission\Models\Role {#4610
         id: 2,
         name: "manager",
         label: "Manager",
         guard_name: "web",
         created_at: "2021-02-08 19:10:05",
         updated_at: "2021-02-08 19:10:05",
         users_count: 1,
         permissions: Illuminate\Database\Eloquent\Collection {#4606
           all: [
             Spatie\Permission\Models\Permission {#4630
               id: 1,
               name: "manage_subscriptions",
               guard_name: "web",
               created_at: "2021-02-08 19:10:03",
               updated_at: "2021-02-08 19:10:03",
               pivot: Illuminate\Database\Eloquent\Relations\Pivot {#4620
                 role_id: 2,
                 permission_id: 1,
               },
             },
           ],
         },
       }

All works fine.

But the code in the component still does not work

Activity icon

Replied to Get Roles WithCount Users Trouble

Yes, it is. I used use Spatie\Permission\Models\Role

Activity icon

Replied to Get Roles WithCount Users Trouble

<?php

namespace App\Http\Livewire\Backend;

use Livewire\Component;
use Spatie\Permission\Models\Role;

class Roles extends Component
{
    public function render()
    {
        $roles = Role::with('permissions')->withCount('users')->get();

        return view('livewire.backend.roles', compact('roles'));
    }
}

The mistake in the

vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php:745

I understand that the error is part of the code withCount('users'), but I do not understand how to solve this error.

The Roles model doesn't seem to know anything about the Users model. But I don't think I need to write code in the vendor directory. And I don't know how to override the Roles model and specify the relationship there.

Activity icon

Started a new Conversation Get Roles WithCount Users Trouble

Hi all. I need your help.

I am using laravel_permission (https://spatie.be/docs/laravel-permission/v4) and Livewire.

In tinker I make a request:

Role::with('permissions')->withCount('users')->get()

Everything goes fine as I expect it to.

But when I transfer the same line of code to the Livewire component, I get an error:

Class name must be a valid object or a string

I can't figure out what the problem is.