IvanRadojevic

IvanRadojevic

Member Since 5 Months Ago

Experience Points
9,550
Total
Experience

450 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
59
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 2
9,550 XP
May
19
1 week ago
Activity icon

Started a new Conversation Vue-multiselect Change Color

How to change color of selected items?

Default is red, I want to be yellow.

Activity icon

Started a new Conversation Vue-multiselect Questions

My vue-multiselect have small irregularities. How to clear this glitch?

https://imgur.com/CsJLCGC

Apr
28
1 month ago
Activity icon

Replied to [Vue Warn]: Error In Render: "TypeError: _vm.users Is Undefined"

tnx, it is working.

Maybe I have problem with npm run watch

Activity icon

Replied to [Vue Warn]: Error In Render: "TypeError: _vm.users Is Undefined"

console.log(data) is ok, Array(3) [ {…}, {…}, {…} ]

but error is still there, and i have not data in table...

Activity icon

Started a new Conversation [Vue Warn]: Error In Render: "TypeError: _vm.users Is Undefined"

I try to display users but i have error; network resposnse is ok, i have correct json from api/controller

[Vue warn]: Error in render: "TypeError: _vm.users is undefined"

found in

---> at resources/js/components/Users.vue


    <tr v-for="user in users.data" :key="user.id">
                    <td>{{user.id}}</td>
                    <td>{{user.name}}</td>
                    <td>{{user.email}}</td>
                    <td>{{user.type}}</td>
                    <td>{{user.created_at}}</td>
  	</tr>


