James_Moore

James_Moore

Software Developer at Flex-N-Gate Corp.

Member Since 3 Years Ago

Windsor

Experience Points
44,060
Total
Experience

940 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
326
Lessons
Completed
Best Reply Awards
12
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 9
44,060 XP
May
27
5 days ago
Activity icon

Replied to How To Display Db Records Twice A Month Only On A Specific Day

What do you mean by displayed ? But it sounds like you'd want to run an artisan command twice a month to accomplish a task https://laravel.com/docs/7.x/scheduling#schedule-frequency-options

Activity icon

Replied to Why Auth::user Return Null?

hey @timwuuk I'm not sure if you made sure to use the laravel auth scaffolding https://laravel.com/docs/7.x/authentication#authentication-quickstart

May
23
1 week ago
Activity icon

Replied to How To Deploy A Laravel/vue Project On Heroku

I once referenced this video to get a Laravel app on heroku https://www.youtube.com/watch?v=639Pe0PpVLQ

To get the vue side working you will have to also include a node build pack to get npm working then do as you do locally on your heroku server.

May
22
1 week ago
Activity icon

Commented on What We're Building

Really looking forward to this !

May
21
1 week ago
Activity icon

Replied to How To Access A Table From Another Table In My Database

Because you dont have a record in database that satisfies the query it seems to be working correctly.

Activity icon

Replied to Laravel Eloquent “with” / “load” Return Null

Can you post your goods table and user table primary and foreign keys.

If your not following laravel conventions you must specify the keys in the belongs to and has many methods.

/**
 * Get the user that owns the phone.
 */
public function user()
{
    return $this->belongsTo('App\User', 'foreign_key', 'other_key');
}
Activity icon

Replied to How To Access A Table From Another Table In My Database

@icelander my code returns a collection of teachers, which you would loop over to call ->slides on, @bugsysha Returns the first teacher of the collection, which $subj->slides would work

Activity icon

Replied to How To Access A Table From Another Table In My Database

Hey @icelander use dd($subj) to see exactly what your getting after that get();

Try adding a with() to it

Teacher::where('class',$class)
->where('subject',$subject)
->with('slides')
->get();

https://stackoverflow.com/questions/26005994/laravel-with-method-versus-load-method

Activity icon

Replied to How Push Form Data To Multiple Models?

Hey @loyd you could perform some curl requests in your register controllers to also call other controllers to also update your profile model. I dont thinkk this is good practise though

I'm not sure if your working with an existing code base or starting a fresh project. But why not have your profiles reflect your user model instead. Add the username to your users migration, and make a controller such as..

<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Validation\Rule;

class ProfilesController extends Controller
{
    public function show(User $user)
    {
        return view('profiles.show', [
            'user' => $user,
            'tweets' => $user
                ->tweets()
                ->withLikes()
                ->paginate(50),
        ]);
    }

    public function edit(User $user)
    {
        $this->authorize('edit', $user);

        return view('profiles.edit', compact('user'));
    }

    public function update(User $user)
    {
        $this->authorize('edit', $user);

        $attributes = request()->validate([
            'username' => [
                'string',
                'required',
                'max:255',
                'alpha_dash',
                Rule::unique('users')->ignore($user),
            ],
            'name' => ['string', 'required', 'max:255'],
            'description' => ['string', 'required', 'max:255'],
            'avatar' => ['image'],
            'email' => [
                'string',
                'required',
                'email',
                'max:255',
                Rule::unique('users')->ignore($user),
            ],
            'password' => [
                'string',
                'required',
                'min:8',
                'max:255',
                'confirmed',
            ],
        ]);

        if (request('avatar')) {
            $attributes['avatar'] = request('avatar')->store('avatars');
        }

        $user->update($attributes);

        return redirect($user->path())->with('flash', 'Success! profile updated');
    }
}

with views,

views/profiles/edit.blade.php
Activity icon

Replied to One URL Is Showing "Access Forbidden"

Hi @asadseeker Try changing the route name to something else "/this-is-a-test" and see if that works. Also look at your HomeController and double check that no middleware or policies are keeping your potentially unauthenticated/unauthorized user from accessing that controller @blog method.

May
19
1 week ago
Activity icon

Replied to Overwrite WithCount Functionality For Relationship

Hey @michaloravec its a many to many relationship,

$user->programs()->withCount('ecs')->with(platform)->orderBy(..)->paginate(10);

so Id have to loop over every program prior to return.

Activity icon

