viktorivanov

viktorivanov

Member Since 3 Years Ago

Gabrovo, Bulgaria

Experience Points 48,970
Experience Level 10

1,030 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 465
Lessons
Completed
Best Reply Awards 7
Best Reply
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.

08 Mar
1 year ago

viktorivanov left a reply on PHPUnit Checking Errors Incorrect In PHPStorm?

Because your $reply instance is "unaware" of the changes you've introduced.

You can get a fresh instance using $reply->fresh(), so you end up with:

$this->assertCount(1, $reply->fresh()->favorites);
13 Sep
1 year ago

viktorivanov started a new conversation Add Data To Request Object Within A Middleware

Hello, I have a custom middleware where I'm handling the current request and if a specific request header is present I need to pass down data to the chain.

And then in my controller i will check based on the data I've added to the request what response to return to the user.

So my question is:

  • Isrequest()->merge($myCustomData) the proper way to pass my data (the data will be a decoded json string).

Thank you

19 Jul
1 year ago

viktorivanov left a reply on Help With Collections.

@Stratos , I forgot to point out that you should place your macro in one of your ServiceProvider's :)

18 Jul
1 year ago

viktorivanov left a reply on Help With Collections.

One way I can think of is to first check if code's value exists in the collection with contains and if the check is true use transform else push the new item into the collection.

And because the code gets muddy I would make an macro

        Collection::macro('updateCart', function (array $cartItem) {
            return $this->contains('code', $cartItem['code'])
                ? $this->transform(function ($item) use ($cartItem) {
                    if ($cartItem['code'] === $item['code']) {
                        $item['quantity'] += $cartItem['quantity'];
                        return $item;
                    } else {
                        return $item;
                    }
                })
                : $this->push($cartItem);
        });

And use it like this:

        $newCode = ['code' => '123', 'name' => 'Item 1', 'quantity' => 3];

        $cart = collect([
            ['code' => '123', 'name' => 'Item 1',  'quantity' => 1],
            ['code' => '456', 'name' => 'Item 1',  'quantity' => 1]
        ]);

        return $cart->updateCart($newCode);

Please note I have used transform, but if you not wish to directly change the cart collection use map.

viktorivanov left a reply on Condition In Laravel 5 Middleware Always False

Are you trying to use the middleware in your API routes (routes/api.php)? By default these routes are stateless therefore you cannot use session, cookies, etc.

07 Jul
1 year ago

viktorivanov left a reply on Errors In Add Multiple Img By Laravel 5.3

You're looping through the files and every time $post->images's value is overridden and you're left with only the last filename in the database.

I would advice you to associate your Post model with a Image model where Post hasMany Image / Image belongsTo Post. Read more here. Your images table will contain id, name and post_id which will be the foreign key to posts table...

And then you can change your code to be more like:

in Post.php


public function images()
{
    return $this->hasMany(Image::class, 'post_id');
}

in Image.php


public function post()
{
    return $this->belongsTo(Post::class, 'post_id');
}
public function newOffer(Request $request){

    $validate_marge['images'] = 'required';
    $validator = Validator::make($request->all(), $validate_marge);

    if ($validator->fails()){
        return back()->withInput()->withErrors($validator);
    }

    $post = new Post();
    $post->title = Input::get('title');
    $post->category_id = Input::get('category_id');
    $post->second_title = Input::get('second_title');
    $post->description = Input::get('description');
    $post->location = Input::get('location');
    $post->price = Input::get('price');
    $post->save();

    if ($request->hasFile('images')) {
        $files = $request->file('images');
        foreach ($files as $file) {
            $filename = str_random(6) . '_' . time(). $file->getClientOriginalName();
            $file->move(public_path('img/offers').'/', $filename);

            $image = new Image(['name' => $filename]);
            $post->images()->save($image);
        }
    }


    Session::flash('message', 'Congratulation, Post Created!');
    return back();
}

viktorivanov left a reply on Guzzle Issue?

Try to set headers to accept json, eg.'Accept' => 'application/json',

viktorivanov left a reply on Strange Group By Behaviour

Actually the problem is not with Eloquent, but how you are using group by.

Directly from MySQL's reference manual:

In standard SQL, a query that includes a GROUP BY clause cannot refer to nonaggregated columns in the select list that are not named in the GROUP BY clause.

viktorivanov left a reply on Uploading Files And Storing Path In Database