<script>
    export default {

        data() {
          return{
            users : {},
            form: new Form({
              id:'',
              name : '',
              email: '',
              password: '',
              type: '',
              bio: '',
              photo: ''              
            })
          }
        },

        methods: {
                   loadUsers() {

                    axios.get("api/user").then(( {data} ) => (this.users = data.data));
              

    },

 
        created() {
            this.loadUsers();
        }

    }
</script>
Apr
15
1 month ago
Activity icon

Awarded Best Reply on How To Show Value From DB, Selected Option?

I solved with :


<option value="{{ $category->id }}"  {{ ($song->category->id  == $category->id) ? 'selected' : '' }}     > {{ $category->name }}</option>
Activity icon

Replied to How To Show Value From DB, Selected Option?

I solved with :


<option value="{{ $category->id }}"  {{ ($song->category->id  == $category->id) ? 'selected' : '' }}     > {{ $category->name }}</option>
Activity icon

Started a new Conversation How To Show Value From DB, Selected Option?

I want to update, how to show value from DB, selected option?


 public function edit($id)
    {
        $song = Song::findOrFail($id);
        
        $categories = Category::all();
        
        return view("songs.edit", compact('song', 'categories'));
    }

----------------------------

<select name="category_id">

 @foreach ($categories as $category)
  <option value="{{ $category->id }}"> {{ $category->name }}</option>
  @endforeach    

</select>
Apr
06
1 month ago
Activity icon

Replied to How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

What about this method, to merge 2 collections?

´´´ $users = User::all(); $associates = Associate::all();

$userAndAssociate = $users->merge($associates);

Activity icon

Started a new Conversation The Map Method

I have 3 arrays. I want to map and add 27 arrays with price = 0.

How to correct map "date" => $dates?


[
{
"some_day": "2020-03-16",
"total_price": "186"
},
{
"some_day": "2020-03-18",
"total_price": "197"
},
{
"some_day": "2020-04-05",
"total_price": "50"
}
]



$collection = $orders->map(function ($orders) {

$start = Carbon::now()->subDays(30);
for ($i = 0 ; $i <= 30; $i++) {
    $dates[] = $start->copy()->addDays($i)->format('Y-m-d');
}

return [["date" => $orders->some_day, "price" => $orders->total_price], ["date" => $dates, "price" => 0]];

});

return $collection;
Activity icon

Replied to How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

I get absolutely nothing with this. It's exactly the same result.

$newCollection = $orders->map(function ($item) {
    if (!isset($item->{"some_day"})) {
        $item->total_price = 0;
    }
    return $item;
});

dd($newCollection);
Activity icon

Replied to How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

I tried this my way. I don't think it can :(

What do you think, is it availble some sql function?

Activity icon

Replied to SQL Function To Show 0.

Thanks for your reply. That's not very recommended. Excessive memory usage :)

Activity icon

Started a new Conversation SQL Function To Show 0.

My $orders collection looks like this: Is it available SQL function to show me total_price = 0 for the dates that I not have orders? In this case, I should have 27 dates with total_pirce = 0 & 3 how is it in this example.

[
{
"some_day": "2020-03-16",
"total_price": "186"
},
{
"some_day": "2020-03-18",
"total_price": "197"
},
{
"some_day": "2020-04-05",
"total_price": "50"
}
]


$orders = Order::query()
->selectRaw('DATE(created_at) AS some_day, SUM(billing_totalprice) AS total_price')
->whereBetween('created_at', [$dateFrom, $dateTo])
->groupBy('some_day')
->get();
Activity icon

Replied to How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

It is strange to me there are no SQL functions for that.

Activity icon

Replied to How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

Now it is ok! total for 3 days. Thank you very mutch for that.

Is this the way for rest 27 dates?


$start = Carbon::now()->subDays(30);
for ($i = 0 ; $i <= 30; $i++) {

    if ("startDateFromLoop" = "orders-some_day" {
    $collection[] = "Insert" "orders-some_day" "with" "orders-totalprice"; 
    }

    else{
    $collection[] = $start->copy()->addDays($i)->format('Y-m-d'); "with" "orders-totalpirce = 0";
     }
}

return $collection;
Activity icon

Replied to How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

In the end, I need 30 data for 30 days period.

I have orders for 3 days , but i want to show for rest 27 dates total_price 0.

is it availble some sql function, which show the rest 27 dates (from 30 day period) with total price = 0 ?

Activity icon

Replied to How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

You do not understand me. I need this: 3 dates, not 4!

Illuminate\Support\Collection {#328 ▼
  #items: array:3 [▼
    0 => {#331 ▼
      +"DATE(created_at)": "2020-03-16"
      +"total_price": "186"
    }
    1 => {#330 ▼
      +"DATE(created_at)": "2020-03-18"
      +"total_price": "197"
    }
    2 => {#332 ▼
      +"DATE(created_at)": "2020-04-05"
      +"total_price": "50"
    }
  ]
}
Activity icon

Replied to How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

Do you know, is it availble some sql function, which show the rest 27 dates (from 30 day period) with total price = 0?

Activity icon

Replied to How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

It is working, but I dont have data what I want. I need total price per day. For 18-03-2020 i have double data.

[
{
"created_at": "2020-03-16 00:00:00",
"total_price": "186"
},
{
"created_at": "2020-03-18 00:00:00",
"total_price": "147"
},
{
"created_at": "2020-03-18 00:00:00",
"total_price": "50"
},
{
"created_at": "2020-04-05 00:00:00",
"total_price": "50"
}
]
Activity icon

Replied to How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

I must have groupBy ('DATE(created_at)') ,because i have orders with same date, but diferent time... No, it is not working :(

Activity icon

Replied to How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

No, I dont want to replace. I want to add to the rest of dates from 30 days period, total price = 0.

Activity icon

Replied to How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

No, I dont want to replace. I want to add to the rest of dates from 30 days period, total price = 0.

p.s. I know DATE(created_at) is a bad property name; but i cannot chage. I have problem with DB:RAW sql, i try to change names AS, but doesnt work...

$orders = DB::table('orders')
    ->select(DB::raw('DATE(created_at)'), DB::raw('SUM(billing_totalprice) AS total_price'))
    ->whereBetween('created_at', [$dateFrom, $dateTo])
    ->groupBy(DB::raw('DATE(created_at)'))
    ->get();
Activity icon

Started a new Conversation Forloop, If Logic

I have this collection data.

Illuminate\Support\Collection {#328 ▼
  #items: array:3 [▼
    0 => {#331 ▼
      +"DATE(created_at)": "2020-03-16"
      +"total_price": "186"
    }
    1 => {#330 ▼
      +"DATE(created_at)": "2020-03-18"
      +"total_price": "197"
    }
    2 => {#332 ▼
      +"DATE(created_at)": "2020-04-05"
      +"total_price": "50"
    }
  ]
}

Now i want to loop last 30 days, and if is the dates equal, totalprice is from data above. Else, rest of the dates have totalprice = 0.

Can somebody help me with this for loop logic?


``
$start = Carbon::now()->subDays(30);

for ($i = 0 ; $i <= 30; $i++) {
   if ("startDateFromLoop" = "orders-Date(crated_at)" {
    $collection[] = "Insert" "orders-Date(crated_at)" "with" "orders-totalprice"; 
    }

    else{
    $collection[] = $start->copy()->addDays($i)->format('Y-m-d'); "with" "orders-totalpirce = 0";
     }
}

return $collection;
Activity icon

Started a new Conversation How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

Illuminate\Support\Collection {#328 ▼
  #items: array:3 [▼
    0 => {#331 ▼
      +"DATE(created_at)": "2020-03-16"
      +"total_price": "186"
    }
    1 => {#330 ▼
      +"DATE(created_at)": "2020-03-18"
      +"total_price": "197"
    }
    2 => {#332 ▼
      +"DATE(created_at)": "2020-04-05"
      +"total_price": "50"
    }
  ]
}
Activity icon

Started a new Conversation DB::RAW AS (not)working?

Interesting DB::raw('SUM(billing_totalprice) AS total_price') is working. But, if i want to rename DB::raw('DATE(created_at) AS cday') not???

$orders = DB::table('orders')
    ->select(DB::raw('DATE(created_at)'), DB::raw('SUM(billing_totalprice) AS total_price'))
    ->whereBetween('created_at', [$dateFrom, $dateTo])
    ->groupBy(DB::raw('DATE(created_at)'))
    ->get();
Activity icon

Started a new Conversation How To Insert Values Of Total_price 0 For Last 30 Days If Is Not Created_at?

Illuminate\Support\Collection {#328 ▼
  #items: array:3 [▼
    0 => {#331 ▼
      +"DATE(created_at)": "2020-03-16"
      +"total_price": "186"
    }
    1 => {#330 ▼
      +"DATE(created_at)": "2020-03-18"
      +"total_price": "197"
    }
    2 => {#332 ▼
      +"DATE(created_at)": "2020-04-05"
      +"total_price": "50"
    }
  ]
}
Activity icon

