AlexanderKim

AlexanderKim

Almaty

Hire Me

Member Since 4 Years Ago

Experience Points 13,825
Experience
Level
Lessons Completed 52
Lessons
Completed
Best Reply Awards 2
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

21 Oct
3 weeks ago

AlexanderKim started a new conversation Setup Sublime Text 3 + Xdebug + Valet

I've installed Xdebug extension using PECL:

peel install xdebug

Restarted valet, installed Xdebug client in sublime text 3, but now I cannot find xdebug.ini, googling didn't help, because all of the articles are mostly outdated. Is there any step by step guide?

07 Aug
3 months ago

AlexanderKim left a reply on How To Setup Nginx With Dnsmasq To Make It Work Like Valet On MacOS?

Is there nginx config also? So i won't create individual vhosts for each local domain.

06 Aug
3 months ago

AlexanderKim left a reply on How To Setup Nginx With Dnsmasq To Make It Work Like Valet On MacOS?

I also confused in Ubuntu 18.04, it does have built-in dnsmasq and standalone dnsmasq?

AlexanderKim started a new conversation How To Setup Nginx With Dnsmasq To Make It Work Like Valet On MacOS?

Migrated to Ubuntu now and experiencing issues setting up dnsmasq, so it would work just like with laravel Valet, any guides?

16 Jul
3 months ago

AlexanderKim left a reply on Tinker Won't Detect Migration Class

How many steps back i can go? 10, 15?

AlexanderKim left a reply on Tinker Won't Detect Migration Class

I just wanted to rollback certain migrations this way, now i think there's no other way than editing batch number directly in database.

AlexanderKim left a reply on Tinker Won't Detect Migration Class

So, no way to get it's class in tinker?

AlexanderKim left a reply on Laravel + Vue.js The Page Has Expired Due To Inactivity. Please Refresh And Try Again.

Yes, it's because of missing CSRF.

Here's example:

var csrf_token = $('meta[name="csrf-token"]').attr('content');
    /*Event handling within vue*/
    //when we actually submit the form, we want to catch the action
    new Vue({
        el      : '#timeline',
        data    :   {
            post    : '',
            token   : csrf_token,
        },
        methods : {
            postStatus : function (e) {
                e.preventDefault();
                console.log('Posted: '+this.post+ '. Token: '+this.token);
                $.ajax({
                    url         :   '/posts',
                    type        :   'post',
                    dataType    :   'json',
                    data        :   {
                        'body'  :   this.post,
                        '_token':   this.token,
                    }
                });
            }
        },
    });

AlexanderKim started a new conversation Tinker Won't Detect Migration Class

For example, if i have a migration class:

class CreateServicesTable extends Migration { ... }

Then i try in tinker:

new CreateServicesTable;
PHP Fatal error:  Class 'CreateServicesTable' not found in Psy Shell code on line 1

Is there a way to access migration's class using tinker? I want to access up & down methods.

14 Jul
4 months ago

AlexanderKim left a reply on How To Use Faker In Seeder?

@giovanniciriello

No errors, i've checked before with single -v, with -vvv same result, i just get success message: Seeding: UsersTableSeeder

AlexanderKim started a new conversation How To Use Faker In Seeder?

Here's my seeder:

    public function run()
    {
        // create administrator
        User::create([
            'user_name' => 'Administrator',
            'user_email' => '[email protected]',
            'user_address' => '123123 34',
            'user_phone' => '+123123213',
            'password' => bcrypt('test')
        ]);

        // generating users for testing purposes with faker
        factory(App\User::class, 10)->make();
    }

UserFactory.php:

$factory->define(App\User::class, function (Faker $faker) {
    return [
        'user_name' => $faker->name,
        'user_email' => $faker->unique()->safeEmail,
        'user_address' => $faker->sentence(5),
        'user_phone' => '123',
        'password' => 'y$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
        'remember_token' => str_random(10),
    ];
});

When i run php artisan db:seed, it seeds just my manually created user "Administrator", but factory doesn't run.

Also where i can check all $faker properties? Like name/email/sentence, couldn't find anything in documentation.

13 Jul
4 months ago

AlexanderKim left a reply on Set Cookie On Ajax Post Request

Ok, but how can i use this function inside:

                    success: function(data) {
                        console.log(getCookie('project'));
                    },

returns null, because it's in success scope i guess.

AlexanderKim left a reply on Set Cookie On Ajax Post Request

in Ajax success section you mean? Could you throw an example?

AlexanderKim started a new conversation Set Cookie On Ajax Post Request

Doing some vote up/down functionality with Ajax.