Hi @jontyjago , I was having the same issue with path including public/xxx_hash_xxx.jpg and what i did was to use basename($path) and prefix it with 'storage/' and then store the string to the db, eg. storage/xxx_hash_xxx.jpg.

But I'm curious to see the proper way as well :)

06 Jul
1 year ago

viktorivanov left a reply on Save My Api Token

@f0ntana, so your laravel driven API will first have en endpoint to sign a cookie, right? I mean you'll pass some username/password credentials and if they are correct the API can response with the token. So that token can be stored on a cookie. After that the client will pass the token with every request to the API. API will probably have some parsing and checking (probably in a middleware) on the routes of your choice whether the token is valid and not expired.

05 Jul
1 year ago

viktorivanov left a reply on Laravel Referer Tracking

Hello @tolgayigit , I'll suggest to use Middleware where you could check for ?ref_id=10 and make a cookie using the queue method, that way Laravel will set it for you with the next response.

Here are the steps to reproduce:

  1. go in terminal and type php artisan make:middleware Referrer and Laravel will generate a class Referrer in app/Http/Middleware
  2. in handle method of that class type in the following:
    public function handle($request, Closure $next)
    {
        if($request->has('ref_id')) {
            Cookie::queue('ref_id', $request->get('ref_id'), 43200); // 43200 in minutes are 30 days
        }
        return $next($request);
    }
  1. register your middleware in app/Http/Kernel as route middleware, e.g. append 'referrer' => App\Http\Middleware\Referrer::class into protected $routeMiddleware

  2. assign 'referrer' to your "home" route in routes/web.php, for example Route::get('/home', '[email protected]')->name('home')->middleware('referrer');

And whenever there is ref_id query parameter in your home route (http://www.example.com?ref_id=10) a cookie will be set on the client's browser.

Cheers

viktorivanov left a reply on Save My Api Token

Store your token on the client side, for example on a cookie (preferable) or in https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage or https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage. And pass that with every request to the API where you check the validity of the token.

viktorivanov left a reply on Unable To Login Using Attempt Method

Perhaps check for their existence in the users table...

15 Jun
2 years ago

viktorivanov left a reply on Run TinyMCE With Vue

Please make a fiddle or codepen to make the debugging more easy...

p.s. I'm also noticing you've putted v-model on the textarea which will make the syncing of the value between tinymce and the v-model not so straightforward... 'cause tinymce doesn't update the value of the textarea on every keystroke, so for that reason you would have to use its API

viktorivanov left a reply on Run TinyMCE With Vue

Here I've made a quick fiddle so you can see how it works

viktorivanov left a reply on Run TinyMCE With Vue

This sounds like your textarea element is not available... Please double check you're passing target: el where comes from bind(el)

14 Jun
2 years ago

viktorivanov left a reply on Run TinyMCE With Vue

Try this


    import tinymce from 'tinymce/tinymce'
    import 'tinymce/themes/modern/theme'

    Vue.directive('tinymce', {
        bind(el) {
            tinymce.init({
              target: el, // The element the directive is bound to. See here https://vuejs.org/v2/guide/custom-directive.html#Directive-Hook-Arguments
              theme: 'modern',
              skin_url: '/css/tinymce/skins/lightgray' // point your tinymce skin directory here
          })
        }
    })
12 Jun
2 years ago

viktorivanov left a reply on Notification System

Sure, basically you have to insert 'object_id' in select list, omit the where clause for 'object_id' and finally group by the 'object_id' to get what you want.

$notifications = App\Notification::select('object_id', \DB::raw('SUM(type="post_like") as post_like_count'), \DB::raw('SUM(type="post_dislike") as post_dislike_count'), '...the other types...')->where([['user_id', $currentUserId],['read', false]])->groupBy('object_id')->get();

and the result will be something like

 Illuminate\Database\Eloquent\Collection {#728
     all: [
       App\Notification {#671
         object_id: 1,
         post_like_count: "3",
         post_dislike_count: "2",
       },
       App\Notification {#729
         object_id: 2,
         post_like_count: "2",
         post_dislike_count: "1",
       },
     ],
   }

// ....

p.s. you can also order them by the number of likes, etc.

viktorivanov left a reply on Laravel And Vue.JS 2 Multilingual

I use the following laravel package. It basically gives you laravel translations available inside your vue when using vue-i18n.

viktorivanov left a reply on Notification System

You can try something like this:

assuming the column 'red' is a typo for the word 'read' which is how you'll determine if the notification is already seen by the user.

$notifications = App\Notification::select(\DB::raw('SUM(type="post_like") as post_like_count'), \DB::raw('SUM(type="post_dislike") as post_dislike_count'), '...the other types...')->where([['user_id', $currentUserId],['object_id', $currentObjectId],['read', false]])->get();
09 Jun
2 years ago

viktorivanov left a reply on Accessing Dynamic Database In Laravel

You're using the following package for mongodb, right?

Assuming you are, can you try specifying the connection when executing your 'contacts' fetching query?

\DB::connection($users->db_name)->collection('users')->get();
10 May
2 years ago

viktorivanov left a reply on Vue Js Anonymous Function Access This.user

this.user is undefined because of the context this has when you're inside function callbacks and how they're called. More on this subject here.

So you could just var self = this before you call geocoder and replace every "this" inside the callback with "self", e.g. this.user would be self.user

Other solutions are pointed out in the link above so you should definitely check it out as this is common "pitfall" in JavaScript :)