Started a new Conversation Overwrite WithCount Functionality For Relationship

Is it possible to overwrite something on a Model to cause the withCount method to return the count of the relationship, -1.

	Program::withCount('relationship'); // say this returns 5 I want it to return 4. 
May
15
2 weeks ago
Activity icon

Replied to Testing Command That Sends Two Different Notifications To Two Different Users

It turned out I had a bug in my code @drewdan thanks for the reply

Activity icon

Replied to How To Put Custom Composer Package Outside Of Vendor Folder In Laravel?

@dr24 run your terminal as admin then and i think it should be the same .. let me know how it goes

Activity icon

Started a new Conversation Testing Command That Sends Two Different Notifications To Two Different Users

Currently the following test fails, removed a lot of code so its less to read just trying to get the point across.

The expected [App\Notifications\AnotherReActivationNotification] notification was not sent.
   ├ Failed asserting that false is true.

But another test that tests the first notification is sent passes.

    /** @test */
    public function this_is_my_test() {
        Notification::fake();

        $suspendedParticipant = // a user model

        $manager = // users manager

        Artisan::call('the command');

        Notification::assertSentTo($manager, AnotherReActivationNotification::class);
    }

some code from command

        $participants->each(function ($participant) {
            $participant->notify(new ReActivationNotification());

	    $participant->manager->notify(new AnotherReActivationNotification())
        });
Activity icon

Replied to How To Put Custom Composer Package Outside Of Vendor Folder In Laravel?

Hey @dr24 so I would follow this process, my development environment is a windows / homestead box.

  1. Add the following to composer.json below require-dev with your package
-     "repositories": [
        {
            "type": "path",
            "url": "./packages/james-n-m/chuck-norris-jokes",
            "options": {
                "symlink": true
            }
        }
    ],
  1. Put your package in your laravel_app/packages/intervention/zodiac

my personal project example

packages/james-n-m/chuck-norris-jokes
  1. if your running a homestead vagrant box you must run as administrator, make sure your vm is completely off before re-running shell as admin or it will lock. Go as far as checking virutal box to make sure its powered off.

  2. composer require name of package james-n-m/chuck-norris-jokes this will set up the symlink. Symlink just means youll be able to edit from packages/intervention/the-package

  3. "symlinking from" when dependencies added means its working

  4. your composer.json will have the "dev-master" next to the package name. I think your missing the intervention in "url" for repositories.

May
14
2 weeks ago
Activity icon

Replied to Want To Short This, HELP!!

if its returning an array of just one element you could just

$user->rankProvider->pluck('service_income')[0];

I think but their is probably a better way to do this.

Activity icon

Replied to Cannot Pass Data As An Object When Testing GET Request

I'm not sure haha we use it in our tests cause I think we HAVE to because of the size of our application. LOTS of routes

Activity icon

Awarded Best Reply on Cannot Pass Data As An Object When Testing GET Request

Hey @drewdan make sure your test class extends the correct stuff, I think this comes with laravel I dont think ours is custom anyways heres an example from our code base passing using get in a test. The usage of the route() helper function I believe this just allows you to use named routes but it also has the second parameter for passing data.

        $response = $this->get( route('our-route.index', ['role_id' => 1]) );

Make sure you type hint Request in your controller on the receiving end.

    public function index(Request $request)
    {
    }
}

or use the request() helper method to access the data.

post example

$response = $this->post(route('budgets.store', ['budget' => $budget]));
May
13
2 weeks ago
Activity icon

Replied to Cannot Pass Data As An Object When Testing GET Request

Hey @drewdan make sure your test class extends the correct stuff, I think this comes with laravel I dont think ours is custom anyways heres an example from our code base passing using get in a test. The usage of the route() helper function I believe this just allows you to use named routes but it also has the second parameter for passing data.

        $response = $this->get( route('our-route.index', ['role_id' => 1]) );

Make sure you type hint Request in your controller on the receiving end.

    public function index(Request $request)
    {
    }
}

or use the request() helper method to access the data.

post example

$response = $this->post(route('budgets.store', ['budget' => $budget]));
Activity icon

Replied to Tippy.js Seems Not To Work

@alev Great to hear !

Activity icon

Replied to Count A Value

I'm having a little trouble understanding what your trying to ask but, this may be what your after.

https://laravel.com/docs/7.x/eloquent-relationships#counting-related-models

May
12
2 weeks ago
Activity icon

Replied to ???-Best Way To Upgrade A Lumen 5.1 Project To Lumen 7.0