JS:

    <script type="text/javascript">
        $(document).ready(function () {
            $('.thumb-down, .thumb-up').click(function (e) {
                e.preventDefault();
                if ($(this).attr('class') == 'thumb-up') {
                    var voteValue = 1;
                } else {
                    var voteValue = 0;
                }

                var projectID = $('#project-id').text();
                
                // console.log(projectID);

                $.ajax({
                    method: 'post',
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                    url: '/vote',
                    data: {
                        vote: voteValue,
                        id: projectID
                    },
                    success: function(data) {
                        $('.thumb-count').html(data.total_count);
                        console.log(data);
                    },
                    error: function(jqxhr, status, exception) {
                        console.log('Error ' + exception);
                    }
                });
            });
        });
    </script>

Controller:

    /**
     * Vote post method
     */
    public function vote(Request $request)
    {
        $vote = new Vote;

        $vote->project_id = $request->input('id');
        $vote->vote = $request->input('vote');
        $cookie = cookie()->forever('navien-project-' . $request->input('id'), $request->input('vote'));
        $vote->cookie = $cookie;
        
        $vote->save();

        $votes_up = Vote::where('project_id', $request->input('id'))->where('vote', '=', 1)->count();
        $votes_down = Vote::where('project_id', $request->input('id'))->where('vote', '=', 0)->count();

        if ($votes_up > $votes_down) {
            $total_count = $votes_up - $votes_down;
        } else if ($votes_down > $votes_up) {
            $total_count = $votes_up - $votes_down;
        } else {
            $total_count = 0;
        }

        return response()->json(compact('total_count'))->cookie($cookie);
    }

When user clicks vote up or down, it sends ajax post request to this controller's method, in this controller i'm setting up cookie and sending it back with response(), but how can i then check if this cookie exists on client's browser, so it won't allow to vote him again?

10 Jul
4 months ago

AlexanderKim left a reply on Ajax Pagination Not Working

Standart laravel pagination, here's jquery from the tutorial:

            $('body').on('click', '.pagination a', function(e) {
                e.preventDefault();

                var url = $(this).attr('href');
                getArticles(url);
                window.history.pushState("", "", url);
            });

            function getArticles(url) {
                $.ajax({
                    url : url
                }).done(function (data) {
                    $('#products').html(data);
                }).fail(function () {
                    alert('Articles could not be loaded.');
                });
            }

When i click on pagination item, normal page reload happens and shows that error

AlexanderKim started a new conversation Ajax Pagination Not Working

Tried to follow this tutorial: https://laraget.com/blog/how-to-create-an-ajax-pagination-using-laravel

But had no success. When i click on a pagination link, i get the following error:

[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
08 Jul
4 months ago

AlexanderKim left a reply on Using || Operator In PHP

@CodebyRay

I've tried using && in my case, but it was returning unexpected results either.

AlexanderKim left a reply on Using || Operator In PHP

@Snapey

Yes, but in my case url()->previous() is not true when i'm on different page, like: domain.test/admin/pages. It only works if i make it in separate IF.

AlexanderKim started a new conversation Using || Operator In PHP

@if (url()->previous() != Request::root() . '/admin/news' || url()->previous() != Request::root() . '/admin/pages')
true
@endif

In this case only the first statement before OR is working, but second is always ignored. I'm using it incorrectly?

07 Jul
4 months ago

AlexanderKim left a reply on Chrome Or Safari On Mac?

Firefox is even more power hungry than Chrome, so i guess, you're all using desktops. So i'm deciding about Chrome vs Safari

06 Jul
4 months ago

AlexanderKim started a new conversation Chrome Or Safari On Mac?

What do you, guys, use on a Mac? Chrome seems like battery hungry if compare to Safari, but Safari is not so extendable like Chrome, etc. Opinions?

03 Jul
4 months ago

AlexanderKim left a reply on Filtering Data With Selected Order And Returning Data With Pagination

@Sergiu17

Thanks, but that filter part is a last thing to do on my project to finish it, i went jquery way, i will dive to Vue on the next project for sure.

I figured out on how to output pagination, but when i click on pagination item, it returns the following link: products/prices-sort?page=2 instead of products?page=2, that's because i' POSTing data to products/price-sort url i guess. Do i need to make GET route in order to make it work? What's the correct way?

02 Jul
4 months ago

AlexanderKim started a new conversation Filtering Data With Selected Order And Returning Data With Pagination

Blade:

                        <select id="price_sort" class="custom-select" name="price_sort">
                            <option value="default" selected>By price</option>
                            <option value="asc">Ascending</option>
                            <option value="desc">Descending</option>
                        </select>

ajax request:

        $(document).ready(function () {
            $('#price_sort').change(function () {
                var price_sort = $(this).val();

                $.ajax({
                    method: 'post',
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                    url: '/products/price-sort',
                    data: {
                        order: price_sort
                    },
                    success: function(products) {
                        // process your data
                        console.log(products);
                    },
                    error: function(jqxhr, status, exception) {
                        alert('Error ' + exception);
                    }
                });
            });
        });

Controller:

    // price sort select
    public function priceSort(Request $request)
    {   
        if ($request->input('order') == 'desc') {
            $products = Product::orderBy('price', 'desc')->get();
        } else if ($request->input('order') == 'asc') {
            $products = Product::orderBy('price', 'asc')->get();
        }

        if (!empty($products)) {
            return $products;
        }        
        
    }

It's working, it does return products in a console log. But the question is, how do i display it as a view with pagination? Currently i am display 12 products per page, but when i trigger price filtering it should replace current products with a new ones with different ordering by price.

01 Jul
4 months ago

AlexanderKim left a reply on Vote Up & Down Packages

Well, if just increasing/decreasing by clicking - yes, but how to avoid abusing? by ip or somehow.

AlexanderKim left a reply on How To Make Select Filters?

@Cronix

But how do i update my product list with pagination?

AlexanderKim started a new conversation Vote Up & Down Packages

Is there any packages that would let me do this thing: https://yadi.sk/i/ZqqaPITN3Ye2Bc

AlexanderKim left a reply on How To Pass Request Data To Job, Then To Mailable Class

@bobbybouwmann

Thanks! I also noticed, that i can use empty dispatch(), what for is an argument inside dispatch?

AlexanderKim started a new conversation How To Pass Request Data To Job, Then To Mailable Class

Mailable class:

class CallBack extends Mailable
{
    use Queueable, SerializesModels;

    public $name;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($name)
    {
        $this->name = $name;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.callback');
    }
}

Job class:

class CallBack implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $name;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($name)
    {
        $this->name = $name;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $settings = Settings::find(1);
        Mail::to($settings->site_email)->send(new CallBackMail($name));
    }
}

