IvanRadojevic

IvanRadojevic

Member Since 10 Months Ago

Experience Points
28,780
Total
Experience

1,220 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
199
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.

Level 6
28,780 XP
Oct
20
13 hours ago
Activity icon

Replied to How Spatie QueryBuilder Works?

Nice, but in the meantime I gave up on that package. There are a few mistakes, and I don’t have time to solve.

Oct
19
1 day ago
Activity icon

Replied to Frontend Query String For Spatie Query Builder

This can cause a problem how to determine the active link. Is it possible to decode somehow?

Activity icon

Replied to Limit Array_merge By One Key

I have duplicated keys, 2 [filter]name, but showing me result for the one key.

http://test.test/products?[filter]name=puma&[filter]name=nike
Activity icon

Replied to Limit Array_merge By One Key

Tnx, I try this, but have error array_unique() expects parameter 2 to be int, array given.

@foreach(\App\Product::get()->pluck("name") as $value => $name)
<a href="{{ route('products.index', array_unique(array_merge(request()->query()),  [ 'filter[name]' => $name  ] ) )  }}" >{{$name}}</a>
@endforeach

Activity icon

Replied to Limit Array_merge By One Key

My brain burned out :| I will continue to study in the coming days.

Activity icon

Replied to Limit Array_merge By One Key

and that would be just the beginning, imagine inserting 15 more parameters.

Spatie:
$products = QueryBuilder::for(Product::class)
    		->allowedFilters('name', AllowedFilter::exact('size') )
    		->get();
Mine:
$products= Product::when($request->get('name'), function ($query, $name) {
        return $query->where('name', $name);
    })->when($request->get('size'), function ($query, $size) {
        return $query->where('size', $size);
    })->get();
Activity icon

Replied to Limit Array_merge By One Key

I wanted my code not to be 50 lines long, and to implement multiple selected values with the same key.

Activity icon

Replied to Limit Array_merge By One Key

I'm not claiming that, but I asked the question with the thought that it can't.

https://laracasts.com/discuss/channels/laravel/specify-multiple-matching-filter-spatie

Activity icon

Replied to Limit Array_merge By One Key

But I've already asked the question, and this one ?filter[name]=seb,freek can't do without JS?!

Activity icon

Replied to Limit Array_merge By One Key

From the Spatie docs, this is how it should look query string for the same key // GET /users?filter[name]=seb,freek

Activity icon

Replied to Limit Array_merge By One Key

"For the love of science and logic, why?"

:)

Because, my raw code is to ugly, thousands of when and where statements.

Activity icon

Replied to Limit Array_merge By One Key

I am using Spatie package Query Builder: When I click adidas:

url: http://test.test/products?filter%5Bname%5D=adidas
data: [{"id":1,"name":"adidas","size":"l","created_at":null,"updated_at":null},{"id":2,"name":"adidas","size":"xl","created_at":null,"updated_at":null}]

and then, when I click puma I have result only for puma, but in query string stay adidas.

url: http://test.test/products?filter%5Bname%5D=adidas&filter%5Bname%5D=puma
data: [{"id":3,"name":"puma","size":"s","created_at":null,"updated_at":null},{"id":4,"name":"puma","size":"xl","created_at":null,"updated_at":null}]
Activity icon

Replied to Limit Array_merge By One Key

No, I dont want double key with same name in query string: ?[filter]name=puma&[filter]name=nike , but I need array_merge for the other keys: size, color, etc...

Activity icon

Started a new Conversation Limit Array_merge By One Key

How to limit array_merge by one key with same name. For the example: http://test.test/products?[filter]name=puma&[filter]name=nike I want only to be "clickable" one key http://test.test/products?[filter]name=puma

@foreach(\App\Product::get()->pluck("name") as $value => $name)
<a href="{{ route('products.index', array_merge(request()->query(), [ 'filter[name]' => $name  ] ) )  }}" >{{$name}}</a>
@endforeach

<br>

@foreach(\App\Product::get()->pluck("size") as $value => $size)
<a href="{{ route('products.index', array_merge(request()->query(), [ 'filter[size]' => $size  ] ) ) }}" >{{$size}}</a>
@endforeach
Activity icon

Replied to Specify Multiple Matching Filter - Spatie

