AlexanderKim

AlexanderKim

Member Since 5 Years Ago

Almaty

Experience Points 14,105
Experience Level 3

895 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 52
Lessons
Completed
Best Reply Awards 2
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

31 Aug
2 weeks ago

AlexanderKim left a reply on How To Use Docker Compose's Env Variables Inside Laravel/lumen Envs?

No, it is correct: https://docs.docker.com/compose/environment-variables/

I just tried again, lumen doesn't read variables from compose.

AlexanderKim left a reply on How To Use Docker Compose's Env Variables Inside Laravel/lumen Envs?

@bobbybouwmann i have these variables at container layer, but my .env (file) has no defined variables, so it cannot connect to a database.

AlexanderKim started a new conversation How To Use Docker Compose's Env Variables Inside Laravel/lumen Envs?

If i set env variables inside compose.yml:

version: '3'
services:
  branch-api:
    restart: always
    image: "imagename"
    ports:
      - 9000:80
    container_name: "branch"
    environment:
      - "DB_CONNECTION=pgsql"
      - "DB_HOST=152.1.1.1"
      - "DB_PORT=5432"
      - "DB_DATABASE=branch"
      - "DB_USERNAME=branch"
      - "DB_PASSOWRD=branch"

How do i use compose env variables inside laravel/lumen .env file? For example:


DB_CONNECTION=env('DB_CONNECTION')

But that won't work.

AlexanderKim left a reply on Running Lumen Inside A Docker Container

@corbosman

Do you know, what do i need to install in order to make postgres connection work in a container, i'm using php:7.3-fpm-alpine image, here's my full Dockerfile:

FROM php:7.3-fpm-alpine

RUN apk add --update \
    && docker-php-ext-install pgsql pdo_pgsql

RUN curl -sS https://getcomposer.org/installer | php -- \
  --install-dir=/usr/bin --filename=composer

COPY . /app

RUN cd "/app" && cp .env.production .env && composer install

WORKDIR /app

EXPOSE 80

CMD php -S 0.0.0.0:80 -t public

But it doesn't connect to my pgsql instance, probably i do miss something else.

AlexanderKim left a reply on Running Lumen Inside A Docker Container

i see, it's just my internal API, no need for nginx/apache. What the difference between php artisan serve and php -S - it is basically the same builtin webserver?

AlexanderKim started a new conversation Running Lumen Inside A Docker Container

I'm running Lumen instance in a docker container using this command:

CMD php -s 0.0.0.0:80 -t public

Is it ok for production API's? I just noticed, it is php development server.. i wonder, is there a php production server built-in? How do you run your Lumen's inside a docker container without a web-server? (Installing webserver is not needed in my case)

30 Aug
2 weeks ago

AlexanderKim left a reply on How To Save Current Date As Unix Timestamps In Postgres?

@resin

Schema::create('links', function (Blueprint $table) {
    $table->string('id')->primary();
    $table->string('title', 300)->nullable();
    $table->dateTime('created');
});

Not using $table->timestamps() on purpose.

AlexanderKim left a reply on How To Save Current Date As Unix Timestamps In Postgres?

Postgres is a bit different in this case, i've tried to save current date as Carbon::now()->timestamp, so the date would like unix timestamp 453412334123, but postgres won't save this in date, dateTime, timestamp field, throw ERROR 7 with overflow thing.

AlexanderKim started a new conversation How To Save Current Date As Unix Timestamps In Postgres?

Now, i'm saving my date this way:

$link->created = Carbon::now();

But in postgre i'm getting '2019-08-29' kind of date, so i cannot reformat it on my frontend with hours, minutes, seconds. What's the correct way on saving current date with Carbon?

AlexanderKim left a reply on Is There Prettier Alternative For PHP In VScode

@janosk wait, is php inteliphense does the same work as php cs fixer? I have installed them both, but none of them does the job as prettier, for example, if i omit semicolon, then formatting a document won't put a semicolon there.

AlexanderKim started a new conversation Is There Prettier Alternative For PHP In VScode

In VSCode there's a function "Format document", when i work on a clientside code in TS/JS - prettier works awesome, it corrects indentation, string lines, semicolons. But i cannot find something similar for PHP. Can somebody advice a good plugins, if it does exists.

21 Oct
10 months 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
1 year 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
1 year 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
1 year 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
1 year 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
1 year 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.

Do i need to store cookie in database at all?

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('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
1 year 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
1 year 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
1 year 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
1 year 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
1 year 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'm 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
1 year 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 displaying 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
1 year 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! Could you explain, why i should use $this->name instead of $name?

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
1 year 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? Also, i need to update my product list using Ajax as well? Or i can just force browser reload.

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
1 year 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

no ssl

Here's the error:

The site https://f7554e7d.ngrok.io/css/app.css contains harmful content, including pages that:

Try to trick visitors into sharing personal info or downloading software
Contain unwanted or malicious software

I'm printing out css file this way:

<link rel="stylesheet" href="{{ mix('css/app.css') }}">

if i comment it at all, then chrome doesn't complain about phishing stuff, but all my css stopping working. If clean out whole app.css - anyway it will complain, it stops complaining only after i comment mix('css/app.css')

@nickdavies07 have you managed to solve this issue?

Here's the share link: http://0b5e8729.ngrok.io

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
1 year ago

AlexanderKim left a reply on Setting Custom Date Results An Error

I just want to set default date format for model