kenny11

kenny11

Member Since 2 Years Ago

Experience Points 16,170
Experience Level 4

3,830 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 75
Lessons
Completed
Best Reply Awards 9
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

29 May
1 year ago

kenny11 started a new conversation Raw Query

I have a polymorphic relation.

Class Reply

public function replyable()
{
    return $this->morphTo();
}

Which belongs to User and Trainer.

When I fetch replies I want an authenticated user's reply placed first.

So, if an auth user is a trainer, trainer's reply should be first and an auth user is a normal user, user's reply should be first.

This is what I got for now.

public function index(Question $question)
{
        if (!! trainer()) {
            //if an auth user is a trainer, place their posts first in the response data
            return $question->replies()->orderByRaw("FIELD(replyable_id, ".trainer()->id.") DESC")->inRandomOrder()->with('replyable', 'question')->paginate(15);
        }

        if (auth()->check()) {
            //if an auth user is a normal user, place their posts first in the response data
            return $question->replies()->orderByRaw("FIELD(replyable_id, ".auth()->id().") DESC")->inRandomOrder()->with('replyable', 'question')->paginate(15);
        }

        return $question->replies()->with('replyable', 'question')->inRandomOrder()->paginate(15);
}

I need to restraint a query based on replyable_type. So, an auth user is a trainer, replies should be ordered first with a reply which has replyable_type of trainer with replyable_id of whatever the authenticated user (trainer) id is.

This query is not working.

 if (!! trainer()) {
            //if an auth user is a trainer, place their posts first in the response data
            return $question->replies()->orderByRaw("where replyable_type = trainers FIELD(replyable_id, ".trainer()->id.") DESC")->inRandomOrder()->with('replyable', 'question')->paginate(15);
        }
20 Mar
1 year ago

kenny11 left a reply on Destroy

destroy accepts id

use this $product->delete()

09 Mar
1 year ago

kenny11 started a new conversation React With Laravel Non Spa

Has anyone created a non spa web application with React and Laravel?

If the website is not a spa, what is the best way to mount a component in blade files?

Call a component like this?

import React, { Component } from 'react';
import ReactDOM from 'react-dom';