Replied to Last 30 Days...

One of the problem is that column name is DATE(created_at). I try to change AS, but I have error.

Activity icon

Replied to Last 30 Days...

I made last 30 days array, but I dont know next step...

$list = Carbon::now()->subDays(30);
for ($i = 0 ; $i <= 30; $i++) {
    $dates[] = $start->copy()->addDays($i)->format('Y-m-d');
     
}
Activity icon

Replied to Last 30 Days...

Thanks for the suggestion, but I wouldn't know how to do it. I'll try to click something for me. I was wondering if it could be done with the SQL function. I guessed that I should looped on. I've been trying to do some solutions already, but I'm not succeeding.

Apr
05
1 month ago
Activity icon

Replied to Last 30 Days...

Yup, but dont do it what I want :)

Activity icon

Started a new Conversation How To Get Non Created_at Days?

I want array or colection, if I dont have orders certain days to show me totalprice for that day 0 ?

$orders = DB::table('orders')
    ->select(DB::raw('DATE(created_at)'), DB::raw('SUM(billing_totalprice) AS total_price'))
    ->whereBetween('created_at', [$dateFrom, $dateTo])
    ->groupBy(DB::raw('DATE(created_at)'))
    ->get();
Activity icon

Replied to Last 30 Days...

I fixed, I dont have errors, but I dont have result that i want, to show me all 30 days array or collection..

$orders = DB::table('orders')
    ->select(DB::raw('DATE(created_at)'), DB::raw('SUM(billing_totalprice) AS total_price'))
    ->whereBetween('created_at', [$dateFrom, $dateTo])
    ->groupBy(DB::raw('DATE(created_at)'))
    ->get();
Activity icon

Replied to Last 30 Days...

I fixed with )

$orders = DB::table('orders')
    ->select('created_at', DB::raw('SUM(billing_totalprice) AS total_price'))
    ->whereBetween('created_at', [$dateFrom, $dateTo])
    ->groupBy(DB::raw('DATE(created_at)'))
    ->get();

