IvanRadojevic

IvanRadojevic

Member Since 10 Months Ago

Experience Points
29,120
Total
Experience

880 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
29,120 XP
Oct
26
1 day ago
Activity icon

Replied to Migration Migrane

They exists, but I already have products in products table, and that make the problems...

I added to be nullable.

$table->unsignedBigInteger('brand_id')->index()->nullable();
$table->unsignedBigInteger('manufacturer_id')->index()->nullable();
Activity icon

Started a new Conversation Migration Migrane

I want to add colums to the products table. I don't know what it wants now.

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (kofi.#sql-758_1c8, CONSTRAINT products_brand_id_foreign FOREIGN KEY (brand_id) REFERENCES brands (id)) (SQL: alter table products a dd constraint products_brand_id_foreign foreign key (brand_id) references brands (id))

public function up()
    {
        Schema::table('products', function (Blueprint $table) {
            $table->string('photo')->default('https://images.unsplash.com/photo-1506629082955-511b1aa562c8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80');
            $table->unsignedBigInteger('brand_id')->index();
            $table->unsignedBigInteger('manufacturer_id')->index();

            $table->foreign('brand_id')->references('id')->on('brands');
            $table->foreign('manufacturer_id')->references('id')->on('manufacturers');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('products', function (Blueprint $table) {
            $table->dropColumn(['photo', 'brand_id', 'manufacturer_id']);
        });
    }
Oct
25
2 days ago
Activity icon

Replied to Error: Trying To Get Property 'quantity' Of Non-object

$tnx["благодарам"] ;

Activity icon

Started a new Conversation Error: Trying To Get Property 'quantity' Of Non-object

dd($basket) =

array:2 [
  0 => array:3 [
    "quantity" => 3
    "variation" => array:5 [
      "id" => 4
      "name" => "small pack"
      "price" => ".00"
      "stock_count" => 100
      "in_stock" => true
    ]
    "slug" => "kafa"
  ]
  1 => array:3 [
    "quantity" => 2
    "variation" => array:5 [
      "id" => 5
      "name" => "big pack"
      "price" => ".99"
      "stock_count" => 100
      "in_stock" => true
    ]
    "slug" => "kafa"
  ]
]

I am trying to insert $basket data in many-to-many table

foreach ($basket as $item) {
            ProductVariationOrder::create([
                'order_id' => $order->id,
                'quantity' => $item->quantity,
                'product_variation_id' => $item->variation>id,              
            ]);
        }
Activity icon

Replied to Call To A Member Function Except() On Array

and then I have to go back to the array...

$collection = collect($data)->except('basket');
$foo = $collection->toArray();
Activity icon

Started a new Conversation Call To A Member Function Except() On Array

I want to create Order except basket. I checked (dd) what it looked like $data, but get an error Call to a member function except() on array...

$data = $request->validate([
            'basket' => 'required|array|min:1',
            'orders_shipping_price' => 'required',           
            'orders_shipping_name' => 'required|string',
            'orders_name' => 'required|string',
            'orders_address_1' => 'required|string',           
            'orders_city' => 'required|string',
            'orders_postal_code' => 'required', 
            'orders_price' => 'required',            
            'orders_quantity' => 'required', 
            'orders_sub_total' => 'required', 
        ]);

dd($data->except('basket'));
        
//$order = Order::create($data->except('basket'));
Oct
23
4 days ago
Activity icon

Replied to Check If Relationship Exists

Oh no.. auth('sanctum')->address... It came from a tired brain.

What is the best response for else statement in this case, the most correct?

p.s. You both deserve the best reply. This time Michal Oravec, next time Snapey, sorry Laracast leader :)

Activity icon

Replied to Check If Relationship Exists

Network response message: Undefined property: Illuminate\Auth\RequestGuard::$address

I try to catch error, but Request failed with status code 500

created() {
            axios.get(`/api/addresses`).then(response => {
                console.log(response);    
            }).catch(function(error){ 
                console.log(error);
            });

Controller:

class AddressController extends Controller
{
	public function __construct()
	{
		$this->middleware('auth:sanctum');
	}

    public function index()    
    {   
        if (auth('sanctum')->address)   {

    	   return new AddressResource(
    	       auth('sanctum')->user()->address
    	   );

        } else {

            return "User doesn´t have address";
        }   

    }
Activity icon

Replied to Check If Relationship Exists

User is logged in, , but has no address yet...

Activity icon

Replied to Check If Relationship Exists

Auth user is there, but does not have address at the moment :)

Activity icon

Replied to Check If Relationship Exists

if (auth()->user()->address)  { ...

Trying to get property 'address' of non-object

p.s. Sanctum because I am using Sanctum.

Activity icon

Started a new Conversation Check If Relationship Exists

I am trying to check in controller does auth User has address, but have error: Call to a member function address() on null.

controller:
if ( (auth('sanctum')->user()->address()->exist()) ) { ...

model class User:
public function address()
    {
        return $this->hasOne(Address::class);
    }
Activity icon

Replied to Data From Vuex Getters...

Thank you for your effort. I thought it was simpler, with less code. I will try to post the data to the backend directly from the getter. Anyway, I'm going to need this piece of code. Thanks again.

Activity icon

Started a new Conversation Data From Vuex Getters...

How to get data in data() from Vuex Getters. I try this.totalPrice, but data is undefined.

       computed: {
            
            ...mapGetters(["totalPrice"]),
                   
        },

        data() {
            return {
                address: {},
                shippings: [], 
                form: {
                    shipping_price: "",
                    shipping_name: "",
                    orders_name: "",
                    orders_address_1: "",
                    orders_city: "",
                    orders_postal_code: "",
                    orders_totalprice: this.totalPrice,
                    orders_quantity: "",
                    orders_sub_totalprice: "",
                }             
            };
        },
Oct
20
1 week 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 week 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
1 week 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
2 weeks 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.