export default class Example extends Component {
    render() {
        return (
            <div className="container">
                <div className="row justify-content-center">
                    <div className="col-md-8">
                        <div className="card card-default">
                            <div className="card-header">Example Component</div>

                            <div className="card-body">
                                I'm an example component!
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}

if (document.getElementById('app')) {
    ReactDOM.render(<Example />, document.getElementById('app'));
}

So if a component is like <Comment/>.

Create a mounting point like this for each component in blade files?

if (document.getElementById('comment')) {
    ReactDOM.render(<Comment/>, document.getElementById('comment'));
}

and in a blade file

<div id="comment"></div>

I wanna know if this is the right way or no. If there is another way please let me know

22 Oct
1 year ago

kenny11 left a reply on Composite Primary Key - Unique Constraint Failed

can you post you controller method which throws the error?

20 Oct
1 year ago

kenny11 left a reply on File Upload/edit Form.

wow you overcomplicated your code. Would you paste the SlugRepo or I should say every repo?

15 Oct
1 year ago

kenny11 left a reply on How To Get Answers To The Questions ?

Laracasts is full of trolls these days

13 Oct
1 year ago

kenny11 left a reply on Show Pages Name

Don't you think it's disrespectful to not read an answer provided by people like @36864 ?

Can you just select his reply as the best answer and end this nonsense? What else do you need?

kenny11 left a reply on Show Pages Name

Are u serious? What's the point asking a question if you don't even read it?

kenny11 left a reply on Show Pages Name

I got a feeling that you might be the biggest troll on Laracasts. You don't even reply to others on the topics you created nor you don't mark a reply that could have solved your problem @davy_yg

12 Oct
1 year ago

kenny11 left a reply on Laravel Transformers

laracasts so dead even unable to use emoji

07 Oct
1 year ago

kenny11 left a reply on DRY Related

Keep it simple stupid.use middleware for that

06 Oct
1 year ago

kenny11 left a reply on Eloquent API - Resources Doesnt Work Anymore

Let me format it for you

public function index() 
{ 
    $data = Post::where('active', '1')->with('category')->with('comments')->paginate(config('toxictoast.pagination.per_page')); 

return BlogPostResource::collection($data); 
}

public function show($id) 
{ 
    $query = Post::find($id); 
     if (!empty($query)) { 
         $data = $query->where('active', '1')->with('category')->with('comments')->get(); 
     } else { $data = collect(); } 
         return BlogPostResource::collection($data); 
     } 
}
<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;

use App\Http\Resources\BlogCommentsResource; use App\Http\Resources\BlogCategoryResource;

class BlogPostResource extends Resource 
{ 
    public function toArray($request) { 
        return [ 
            'id' => $this->id, 
            'title' => $this->title, 
            'slug' => $this->slug, 
            'content' => $this->content, 
            'date' => $this->created_at, 
            'category' => (!empty($this->category)) ? 
                BlogCategoryResource::make(collect()->push($this->category)) 
                : null, 
            'comments' => (!empty($this->comments)) ? 
                BlogCommentsResource::collection(collect()->push($this->comments)) 
                : null, 
         ]; 
      } 
}
04 Oct
1 year ago

kenny11 left a reply on Eloquent Nested Child

Can you explain your relationship and what you are trying to achieve?

03 Oct
1 year ago

kenny11 left a reply on Mac Shutdown During Tests. Why?

Nobody likes a test

01 Oct
1 year ago
29 Sep
1 year ago

kenny11 left a reply on How To Access The Files/images Located At Storage Directory

tell me that after you try it. I hope you made a symlink

kenny11 left a reply on How To Access The Files/images Located At Storage Directory

asset('users/' . $picture->file_name) @d3cypher

25 Sep
1 year ago

kenny11 left a reply on Understanding About Helper.

Controllers are there for a reason

23 Sep
1 year ago

kenny11 left a reply on How To Get All Models That Match Child Model Values?

I need to match more than one and all of them need to be true

What do you mean?? just tell us what kind of data you wanna fetch

16 Sep
1 year ago

kenny11 left a reply on Is 2 Weeks For Learning Laravel Fast?

tbh nobody cares if you can learn laravel in 2 weeks or not

what u can do is learn as much as possible and ask a question here when u r stuck

kenny11 left a reply on Is 2 Weeks For Learning Laravel Fast?

Are you gonna disappear in 2 week or something?

13 Sep
1 year ago

kenny11 left a reply on Vue Interpolation

That's just an example. I don't have control what users would type

https://github.com/vuejs/vue/issues/4223

kenny11 left a reply on Vue Interpolation

I made a middleware to remove curly brackets, but don't know if this is a better way to do this

kenny11 started a new conversation Vue Interpolation

When you have a user content which includes double curly brakets {{ }} in blade files, it will compile it by Vue.

So, what I mean by that is if users' input is like this my input is {{ alert('hello xss vulnabilities') }} it will alert in blade files. If you don't trust me try it, but you need to run npm run production since the command remove a debug tool.

public function index () {
$text = 'hello {{ xss vulnabilities }}';

return view('welcome', compact('text'));

}

// the screen will go blank if your js file is not minified but it will alert when minified
in blade
<h1>{{ $text }}</h1>

Yes we can use v-pre on every tag where you show your users' contents to tell Vue to not compile it but it is very tiring isn't it?

How do you guys go about fixing this?

09 Sep
1 year ago

kenny11 left a reply on FatalThrowableError In Grammar.php Line 107

$uprofile = UserProfile::find('user_id', $user_id);

what's this?? what are u trying to do?

01 Sep
1 year ago

kenny11 started a new conversation Set Header In Middleware

Can anybody explain why this works

public function handle($request, Closure $next)
    {
        $response = $next($request);

        $response->header('x-robots-tag', 'none', false);

        return $response;
    }

but this won't

public function handle($request, Closure $next)
    {

        $next($request)->header('x-robots-tag', 'none', false);

        return $next($request);
    }

Isn't it basically the same thing? the only difference is if you put$next($request) in a variable, but the latter won't set this header x-robots-tag: none

27 Aug
1 year ago

kenny11 left a reply on Some Users Posts Appear Twice

I hope Jeffrey Way makes an explanation video out of this bug

21 Aug
1 year ago

kenny11 started a new conversation Bug

Click on my avatar

18 Aug
2 years ago
14 Aug
2 years ago

kenny11 left a reply on What Are You Working On ?

I am still thinking about what to create. I kinda feel like creating an app using apis from some company since I have never done that.

What's good about knowing how to code with Laravel is you can quickly create pretty much any kind of website

kenny11 left a reply on Ads Make Site Slow

The problem is Disqus. They have started to charge for their comment system.

Definitely, Jeff has not upgraded his subscription, if you see the ads

30 May
2 years ago

kenny11 started a new conversation Event Calendar Search

In my web application, users can post an event. on the index page, I want a calendar which users can click a date and post to my database to search an event that's held on that day and return the events.

Do you guys know any good calendar library for it? It will be a plus if a day shows like a check mark only when there is an event held on the day.

11 May
2 years ago

kenny11 started a new conversation How To Validate Date

How do you validate a date which comes from <input type="datetime-local">?

example 2017-05-12T06:00

08 May
2 years ago

kenny11 left a reply on Where Is The Image Located?

Life must be hard for you

06 May
2 years ago
03 May
2 years ago

kenny11 started a new conversation Building Mobile Apps With Vue.js

Has anyone made a mobile app with Vue.js?

What is your experience using the tools?

I am digging into Weex, so if you have some opinions let me know

02 May
2 years ago

kenny11 left a reply on Controller

rtfm

kenny11 left a reply on Routes

Just use laravel homestead and watch the intro videos

11 Apr
2 years ago

kenny11 left a reply on Stop Spamming.

Are you using Redis? if so store a user_id and like a last_commented_time and compare current time with it and if an hour has not passed, redirect back with a flash message to tell unauthorized

kenny11 left a reply on LARAVEL 5 How To UPDATE One To Many (hasMany) Relation Into DB By Maintain Items ID

if the number of items are fixed.

$items = $product->items;
foreach($request->get('item_name') as $key => $item_name)
    {   
        
        $items[$key]->products_id = $product->id;
        $items[$key]->item_name = $item_name;
        $items[$key]->quantity = $request->quantity[$key];
        $items[$key]->price = $request->price[$key];
        $items[$key]->save();
    };

what about this? and remove this $product->items()->delete();