viktorivanov left a reply on Form Validation Array Not Validating Properly

You can follow this guide. Also I'm noticing that your code has $errors->has('step-title'.$i) but the name of the field is only title...

viktorivanov left a reply on Adding The Rest And Spread Operator To A Laravel/vue Application

You could use this Than create on your own the .babelrc file with something like

{
"plugins": [
    "transform-object-rest-spread"
  ]
}```
23 Nov
2 years ago

viktorivanov left a reply on Laracasts Refresh

Hi @JeffreyWay,

can you consider showing the publication date for every Laracast Snippet?

Great work by the way!

Cheers

25 May
3 years ago

viktorivanov left a reply on Vue.js Data Value Not Updating

@jgravois please check this about the prop/data issue.

Good luck :)

viktorivanov left a reply on Props Without Values (think Attributes) In Vuejs

You have to use v-bind or : syntax to pass data from the parent scope to your component's scope. If you omit them and just use spacer="true" Vue will interpret your spacer prop as the string "true" and not the boolean true.

viktorivanov left a reply on Vue.js Data Value Not Updating

I think the reason is in the arrow function where this is not what you would expect. You can read more in this article.

Just change your code and use property method assignment and it should work.

Also avoid using the same name for props and data properties. In your case scopes

17 May
3 years ago

viktorivanov left a reply on Can't Passing Value Object To Custom Component

Hi,

you need to use props in order to pass data into your component. Also you should definitely check the Learning Vue 1.0 series.

viktorivanov left a reply on Only Send A Form When It Is Valid

Hi, just leave one handler on the form itself (@submit="onSubmit") and check the state of the validator instance there. One solution will be this. So you can discard the @click handler on the submit input and in addition you could add :disabled="$validation1.invalid".

viktorivanov left a reply on Update VUE Data Object In Different Component

Hi,

I would suggest you to read about Vuex or you could use simpler approach explained here.

10 May
3 years ago

viktorivanov left a reply on Vue + Vue-validator Show Errors Only On Submit

Hi, maybe you can check out this quick fiddle I've made https://jsfiddle.net/viktorivanov/vwfmwwjz/ the idea is when submitting the form to set a variable on your vm instance (formIsInvalid) and make sure to show any error messages if it's true, e.g. v-show="$validation.title.required && formIsInvalid"

13 Nov
3 years ago

viktorivanov left a reply on Updating All Form Text Fields At Once

You can use a watcher to watch changes on any of them and on every change calculate and update their values. Here's a quick jsfiddle

viktorivanov left a reply on Adding Id To Optgroup

There is not such option out of the box, but you can override and write your own implementation. See here for guidance.

12 Nov
3 years ago

viktorivanov left a reply on Set A Vue.js Data From JQuery Click Event

@jillztom , you're missing a comma between the data and methods property. Why are you adding an event listener on the addActive method? You should listen on the DOM element itself by adding @click="addActive" instead.

And your addActive method could be something like:

addActive: function(e){
    var element = $(e.target);
    this.$set('active', {
        name: element.attr('prop-name'),
        latitude: element.attr('prop-lat'), 
                 longitude: element.attr('prop-long'), 
                 icon: element.attr('prop-icon')
    });
}
11 Nov
3 years ago

viktorivanov left a reply on How To Enable A Submit Button.

You can use v-bind directive to bind on the disabled state of the input. More on that here

viktorivanov left a reply on How To Enable A Submit Button.

Hi, I've made a quick JS Bin here.

But I don't understand why you want to disable the other checkboxes? Why not just use radio inputs?