Yes, Vue.js, but only when I do it this way. Is it possible to do that without javascript.

Activity icon

Started a new Conversation Specify Multiple Matching Filter - Spatie

How to specify multiple matching filter for the Spatie package Query Builder?

Url should be:

?filter[name]=seb,freek

I try this, and error is array_merge(): Expected parameter 1 to be an array, string given

@foreach(\App\Product::get()->pluck("name") as $value => $name)
<a href="{{ route('products.index',  [ 'filter[name]' => array_merge($name) ] ) }}" >{{$name}}</a>
@endforeach
Activity icon

Started a new Conversation Frontend Query String For Spatie Query Builder

How to make on frontend query string for Spatie query builder?

@foreach(\App\Product::get()->pluck("name") as $value => $name)

<a href="{{ route('products.index', ['filter[name]'=>$name ]) }}" >{{$name}}</a>

@endforeach

Result is this:
http://test.test/products?filter%5Bname%5D=armani

wanted :
http://test.test/products?filter[name]=armani
Activity icon

Replied to How Spatie QueryBuilder Works?

Ok, that is it. I am reading official docs: FILTER A QUERY BASED ON A REQUEST: /USERS?FILTER[NAME]=JOHN:

Activity icon

Replied to How Spatie QueryBuilder Works?

Only that.

Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        });

[{"id":1,"name":"armani","created_at":null,"updated_at":null},{"id":2,"name":"armani","created_at":null,"updated_at":null},{"id":3,"name":"puma","created_at":null,"updated_at":null},{"id":4,"name":"puma","created_at":null,"updated_at":null}]

Activity icon

Started a new Conversation How Spatie QueryBuilder Works?

In controller I have this function, from the Spatie docs example:

public function index(Request $request)
    {
        $products = QueryBuilder::for(Product::class)
    		->allowedFilters('name')
    		->get();

        return view('products', compact('products'));
    }

I am trying this URL:

http://test.test/products?FILTER[name]=armani

However I get all the results, they are not filtered!

Activity icon

Replied to Class 'Spatie\QueryBuilder\QueryBuilder' Not Found

I adjusted manualy in php.ini file

Activity icon

Replied to Class 'Spatie\QueryBuilder\QueryBuilder' Not Found

Could not open input file: composer

Activity icon

Replied to Class 'Spatie\QueryBuilder\QueryBuilder' Not Found

I try for my Composer path: php -d memory_limit=-1 /c/ProgramData/ComposerSetup/bin/composer require spatie/laravel-query-builder

dir=$(cd "${0%[/\]*}" > /dev/null; pwd)