hey @robinhood05 I'm pretty sure the creator of lumen also created this tool https://laravelshift.com/

Activity icon

Replied to Tippy.js Seems Not To Work

hey @alev couple things to try here

https://stackoverflow.com/questions/53402195/how-to-require-tippy-js-in-webpack-3-6

depending what version of Laravel your using you should see some stuff for popper and do the follow that one of the stack overflow users recommends

window.Popper = require('popper.js').default;
window.tippy = require('tippy.js').default;
Activity icon

Awarded Best Reply on Conditionally Loaded Data In API Resource: How To "pass" A Condition?

hey @ahoi this sounds a lot like something one of our developers setup for our API. Hoping this example might help I stripped some stuff i didn't think was necessary to get the point across.

<?php

use App\Http\Resources\JsonResource;

class CountryResource extends JsonResource
{
    public function toArray($request)
    {
        $fields = [
            'id',
            'name',
            'short_name',
            'code',
            'created_on',
        ];

        $relations = [
            'states' => StateResource::collection($this->whenLoaded('states')), // 'states' being the relationship
        ];

        return $this->prepare($fields, $relations);
    }
}
    public function index(Request $request)
    {

        $countries =
            Country::with('states') // this is what triggers the resource to include the states relationship
            ->paginate($request->per_page);

        return  CountryResource::collection($countries);
    }
May
11
3 weeks ago
Activity icon

Replied to Conditionally Loaded Data In API Resource: How To "pass" A Condition?

hey @ahoi this sounds a lot like something one of our developers setup for our API. Hoping this example might help I stripped some stuff i didn't think was necessary to get the point across.

<?php

use App\Http\Resources\JsonResource;

class CountryResource extends JsonResource
{
    public function toArray($request)
    {
        $fields = [
            'id',
            'name',
            'short_name',
            'code',
            'created_on',
        ];

        $relations = [
            'states' => StateResource::collection($this->whenLoaded('states')), // 'states' being the relationship
        ];

        return $this->prepare($fields, $relations);
    }
}
    public function index(Request $request)
    {

        $countries =
            Country::with('states') // this is what triggers the resource to include the states relationship
            ->paginate($request->per_page);

        return  CountryResource::collection($countries);
    }
May
10
3 weeks ago
Activity icon

Replied to Where Are You All From?

Windsor Ontario, Canada 🇨🇦

Activity icon

Replied to Want To Short This, HELP!!

Just add a custom method on your user model that wraps the following code you have here.

Activity icon

Replied to Hands On: Community Contributions | Episode 2 - Display Community Links

hey @soso-_- can you post the code your having trouble with, I'm having a hard time understanding what your problem is exactly. Is the problem that the $links variable your passing from your controller to your view is empty when you feel it shouldn't be. please use the

``` code goes here syntax ```

to post your model code, controller code and view, and even the factory. You may want to directly check your database community_links table if that what you named it to make sure there is data in it.

May
09
3 weeks ago
Activity icon

Commented on Goodbye And Next Steps

Great review of the Laravel Framework thanks !

Activity icon

Replied to Variable Does Not Work In Laravel Components

if your using blade components I believe the syntax is the following. $user would come from your controller in this example

Blade component syntax

<x-follow-button :user="$user"></x-follow-button>

the blade component itself

@unless (current_user()->is($user))
    <form method="POST" action="/profiles/{{ $user->name }}/follow">
        @csrf

        <button type="submit"
                class="bg-blue-500 rounded-full shadow py-2 px-4 text-white text-xs"
        >
            {{ current_user()->following($user) ? 'Unfollow Me' : 'Follow Me' }}
        </button>
    </form>
@endunless
Activity icon

Replied to Variable Does Not Work In Laravel Components

Hey @hjortur17 whats your blade component look like ? You have to pass data to your components or it wont see it

example

<x-follow-button :user="$user"></x-follow-button>

Is it a vue js component ?

Activity icon

Replied to App\Todo::lead Must Return A Relationship Instance, But "null" Was Returned. Was The "return" Keyword Used? (View: C:\xampp\htdocs\crm\resources\views\taskmanagement\cruds\index.blade.php)

Hey @neeraj1005 also specify the the primary key 'ld_id' in your lead relationship.

here is an example from the Laravel documentation. reason being it is looking for primary key 'id' cause thats laravel conventions. and yours is not 'id' also you have a typo

<strong class="mx-4">{{$task->lead->firs_name}}</strong></a 

 * Get the user that owns the phone.
 */