Now I have error: 
SQLSTATE[42000]: Syntax error or access violation: 1055 '.orders.created_at' isn't in GROUP BY (SQL: select `created_at`, SUM(billing_totalprice) AS total_price from `orders` where `created_at` between 2020-03-06 12:08:29 and 2020-04-05 12:08:29 group by DATE(created_at))
Activity icon

Replied to Last 30 Days...

syntax error, unexpected ';', expecting ')'

I try to find where it is, but something is not ok with updated reply

Activity icon

Replied to Charts.js

Yes my demo graph is working, but dont know how to do it :) I post question about orders with last 30days. Maybe that be my answer.

Activity icon

Replied to Last 30 Days...

Nope :( I have this array: I have sum for first 2, beacuse it have same time, anyway I want to show me array of all 30 days, and for the days where I dont hvae order to show me total price: 0.

[
{
"created_at": "2020-03-16 00:00:00",
"total_price": "186"
},
{
"created_at": "2020-03-18 09:07:25",
"total_price": "147"
},
{
"created_at": "2020-03-18 10:00:00",
"total_price": "50"
}
]
Activity icon

Replied to Last 30 Days...

Nope :( both method give me $total = 186 !?! Not array, not collection

Activity icon

Started a new Conversation Last 30 Days...

How to make query that show ALL last 30 days with totalpirce. If i dont have created_at certain date, to show me 0 for that day?

$orders = DB::select('SELECT DATE(created_at) as stat_day, SUM(billing_totalprice) from Orders GROUP BY DATE(created_at) ORDER BY stat_day;');

Activity icon

Started a new Conversation Charts.js

I have $dates array...

[ "2020-03-13", "2020-03-14", "2020-03-15", "2020-03-16", "2020-03-17", "2020-03-18", ]

...and $orders

[ { "stat_day": "2020-03-16", "SUM(billing_totalprice)": "186" }, { "stat_day": "2020-03-18", "SUM(billing_totalprice)": "197" } ]

How to show on x-axis label all $dates, with $orders SUM(billing_totalprice) ONLY for stat_day???

Apr
04
1 month ago
Activity icon

Started a new Conversation Does Laravel Protect SQL Injection When Using Raw SQL?

Is it safe to use raw SQL?

Activity icon

Started a new Conversation Function Pluck Doesn´t Work?

-Call to a member function pluck() on array-

$orders = $orders->pluck('created_at')->all();

Activity icon

Replied to How To Get Only Date From Created_at (datetime)

Ok, this is what i want. Thank you KALEMDZIEVSKI :)

Activity icon

Replied to How To Get Only Date From Created_at (datetime)

Don't ask me :) I've been struggling with this for a month. In the end, I decided to write a raw sql.

Activity icon

Replied to How To Get Only Date From Created_at (datetime)

Yes, I use mysql. The problem is that, I am using raw expression, so I can't enter a $variable. I must do some sql function.

Activity icon

Replied to How To Get Only Date From Created_at (datetime)

This is same method as mine. ´´´ $orders = DB::select('SELECT DATE(created_at) as stat_day, SUM(billing_totalprice) from Orders GROUP BY DATE(created_at) ORDER BY stat_day;');

Activity icon

Started a new Conversation How To Get Only Date From Created_at (datetime)

I need only date from created_at column for DB RAW query:

$orders = DB::select('SELECT created_at as stat_day, SUM(billing_totalprice) from Orders GROUP BY created_at order by stat_day;');

Activity icon

Started a new Conversation Total Per Day?

Can anyone help me how to define the raw expression, to get Sum billing_totaprice per day.

This is my query:

$orders = DB::select('SELECT created_at as stat_day, SUM(billing_totalprice) from Orders GROUP BY created_at order by stat_day;');

Result is:

0 => {#322 ▼ +"stat_day": "2020-03-16 14:44:02" +"SUM(billing_totalprice)": "150" } 1 => {#325 ▼ +"stat_day": "2020-03-18 09:07:25" +"SUM(billing_totalprice)": "147" } 2 => {#326 ▼ +"stat_day": "2020-03-18 10:00:00" +"SUM(billing_totalprice)": "50"

I want for 2020-03-18 Sum billing_totalprice 197(147+50)