Controller:

CallBack::dispatch($request->input('name'));

Then i get the error about undefined variable $name, simple things is complicated with jobs, wtf.

29 Jun
4 months ago

AlexanderKim left a reply on How To Make Select Filters?

What if i use selects without form?

AlexanderKim left a reply on How To Make Select Filters?

Thanks, will try it. Does $.post works without ajax?

AlexanderKim started a new conversation How To Make Select Filters?

For example, i have a view with all products, and i set up 2 select lists to filter these products without submit button, is there any examples on how to achieve that?

27 Jun
4 months ago

AlexanderKim left a reply on Valet Share - Chrome Complains About Deceptive Site

Put the PC to sleep, then it magically worked.

AlexanderKim left a reply on Valet Share - Chrome Complains About Deceptive Site

It's laravel mix probably screwing up my css?

AlexanderKim left a reply on Valet Share - Chrome Complains About Deceptive Site

lol, is that laravel bug? it complains about css

AlexanderKim started a new conversation Valet Share - Chrome Complains About Deceptive Site

When i do valet share on my local website (it was never been on any hosting, i'm just developing it), i keep getting warning about deceptive site in chrome. Anyone faced that issue?

25 Jun
4 months ago

AlexanderKim left a reply on Setting Custom Date Results An Error

I just want to set default date format for model

AlexanderKim left a reply on Assign Variable Class To <body> With Blade?

I want to extend @bastiaan89 's answer:

<body class="{{ !empty($body_class) ? $body_class : '' }}">

Otherwise it would throw an error about empty var.

24 Jun
4 months ago

AlexanderKim started a new conversation Setting Custom Date Results An Error

From L5.6 documentation, i can change default date format in a model:

class Flight extends Model
{
    /**
     * The storage format of the model's date columns.
     *
     * @var string
     */
    protected $dateFormat = 'd.m.Y';
}

However, when i do this, i'm getting this error:

The separation symbol could not be found Unexpected data found. Trailing data

Do i need to update my schema? I am using currently:

$table->timestamps();

23 Jun
4 months ago

AlexanderKim left a reply on Database Design

Ended up doing this way:

        @foreach($option_types as $type)
            <div class="form-group">
                <label for="source">{{ $type->label }}</label>
                <select class="form-control" id="{{ $type->name }}" name="{{ $type->name }}">
                    @foreach($type->options as $option)
                        @switch($option->name)
                            @case($product->source)
                                <option value="{{ $option->name }}" selected>{{ $option->name }}</option>
                                @break
                            @case($product->installation)
                                <option value="{{ $option->name }}" selected>{{ $option->name }}</option>
                                @break
                            @case($product->type)
                                <option value="{{ $option->name }}" selected>{{ $option->name }}</option>
                                @break
                            @case($product->combustion_chamber)
                                <option value="{{ $option->name }}" selected>{{ $option->name }}</option>
                                @break
                            @case($product->supply)
                                <option value="{{ $option->name }}" selected>{{ $option->name }}</option>
                                @break
                            @default
                                <option value="{{ $option->name }}">{{ $option->name }}</option>
                        @endswitch
                    @endforeach
                </select>
            </div>
        @endforeach

AlexanderKim left a reply on Database Design

My code above just sets all options to selected :( how can i make condition separately?

AlexanderKim left a reply on Database Design

i see only this way:

<option value="{{ $option->name }}" {{ $product->source || $product->installation == $option->name ? 'selected' : '' }}>{{ $option->name }}</option>

But that would be very long line, i have 20+ attributes.

AlexanderKim left a reply on Database Design

@snapey, could you throw an example, please?

AlexanderKim started a new conversation Database Design

I have products table and separate table for select lists (options, option_types)

Should i store select list values in a products table or somehow different?

If i'll be holding select list values in a products table, then how i pre-fill them with previously selected values:

        @foreach($option_types as $type)
            <div class="form-group">
                <label for="source">{{ $type->label }}</label>
                <select class="form-control" id="{{ $type->name }}" name="{{ $type->name }}">
                    @foreach($type->options as $option)
                        <option value="{{ $option->name }}">{{ $option->name }}</option>
                    @endforeach
                </select>
            </div>
        @endforeach

All select values are store in a products table, i can't wrap myself on how to set selected in my case..

22 Jun
4 months ago

AlexanderKim left a reply on How To Correctly Receive Ajax's Post Data?

Seems like $request->input('file') is empty at all, any ideas?

AlexanderKim left a reply on How To Correctly Receive Ajax's Post Data?

with this?

$file = $request->file('file');
 return response()->json($file->getRealPath());

It's obvious.

How can i check dd() output when i'm doing POST request with ajax?

AlexanderKim started a new conversation How To Correctly Receive Ajax's Post Data?

Here's ajax:

            $.upload = function(file) {
                let out = new FormData();
                out.append('file', file, file.name);

                $.ajax({
                    method: 'POST',
                    url: '/summer-uploads',
                    //check laravel document: https://laravel.com/docs/5.6/csrf#csrf-x-csrf-token
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                    contentType: false,
                    cache: false,
                    processData: false,
                    dataType: 'JSON',
                    data: out,
                    success: function(url) {
                        console.log(url);
                        $('#description').summernote('insertImage', url);
                    },
                    error: function(jqXHR, textStatus, errorThrown) {
                        console.error(textStatus + " " + errorThrown);
                    }
                });
            };

Controller:

    public function summerUploads(Request $request)
    {
        if ($request->ajax()) {
            $file = $request->input('file');

            return response()->json($file->path());
        }

        return App::abort(404);
    }

But i'm keep getting an error: "Call to a member function path() on null"

I guess, it's not getting the values from ajax's data? Because $file is null.

AlexanderKim started a new conversation Storing Summernote Images In A Database

I've done so far the following:

Ajax request:

            $('#description').summernote({
                callbacks: {
                    onImageUpload: function(files) {
                        for(var i=0; i < files.length; i++) {
                            $.upload('image', files[i]);
                        } 
                    }
                }
            });

            $.upload = function (file) {
                let out = new FormData();
                out.append('file', file, file.name);

                $.ajax({
                    method: 'POST',
                    url: '/summer-uploads',
                    //check laravel document: https://laravel.com/docs/5.6/csrf#csrf-x-csrf-token
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                    contentType: false,
                    cache: false,
                    processData: false,
                    dataType: 'JSON',
                    data: out,
                    success: function (r) {
                        $('#description').summernote('insertImage', r.url);
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        console.error(textStatus + " " + errorThrown);
                    }
                });
            };

Controller:

    public function summerUploads(Request $request)
    {
        if ($request->ajax()) {
            $file = $request->input('image');

            $store = $file->store('summer-uploads');

            return url() . '/summer-uploads/' . $store;
        }

        return App::abort(404);
    }

Routes:

Route::any('summer-uploads', '[email protected]');

If i try to upload an image, i'm getting the error: 500 (Internal Server Error) in console. If i try to in POSTMAN, i do get "The page has expired due to inactivity. " My CSRF token in meta is present, what could be an issue?

21 Jun
4 months ago

AlexanderKim left a reply on JS Libraries To Handle Image Uploads

My use case is the following:

Basic crud application, when i upload image using the default file input, i don't see a preview of the uploaded image (it should be stored in temp dir somewhere), then after i save an entity, i'll go to edit form, and want to delete that image without deleting whole entity from database.