public function user()
{
    return $this->belongsTo('App\User', 'foreign_key', 'other_key');
}
May
08
3 weeks ago
Activity icon

Replied to Vue UI Frameworks... Discord = I Want To Barf

lol I typically just stick to Laracasts for Laravel/Vue help. The Discord groups for programming stuff are usually pretty big and busy. Easy to get lost in all of the constant messaging. Its definitely nice for smaller groups and to meet people to get into smaller groups. Vuetify is a pretty wild component library

May
05
3 weeks ago
Activity icon

Replied to Php Returning Empty Array?

make sure your php server is running as well :)) php -S localhost:8000

Activity icon

Replied to Php Returning Empty Array?

So nothing at all gets printed from the https://www.php.net/manual/en/function.var-dump.php ok cool try doing exactly what I did in my example above and see what happens put everything in one file.

Activity icon

Replied to Php Returning Empty Array?

and this syntax

<?= $key; ?>

is @michaloravec referring to what may need to be turned on

Activity icon

Replied to Php Returning Empty Array?

@pt-83 Hey comment out the html markup

<!-- html goes here -->

and do a

<?php var_dump($person) ?>

to make sure $person is getting passed to the view to begin with

Activity icon

Replied to Php Returning Empty Array?

Hey @pt-83 I did the following just to try and replicate your error.

<?php

$person = [
    'age' => 31,
    'height' => 5,
    'profession' => 'unknown'
];
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <ul>

        <?php foreach ($person as $key => $feature) : ?>

            <li><strong><?= $key; ?></strong> <?= $feature; ?></li>

        <?php endforeach; ?>

    </ul>

</body>
</html>

