kenny11

Experience

16,070

9 Best Reply Awards

  • Member Since 1 Year Ago
  • 75 Lessons Completed
  • 0 Favorites

30th May, 2018

kenny11 left a reply on Raw Query • 3 weeks ago

anyone?

29th May, 2018

kenny11 started a new conversation Raw Query • 3 weeks ago

I have a polymorphic relation

Class Reply

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

Which has belongs to User and Trainer.

When I show replies I want an authenticated user's reply 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 trainer, 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 inside orderByRaw to check replyable_type is trainer if an auth user is a trainer like this

 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);
        }

But it is not working, how can you convert this to raw query??

I am not so familiar with sql.

29th March, 2018

kenny11 started a new conversation Fuck Browser Inconsistencies • 2 months ago

Fuck Browser inconsistencies

20th March, 2018

kenny11 left a reply on Destroy • 3 months ago

destroy accepts id

use this $product->delete()

kenny11 left a reply on Storing Image File Retrieved From External Url • 3 months ago

congrats

9th March, 2018

kenny11 started a new conversation React With Laravel Non Spa • 3 months ago

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'));
}

30th October, 2017

25th October, 2017

kenny11 left a reply on Pagination • 7 months ago

Are you expecting to get help with that?

22nd October, 2017

kenny11 left a reply on Composite Primary Key - Unique Constraint Failed • 8 months ago

can you post you controller method which throws the error?

20th October, 2017

kenny11 left a reply on Grid Template Compatibility • 8 months ago

Alt Text

kenny11 left a reply on Grid Template Compatibility • 8 months ago

fuck u

kenny11 left a reply on File Upload/edit Form. • 8 months ago

wow you overcomplicated your code. Would you paste the SlugRepo?

18th October, 2017

15th October, 2017

kenny11 left a reply on How To Get Answers To The Questions ? • 8 months ago

Laracast is a full of trolls these days

13th October, 2017

kenny11 left a reply on Show Pages Name • 8 months ago

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?

kenny11 left a reply on Show Pages Name • 8 months ago

Are u serious?

kenny11 left a reply on Show Pages Name • 8 months ago

I got a feeling that you might be the biggest troll on Laracasts

12th October, 2017

kenny11 left a reply on Laravel Transformers • 8 months ago

??

11th October, 2017

kenny11 left a reply on Gitlab And Github • 8 months ago

kenny11 left a reply on Flash Message • 8 months ago

Why don't you just google it?

8th October, 2017

7th October, 2017

kenny11 left a reply on DRY Related • 8 months ago

Keep it simple stupid.use middleware for that

6th October, 2017

kenny11 left a reply on Eloquent API - Resources Doesnt Work Anymore • 8 months ago

Let me format it for you

<?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, ]; } }

4th October, 2017

kenny11 left a reply on Eloquent Nested Child • 8 months ago

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

3rd October, 2017

kenny11 left a reply on Mac Shutdown During Tests. Why? • 8 months ago

Nobody likes a test

1st October, 2017

kenny11 left a reply on Rename Image Name In Src Path • 8 months ago

what you should do is name a file when saving it

30th September, 2017

29th September, 2017

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

tell me that after you try it

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

asset($picture->file_name)

25th September, 2017

kenny11 left a reply on Understanding About Helper. • 8 months ago

Controllers are there for a reason

23rd September, 2017

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

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

What do you mean??

16th September, 2017

kenny11 left a reply on Is 2 Weeks For Learning Laravel Fast? • 9 months ago

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 when u r stuck

kenny11 left a reply on Is 2 Weeks For Learning Laravel Fast? • 9 months ago

No

13th September, 2017

kenny11 left a reply on Vue Interpolation • 9 months ago

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 • 9 months ago

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 • 9 months ago

{{ alert('hello') }}

9th September, 2017

kenny11 left a reply on FatalThrowableError In Grammar.php Line 107 • 9 months ago

lol

1st September, 2017

kenny11 started a new conversation Set Header In Middleware • 9 months ago

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

27th August, 2017

kenny11 left a reply on Some Users Posts Appear Twice • 9 months ago

I hope Jeffrey Way makes an explanation video for this bug

21st August, 2017

kenny11 started a new conversation Bug • 10 months ago

Click on my avatar

kenny11 left a reply on Getting Highest/lowest Value From A OneToMany Relation • 10 months ago

what are u trying to do?

18th August, 2017

kenny11 left a reply on {{ $company->address }}, {{ $company->zipcode }} {{ $company->city }} • 10 months ago

what are you trying to do?

kenny11 left a reply on One Table With Multiple Pivots Tables • 10 months ago

jk paste your migrations

kenny11 left a reply on One Table With Multiple Pivots Tables • 10 months ago

you are missing peace of mind

14th August, 2017

kenny11 left a reply on What Are You Working On ? • 10 months ago

I am still thinking about what to create. I kinda feel like creating an app using apis from some company since 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 • 10 months ago

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

Definitely, Jeff does not pay for it, if you see the ads

30th May, 2017

kenny11 started a new conversation Event Calendar Search • 1 year ago

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.

11th May, 2017

kenny11 started a new conversation How To Validate Date • 1 year ago

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

example 2017-05-12T06:00

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.