AlexanderKim

Hire Me

Experience

13,775

2 Best Reply Awards

  • Member Since 4 Years Ago
  • 52 Lessons Completed
  • 0 Favorites

7th August, 2018

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

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

6th August, 2018

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

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? • 1 month ago

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

16th July, 2018

AlexanderKim left a reply on Tinker Won't Detect Migration Class • 2 months ago

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

AlexanderKim left a reply on Tinker Won't Detect Migration Class • 2 months ago

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 • 2 months ago

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. • 2 months ago

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 • 2 months ago

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.

14th July, 2018

AlexanderKim left a reply on How To Use Faker In Seeder? • 2 months ago

@Cronix

Thank you :)

AlexanderKim left a reply on How To Use Faker In Seeder? • 2 months ago

@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? • 2 months ago

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.

13th July, 2018

AlexanderKim left a reply on Set Cookie On Ajax Post Request • 2 months ago

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 • 2 months ago

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

AlexanderKim started a new conversation Set Cookie On Ajax Post Request • 2 months ago

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?

10th July, 2018

AlexanderKim left a reply on Ajax Pagination Not Working • 2 months ago

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 • 2 months ago

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/.

8th July, 2018

AlexanderKim left a reply on Using || Operator In PHP • 2 months ago

@CodebyRay

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

AlexanderKim left a reply on Using || Operator In PHP • 2 months ago

@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 • 2 months ago

@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?

7th July, 2018

AlexanderKim left a reply on Chrome Or Safari On Mac? • 2 months ago

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

6th July, 2018

AlexanderKim started a new conversation Chrome Or Safari On Mac? • 2 months ago

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?

3rd July, 2018

AlexanderKim left a reply on Filtering Data With Selected Order And Returning Data With Pagination • 2 months ago

@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?

2nd July, 2018

AlexanderKim started a new conversation Filtering Data With Selected Order And Returning Data With Pagination • 2 months ago

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.

1st July, 2018

AlexanderKim left a reply on Vote Up & Down Packages • 2 months ago

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? • 2 months ago

@Cronix

But how do i update my product list with pagination?

AlexanderKim started a new conversation Vote Up & Down Packages • 2 months ago

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 • 2 months ago

@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 • 2 months ago

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.

29th June, 2018

AlexanderKim left a reply on How To Make Select Filters? • 2 months ago

What if i use selects without form?

AlexanderKim left a reply on How To Make Select Filters? • 2 months ago

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

AlexanderKim started a new conversation How To Make Select Filters? • 2 months ago

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?

27th June, 2018

AlexanderKim left a reply on Valet Share - Chrome Complains About Deceptive Site • 2 months ago

Put the PC to sleep, then it magically worked.

AlexanderKim left a reply on Valet Share - Chrome Complains About Deceptive Site • 2 months ago

It's laravel mix probably screwing up my css?

AlexanderKim left a reply on Valet Share - Chrome Complains About Deceptive Site • 2 months ago

lol, is that laravel bug? it complains about css

AlexanderKim started a new conversation Valet Share - Chrome Complains About Deceptive Site • 2 months ago

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?

25th June, 2018

AlexanderKim left a reply on Setting Custom Date Results An Error • 2 months ago

I just want to set default date format for model

AlexanderKim left a reply on Assign Variable Class To <body> With Blade? • 2 months ago

I want to extend @bastiaan89 's answer:

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

Otherwise it would throw an error about empty var.

24th June, 2018

AlexanderKim started a new conversation Setting Custom Date Results An Error • 2 months ago

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();

23rd June, 2018

AlexanderKim left a reply on Database Design • 2 months ago

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 • 2 months ago

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

AlexanderKim left a reply on Database Design • 2 months ago

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 • 2 months ago

@snapey, could you throw an example, please?

AlexanderKim started a new conversation Database Design • 2 months ago

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..

22nd June, 2018

AlexanderKim left a reply on How To Correctly Receive Ajax's Post Data? • 2 months ago

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

AlexanderKim left a reply on How To Correctly Receive Ajax's Post Data? • 2 months ago

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? • 2 months ago

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 • 2 months ago

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?

21st June, 2018

AlexanderKim left a reply on JS Libraries To Handle Image Uploads • 2 months ago

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.

AlexanderKim started a new conversation JS Libraries To Handle Image Uploads • 2 months ago

Is there any good js libraries with mass image upload, just like dropzonejs, but with delete function?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.