I put it all in the same file test.php and it worked printing the

  • items. So I believe you may just be using the

    require 'index.view.php'; 
    

    incorrectly, double check that your require 'index.view.php' has the correct path to it, you may need to double check its not a require '../views/index.view.php'; or something I know jeffery will typically put views in their own directory.

    May
    03
    4 weeks ago
    Activity icon

    Awarded Best Reply on Subscribe Button Not Working Returning Function Name Must Be A String

    Hey @iljido I wasnt able to replicate your error but what you have on your component looks correct. I've had issues with the json_encode helper in the past, but if its a show route and your only showing a specific thread not looping over several threads.

    in the controller that supplies the thread variable try this

    Controller

        public function test()
        {
            $thread = new RandomThing();
    
            $isThreadSubscribedTo = $thread->isSubscribedTo;
    
            return view('test', compact('isThreadSubscribedTo'));
        }
    

    Component

    <template>
        <button :class="classes"  @click="subscribe">Subscribe</button>
    </template>
    
    <script>
        import axios from 'axios';
    
        export default {
    
    
            props: ['active'],
    
            computed: {
    
                classes(){
                    return ['btn' , this.active ? 'btn-primary' : 'btn-outline-primary'];
                }
            },
            methods: {
                subscribe(){
                    // axios[(this.active ? 'delete' : 'post')](location.pathname + '/subscriptions');
                    console.log(this.active);
                    this.active = ! this.active;
                }
            }
        }
    </script>
    

    check your console and see what its spitting out, is a boolean value if so this could be a temporary solution till you figure out whats wrong with your json encode syntax I believe json_encode calls typically look like this and it bundles it up the array like a object, key => value

    echo json_encode([
        'status' => 'success',
        'data' => $data,
    ]);
    
    May
    02
    4 weeks ago
    Activity icon

    Awarded Best Reply on Laravel Many To Many Polymorphic Query

    Hey @zizi_ove this seems like the solution your looking for. It shows examples for a 'Laravel-ish' way and a nice simple query builder way.

    https://stackoverflow.com/questions/24555697/check-if-belongstomany-relation-exists-laravel

    The second example of using query builder seems very straight forward. So you would create a route and controller, pass the tag_id and taggable_id as request parameters and then use them in the where clause.

    Activity icon

    Replied to Laravel Many To Many Polymorphic Query

    Hey @zizi_ove this seems like the solution your looking for. It shows examples for a 'Laravel-ish' way and a nice simple query builder way.

    https://stackoverflow.com/questions/24555697/check-if-belongstomany-relation-exists-laravel

    The second example of using query builder seems very straight forward. So you would create a route and controller, pass the tag_id and taggable_id as request parameters and then use them in the where clause.

    Apr
    30
    1 month ago
    Activity icon

    Replied to Subscribe Button Not Working Returning Function Name Must Be A String

    Hey @iljido I wasnt able to replicate your error but what you have on your component looks correct. I've had issues with the json_encode helper in the past, but if its a show route and your only showing a specific thread not looping over several threads.

    in the controller that supplies the thread variable try this

    Controller

        public function test()
        {
            $thread = new RandomThing();
    
            $isThreadSubscribedTo = $thread->isSubscribedTo;
    
            return view('test', compact('isThreadSubscribedTo'));
        }
    

    Component

    <template>
        <button :class="classes"  @click="subscribe">Subscribe</button>
    </template>
    
    <script>
        import axios from 'axios';
    
        export default {
    
    
            props: ['active'],
    
            computed: {
    
                classes(){
                    return ['btn' , this.active ? 'btn-primary' : 'btn-outline-primary'];
                }
            },
            methods: {
                subscribe(){
                    // axios[(this.active ? 'delete' : 'post')](location.pathname + '/subscriptions');
                    console.log(this.active);
                    this.active = ! this.active;
                }
            }
        }
    </script>
    

    check your console and see what its spitting out, is a boolean value if so this could be a temporary solution till you figure out whats wrong with your json encode syntax I believe json_encode calls typically look like this and it bundles it up the array like a object, key => value

    echo json_encode([
        'status' => 'success',
        'data' => $data,
    ]);
    
    Activity icon

    Replied to How To Assign Value Of User_id From Users Table In Cart?

    @hadis Hey Hadis I'm having some trouble understanding from what you've written what your trying to accomplish. What are the names of the table that are involved in this many to many relationship you are you trying to setup.

    Here is a reference from the laravel documentation for many to many relationships in eloquent. https://laravel.com/docs/7.x/eloquent-relationships#many-to-many

    Apr
    27
    1 month ago
    Activity icon

    Replied to I Need Pass Parameter In Axios Post

    Hey @mvnobrega Im not sure if that’s a vue JS helper. Or if your trying to use laravel helpers in your vue JS code. This is not possible, I believe you may be trying to use the route laravel helper with your named laravel route. Just place the whole route in the route parameter of the post request, and look at example code for passing data along with the request for your laravel API to consume.

    Activity icon

    Replied to How To Generate Laravel Standard Report

    Sounds like your going to need to pick a charting library such as Chart.js

    https://www.chartjs.org/

    It would be easier to create generate vue components using a library then have it hit your Laravel api to populate the charts to compare etc.

    Apr
    26
    1 month ago
    Activity icon

    Awarded Best Reply on Laravel Vuetify Setup

    Hey @joewyzn I'm not sure exactly whats causing it without seeing the code and environment setups can be a pain. But here's a friends open source laravel / vuetify setup

    https://github.com/cdterry87/laravel-vuetify

    you can git clone the repo and make it your own, headache and hassle free.

    Apr
    25
    1 month ago
    Activity icon

    Awarded Best Reply on Specify App.url When Using Asset Function

    Hey @th3apprentis it seems that this function is the following

        function asset($path, $secure = null)
        {
            return app('url')->asset($path, $secure);
        }
    

    which grabs the 'url' from the container which i believe comes from app.php

     'url' => env('APP_URL', 'http://localhost'),
    
     'asset_url' => env('ASSET_URL', null),
    

    So it seems like if you modify your .env itll grab it from there :)

    Activity icon

    Replied to Choosing Best Hardware For Development

    I personally dont like my 2017 Macbook Pro. I just feel like it was cheaply made, fans loud as heck. I'm not entirely sure what the newest 2020 models are like aside from being very expensive. If you want a Macbook and your rich go for it, what ever its new its exciting treat yo self. But keep in mine new and exciting will come with a learning curve, how to do this and that, hotkeys are huge lol. I personally just use my windows work laptop because I use it all day at work and then when I come home I just feel slow and sluggish on my Macbook cause I dont remember hotkeys etc.

    Valet is very nice and very quick on the OSX, very simple setup. But if your not creating projects from scratch often.... what ever. I will admit tests do run very very slow on my work machine but we just figured out whats causing that yet.

    Activity icon

    Replied to Laravel Vuetify Setup

    Hey @joewyzn I'm not sure exactly whats causing it without seeing the code and environment setups can be a pain. But here's a friends open source laravel / vuetify setup

    https://github.com/cdterry87/laravel-vuetify

    you can git clone the repo and make it your own, headache and hassle free.