if [ -d /proc/cygdrive ]; then
    case $(which php) in
        $(readlink -n /proc/cygdrive)/*)
            # We are in Cygwin using Windows php, so the path must be translated
            dir=$(cygpath -m "$dir");
            ;;
    esac
fi

php "${dir}/composer.phar" "[email protected]"
Activity icon

Replied to Class 'Spatie\QueryBuilder\QueryBuilder' Not Found

Oh, I have this error, didnt saw. PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

Activity icon

Started a new Conversation Class 'Spatie\QueryBuilder\QueryBuilder' Not Found

I was installed "spatie/laravel-query-builder": "^3.3", and try basic example, but I have an error Class 'Spatie\QueryBuilder\QueryBuilder' not found?

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Product;

use Spatie\QueryBuilder\QueryBuilder;

class ProductController extends Controller
{
    public function index(Request $request)
    {
        $products = QueryBuilder::for(Product::class)
    		->allowedFilters('name')
    		->get();

        return view('products', compact('products'));
    }
}
Oct
15
5 days ago
Activity icon

Started a new Conversation Access Via URL, Sanctum

Can i access to API via URL when I am using Sanctum. With axios link is working, but when I try with url, it send me to home page?

Oct
13
1 week ago
Activity icon

Replied to Vuex State Updating.

Thanks for the advice, but what can I use for reference, instead id. name, slug?

Activity icon

Replied to Vuex State Updating.

That should be it. You are the god, the king, the master of the universe :)

p.s. This is not according to the documentation (:

Activity icon

Replied to Vuex State Updating.

store.js

state: {

    isLoggedIn: false,
    user: {},

    title: 'Welcome',

    categories: [],


    basket: {
            items: []
    },

  },

From vuex devtools after updating.

basket:Object
items:Array[1]
0:null
Activity icon

Replied to Vuex State Updating.

After updating local storage is set to: basket:"{"items":[null]}"

Activity icon

Replied to Vuex State Updating.

Maybe the problem is with localStorage.

Activity icon

Replied to Vuex State Updating.

I want only to show where is the problem. I try uncommented, but that is not working.

Activity icon

Replied to Vuex State Updating.

I must dispatch to the actions, because localStorage.

Activity icon

Started a new Conversation Vuex State Updating.

I can't find good documentation on how to update vuex state. I try to update basket.item, but this updating work sonly for the first time. Next updating set basket item state to null !?!

template:

<select v-model="vquantity"
                ...
</select>


script:

props: {
            item: {
                type: Object,
                required: true
            }
 },

data () {
            return {
                vquantity: this.item.quantity
            }
},

watch: {
          'vquantity' (vquantity) {
            this.$store.dispatch("updateBasket", {     
                    quantity: vquantity,
                    id: this.item.variation.id
            })
          }
 },



////////////////////////////////////////////////////////////////////////////////////////
store.js:

actions:
updateBasket({ commit, state }, payload) {
          commit('updateBasket', payload);                          
          localStorage.setItem('basket', JSON.stringify(state.basket)); 
    },

mutations:

//updateBasket(state, payload)  {
    //  const newItems = state.basket.items.map(item => {
    //    if (item.variation.id === payload.id) {
    //    item.quantity = payload.quantity
    //  }
    // })

    //  state.basket = Object.assign({}, state.basket, {
    //  items: newItems
    //  })
    //},

state:
basket: {
            items: []
 },
Activity icon

Started a new Conversation How To Update VUEX State With Mutations?

I want to update quantity in shopping cart, but how to update state with mutations?

template:

<select v-model="vquantity"
                ...
</select>


script:

props: {
            item: {
                type: Object,
                required: true
            }
 },

data () {
            return {
                vquantity: this.item.quantity
            }
},

watch: {
          'vquantity' (vquantity) {
            this.$store.dispatch("updateBasket", {     
                    quantity: vquantity,
                    id: this.item.variation.id
            })
          }
 },



////////////////////////////////////////////////////////////////////////////////////////
store.js:

actions:
updateBasket({ commit, state }, payload) {
          commit('updateBasket', payload);                          
          localStorage.setItem('basket', JSON.stringify(state.basket)); 
    },

mutations:
updateBasket(state, payload) {
        ? ? ?
    },

state:
basket: {
            items: []
 },
Activity icon

Replied to Selected Option Is Blank?

I solved it by making a sub component. For now, that is doing job. I will see in other cases is it a good way.

Activity icon

Started a new Conversation Selected Option Is Blank?

I have value {{ item.quantity }} that show 3. But in this selected options there is not value?!?

item.variation.stock_count is 100.


<select v-model="quantityUpdate" class=" appearance-none bg-white border border-gray-400 hover:border-gray-500 px-4  rounded shadow leading-tight focus:outline-none focus:shadow-outline">

                        <option 
                                :value="x"
                                v-for="x in item.variation.stock_count"
                                :key="x"
                                :selected="x == item.quantity"
                            >{{ x }}
                        </option>

 </select>
Oct
12
1 week ago
Activity icon

Replied to API Does Not Load At All

Yes, it works that way

return [
            "id" => $this->id,
            "name" => $this->name,
            "price" => $this->formattedPrice,
            "stock_count" => $this->stock,
            "in_stock" => $this->inStock(),
            "product" => new BelongsToProduct($this->product),
            
        ];

It seemed to me that it was easier for me to break down data from shopping cart, but it is not necessary.

Activity icon

Replied to API Does Not Load At All

Can I try to make new resource for belongsTo relationship for the product:

"product" => new ProductFooResource($this->product),
Activity icon

Replied to API Does Not Load At All

Yes, probably is that; ProductResource

return [
            "id" => $this->id,
            "name" => $this->name,
            "slug" => $this->slug, 
            "description" => $this->description, 
            "price" => $this->formattedPrice,
            "product_stock_count" => $this->productStockCount(),
            "in_product_stock" => $this->inProductStock(),
            "variations" => ProductVariationResource::collection($this->variations)->groupBy("type.name"),
            
        ];
Activity icon

Started a new Conversation API Does Not Load At All

I have an API, that does not load at all, not error, intinity loading. I check in Postman, same situation.

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Http\Resources\ProductResource;

class ProductVariationResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            "id" => $this->id,
            "name" => $this->name,
            "price" => $this->formattedPrice,
            "stock_count" => $this->stock,
            "in_stock" => $this->inStock(),
            "product" => new ProductResource($this->product),
            
        ];
    }
}

The problem arose when I entered "product" => new ProductResource($this->product), It works without it, but why don't I have error?

  return [
            "id" => $this->id,
            "name" => $this->name,
            "price" => $this->formattedPrice,
            "stock_count" => $this->stock,
            "in_stock" => $this->inStock(),
        ];
Oct
02
2 weeks ago
Activity icon

Started a new Conversation Shopping Cart Approach

I know there are many packages for Cart implementation, but I I want to do it myself.

I am in doubt which is the better approach: Cookies or Session. What are your opinions?

Oct
01
2 weeks ago
Activity icon

Replied to Migration Error

It's okay, I made the wrong migration schedule.

Activity icon

Started a new Conversation Migration Error

I can't figure out the error. Can anyone do?

(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `product_variations` add constraint `product_variations_product_variation_type_id_foreign` foreign key (`prod
uct_variation_type_id`) references `product_variation_types` (`id`))
Sep
29
3 weeks ago
Activity icon

Started a new Conversation Changing URL On The Same Component -Vue SPA

I thought I had found a solution, but when I tried to refresh the page, data were not loaded.

watch: {
        '$route': 'reInitialize'
},

methods: { 		
        	reInitialize: function() {
            axios.get(`/api/products?category=${this.$route.params.slug}`).then(response => {
      				this.products = response.data.data;
        		});
        	},
},

How to properly load data on the same component, and change the url depending on the query string?

Sep
28
3 weeks ago
Activity icon

Replied to Multi Axios Calls - Vue SPA

I found solution. "Even thought the URL is changing the component is not, VueJS is basically reusing the component and therefore not calling the created() method again.

Usually you can setup a watcher and refactor a bit your code".

watch: {
        '$route': 'reInitialize'
    	},

    	methods: {
        	reInitialize: function() {
            	axios.get(`/api/products?category=${this.$route.params.slug}`).then(response => {
      				this.products = response.data.data;
        		});
        	},

    	},
Activity icon

Replied to Multi Axios Calls - Vue SPA

URL is changing properly, but without new axios calls, only first and that is it.

Network - xhr have only first request.

Activity icon

Replied to Multi Axios Calls - Vue SPA

Yes, sometimes it's hard for me to explain what I want.

When I click
foo.test/products/categories/shoes page, axios loading data from
foot.test/api/products?category=shoes. And that is working.

Than I want for example to click
foo.test/products/categories/jackets , axios NOT loading data from
foo.test/api/products?category=jackets

I supose the problem is that I am at the same page (SPA app), and browser is not refreshing.
Activity icon

Started a new Conversation Multi Axios Calls - Vue SPA

How to make multi axios calls on the same page according to the query string parameters?

This is my case:

Router link to the CategoriesList

<router-link :to="{ name: 'categorieslist', params: { slug: category.slug } }">      <div>  {{ category.name }} </div>  </router-link>

This is routes.js file


{
        path: "/products/categories/:slug",
        component: CategoriesList,       
        name: "categorieslist",
        meta: {title: "CategoriesList"}
},

and CategoryList.vue page where i want to change values according axios calls

export default {
    	data() {
    		return {
     			products: [],
      			    
    		};
  		},  
  		mounted() {
        	console.log(this.$route.params.slug);
    	},
		created() {
    		
    		axios.get(`/api/products?category=${this.$route.params.slug}`).then(response => {
      			this.products = response.data.data;
      			
    		});
  		},
    }
Activity icon

Replied to VUE Router Doesn`t Work?

Yes, when i access page for the first time, everything is ok, I have correct data. Problem is when I want, for the example:

// to change page from
/products/categories/shoes ------> axios working
//to
/products/categories/jackets -------> nothing happens