GlenUK

GlenUK

Member Since 9 Months Ago

Experience Points
20,200
Total
Experience

4,800 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
150
Lessons
Completed
Best Reply Awards
6
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 5
20,200 XP
Jul
08
5 days ago
Activity icon

Replied to NPM Install Failing

I ended up switching from Homestead to Laragon.

Thank you for the help though.

Jul
07
6 days ago
Activity icon

Started a new Conversation NPM Install Failing

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/vagrant/code/node_modules/@fullhuman/postcss-purgecss/node_modules/commander/package.json.630663003
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/vagrant/code/node_modules/@fullhuman/postcss-purgecss/node_modules/commander/package.json.630663003'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

I keep getting this error when I run npm install.

I have deleted node_modules folder, packages.json-lock and cleared the npm cache

I am using Homestead.

Jun
14
4 weeks ago
Activity icon

Started a new Conversation Higher Order Functions

return AuditLog::latest()->take(35)->get()->map->readable()->filter(function($item) {
    return $item !== null;
});

How can I make the filter a higher order function in this code?

Activity icon

Started a new Conversation Check For Relationship Between Two Models

>>> $s
=> "App\Store"
>>> $bo
=> "App\BackOffice"

If all I have is this above information, is there anyway to identify if there is a relationship defined between them? The classes will always be extended from eloquent models

May
27
1 month ago
Activity icon

Started a new Conversation Passing Data Between Vue Components

I have a StoreRow.vue file (the parent) which includes the following code:

<template>
...
     <store-text-field
            :store_id="clonedStore.id"
            relation="address"
            field="post_code"
            @value-changed="postCodeUpdated"
            :value="clonedStore.address.post_code"/>
...
</template>

<script>
    export default {
        name: "StoreRow",
        data() {
            return {
                clonedStore: '',
                showStoreNameInput: false,
            }
        },
        props: ['store', 'filterByStoreStatus', 'filterString'],
        created() {
            this.clonedStore = this.store
        },
        methods: {
            postCodeUpdated(value) {
                this.clonedStore.address.post_code = value;
            }
        },

    }
</script>

In the StoreTextField.vue file (the child) I have:

            valueChanged() {
                axios.post('/data/store/' + this.storeID,{
			...
                }).then(response => {
                    console.log(this.store_id + ' updated')
                    this.$emit('value-updated')
                })
            }

Please note, everything is working correctly, except the passing of data back to the parent. I get the following errors from vue:

app.js:22334 [Vue warn]: Invalid handler for event "value-changed": got undefined

found in

---> <StoreTextField> at resources/js/components/StoreTextField.vue
       <StoreRow> at resources/js/components/StoreRow.vue
         <Root>

and

app.js:22334 [Vue warn]: Property or method "PostCodeUpdated" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

found in

---> <StoreRow> at resources/js/components/StoreRow.vue
       <Root>

I am not seeing the mistake I have made. Please can someone point it out to me.

May
26
1 month ago
Activity icon

Replied to Updating SQL Integer Column With NULL

Thank you to you both.

Activity icon

Replied to Updating SQL Integer Column With NULL

@michaloravec

            $update = [$request->input('field') => $request->input('value')];
            return $response = $store->update($update);

So $store->update(['tech_support_id' => 'NULL'])

Activity icon

Replied to Updating SQL Integer Column With NULL

HiediSQL shows a check in 'Allow NULL', so I believe it is.

Activity icon

Started a new Conversation Updating SQL Integer Column With NULL

I am trying to set an integer column to null in mysql. In my migration I created the field as such:

$table->integer('tech_support_id')->nullable();

When I try to update the record with that column and NULL I get this error:

"SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'NULL' for column 'tech_support_id' at row 1 (SQL: update `stores` set `tech_support_id` = NULL, `stores`.`updated_at` = 2020-05-26 19:25:07 where `id` = 1)",

Can anyone offer any insight?

May
17
1 month ago
Activity icon

Replied to Using The Same Policy For Multiple Models?

Thanks for your help. I decided to create each of the policies and link them to the models using their constructors.

I created a public function on the user for each of the abilities and used the same method on all policies:

    public function viewAny(User $user)
    {
        return $user->canViewAnyStoreAndItsRelations();
    }

Now, I can maintain the permissions from the User class. Took a while to set up but should be a breeze to maintain...

Activity icon

Started a new Conversation Using The Same Policy For Multiple Models?

Is it possible to use the same policy for multiple models?

I have a model with 21 relationships, I don't want to maintain 22 policies.

May
07
2 months ago
Activity icon

Replied to How To Determine Product Quantity.

@tehseen

What denominators did you use?

If you are trying to split 83 into pack sizes of 15 and 5 then there will be 3 remaining.

It's then upto you how you want to handle that. if your smallest size is 5 and the customer wants 3.. maybe you tell them you cannot do 3 or maybe you send them 5?

Activity icon

Awarded Best Reply on How To Determine Product Quantity.

You would need to write some logic to do that for you.

To help you get started, you could take an array of your denominators (the quantities you sell), and then, sort them by value if needed and keep subtracting them until you can no longer.

$Stocked_Product_Sizes = [5, 1];
$Customer_Request = 11;
$Result = [];

foreach ($Stocked_Product_Sizes as $Size)
{
    while ($Customer_Request >= $Size)
    {
        $Customer_Request = $Customer_Request - $Size;
        array_push($Result, $Size);
    }
}


// catch any remiander 
if ($Customer_Request > 0)
{
    echo "We could not fulfill " . $Customer_Request . " of this order.";
}
    

var_dump($Result)

This would return:

array(3) {
  [0]=>
  int(5)
  [1]=>
  int(5)
  [2]=>
  int(1)
}

Note, I avoided shorthand as I suspect you will understand it better without it - just know this could be refactored to be cleaner.

Activity icon

Replied to How To Determine Product Quantity.

Setting $Customer_Request to 9 should return:

array(5) {
  [0]=>
  int(5)
  [1]=>
  int(1)
  [2]=>
  int(1)
  [3]=>
  int(1)
  [4]=>
  int(1)
}

It will not return 5 and 4 unless you give it 4 as a denominator (those are stored in the $Stocked_Product_Sizes in my example.

Please can you show me your code.

Activity icon

Replied to How To Determine Product Quantity.

You would need to write some logic to do that for you.

To help you get started, you could take an array of your denominators (the quantities you sell), and then, sort them by value if needed and keep subtracting them until you can no longer.

$Stocked_Product_Sizes = [5, 1];
$Customer_Request = 11;
$Result = [];

foreach ($Stocked_Product_Sizes as $Size)
{
    while ($Customer_Request >= $Size)
    {
        $Customer_Request = $Customer_Request - $Size;
        array_push($Result, $Size);
    }
}


// catch any remiander 
if ($Customer_Request > 0)
{
    echo "We could not fulfill " . $Customer_Request . " of this order.";
}
    

var_dump($Result)

This would return:

array(3) {
  [0]=>
  int(5)
  [1]=>
  int(5)
  [2]=>
  int(1)
}

Note, I avoided shorthand as I suspect you will understand it better without it - just know this could be refactored to be cleaner.

Apr
09
3 months ago
Activity icon

Started a new Conversation .

.

Apr
08
3 months ago
Activity icon

Awarded Best Reply on Vagrant - Deleting Boxes

Deleting the boxes from C:\Users\user\.vagrant.d\boxes seems to have worked.

Activity icon

Replied to Vagrant - Deleting Boxes

Deleting the boxes from C:\Users\user\.vagrant.d\boxes seems to have worked.

Activity icon

Started a new Conversation Vagrant - Deleting Boxes

C:\Users\user\Documents\Code\stores (master -> origin)
λ vagrant box remove --all
Vagrant failed to initialize at a very early stage:

There was an error loading a Vagrantfile. The file being loaded
and the error message are shown below. This is usually caused by
a syntax error.

Path: C:/Users/user/Documents/Code/stores/Vagrantfile
Line number: 0
Message: LoadError: cannot load such file -- C:/Users/user/Documents/Code/stores/vendor/laravel/homestead/scripts/homestead.rb

Hello, I am trying to delete some old boxes. the code no longer exists so vagrant is complaining with the above error. How can I resolve this?

Apr
03
3 months ago
Activity icon

Started a new Conversation Relationship Loading

Hello,

I have a model that has 15 relationships. The model is about 20 fields, and each relationship has just a handful of fields.

I have around 700 records, and loading all these takes around a minute.

I am just passing the model to the view, and accessing the relationships like $model->relationship()->fieldName

I'm really hoping someone can advise on a better way to do this, because 1 minute will be too long - especially when the spreadsheet I am trying to replace takes seconds.

Please help :)

Apr
02
3 months ago
Activity icon

Replied to Create Method On Model Relationship

Ignore me, I haven't saved the parent model...

Activity icon

Started a new Conversation Create Method On Model Relationship

I have a Store and an Address with a one to one relationship.

            $store->address()->create([
                'address_1' => $storeData[50],
                'address_2' => $storeData[51],
                'address_3' => $storeData[52],
                'city' => $storeData[53],
                'county' => $storeData[54],
                'post_code' => $storeData[55],
                'trading_as' => $storeData[56],
            ])

Shouldn't this set the store_id for the newly created address? Currently, It's failing with store_id cannot be null but I thought I was doing it correctly from the docs.

The models:

Store:

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

Address:

public function store()
{
    return $this->belongsTo('App\Store');
}
Mar
26
3 months ago
Activity icon

Replied to Dependancy Injection

I wasn't resolving the class through the container

app(Populator::class)

Thanks for your help.

Activity icon

Replied to Dependancy Injection

It still does not work, I put it into the ASP with:

    public function boot()
    {
        $this->app->bind(Populator::class, function ($app) {
            return new Populator(new SeedData());
        });

    }

But initialising (new Populator) still gives Too few arguments to function error.

Activity icon

Replied to Dependancy Injection

@jlrdw I have this use statement, if that's what you mean:

use App\Helpers\SeedData;

It works if I call it like this: (new Populator(new SeedData)) but I wanted to avoid passing in the parameter.

Activity icon

Started a new Conversation Dependancy Injection

Hello,

I have this class constructor:

    public function __construct(SeedData $seedData)
    {
        $this->techSupportList = $seedData::$TECH_SUPPORT;
    }

I see this from the laravel docs:

There is no need to bind classes into the container if they do not depend on any interfaces. The container does not need to be instructed on how to build these objects, since it can automatically resolve these objects using reflection.

So my understanding is $seedData would be an instance of the SeedData class, but my code complains I have not passed in the parameter. How far off the mark am I with this and what's the correct way to do what I wish to achieve here.

Mar
14
3 months ago
Activity icon

Started a new Conversation Testing Model Relationships

Hello,

I have a test as such:

    public function testStoreIsAssociatedToRelatedModel($class, $method)
    {
        $store = factory(Store::class)->create();
        $store->$method()->associate(factory($class)->create());
        $this->assertInstanceOf($class, $store->$method);
    }

Using a data provider, I pass in the class and a method and expect this to fail if the relationship I have defined on the model is wrong.

Here is one such relationship, on my model:

    public function storeType()
    {
        return $this->belongsTo(StoreStatus::class);
    }

I have made a mistake here and defined the StoreStatus relationship with the ->storeType method, so my test should fail - but it does not.

I checked this in tinker. I span up a model using a factory, associated the model with a StoreType model

 $aStore->storeType()->associate(factory(App\StoreType::class)->create())

I called the ->storeType method - and to my surprise, it returned a StoreType instance. I noted the ID number of the parent model and restarted tinker and called ->storeType again, this time it returned an instance of StoreStatus.

Can anyone explain what is going on here, out of interest?

Mar
11
4 months ago
Activity icon

Replied to Database / Eoquent Testing

I just want to test the whole model and its relationships and the factory does that. The StoreFactory also calls all the other factories via the model's->save() and ->associate() methods so it just seemed like an easy way. I am a beginner though.

I have only really created the database and models, so I don't use the factory anywhere else. I wanted to write some database/model tests before moving on to building the back end system.

Activity icon

Started a new Conversation Database / Eoquent Testing

I've created a model with a dozen or so relationships and a factory that spins up a new model and one of each relationship.

I want to write some tests for this... So far all I have is a checking the factory creates an entry in the database:

    /** @test */
    public function StoreFactoryCreatesADatabaseEntry()
    {
        factory(Store::class)->create();
        $this->assertCount(1, Store::all());
    }

What other tests would be good? Maybe calling each of the relationship methods from the model and asserting an object is returned?

Mar
08
4 months ago
Activity icon

Replied to Factory - Eloquent Realtionships

Looks like I forgot to call the relationship

factory(App\Address::class)->make()->store()->associate($store)
Activity icon

Started a new Conversation Factory - Eloquent Realtionships

Hello,

I have two models:

Store hasOne Address / Address belongsTo store

When I call the Store factory, I want to create a new address and associate it with the Store.

$factory->afterMaking(Store::class, function ($store, Faker $faker) {
    factory(App\Address::class)->make()->associate($store);
});

this code gives me BadMethodCallException with message 'Call to undefined method App/Address::associate() error in tinker. Can anyone help?

Feb
07
5 months ago
Activity icon

Awarded Best Reply on Delete Relationships In Update Method

Via the store method on your controller, delete all the Timesheet items and then assign them from scratch from the HTTP request.

If you need to update the original timesheet items (so they have the same ID in the database, for example) then it's a little trickier. I personally use a helper class, such as this one (by patoui):

https://gist.github.com/patoui/cbd8a6370d8786565f2bb0efdae55867

I then call this from the update method of my controller as such:

(new HasManyUpdater($Timesheet_instance, Timesheet_item::class))->update($request->timesheet_items);

Essentially, it grabs the ID of the existing nested items before it updates each nested items, storing the ID of the updated nested item. It then compares the IDs of the items that existed before the update and the array of IDs that got updated. It then iterates over the IDs that remain and deletes them.

Feb
06
5 months ago
Activity icon

Replied to Delete Relationships In Update Method

Via the store method on your controller, delete all the Timesheet items and then assign them from scratch from the HTTP request.

If you need to update the original timesheet items (so they have the same ID in the database, for example) then it's a little trickier. I personally use a helper class, such as this one (by patoui):

https://gist.github.com/patoui/cbd8a6370d8786565f2bb0efdae55867

I then call this from the update method of my controller as such:

(new HasManyUpdater($Timesheet_instance, Timesheet_item::class))->update($request->timesheet_items);

Essentially, it grabs the ID of the existing nested items before it updates each nested items, storing the ID of the updated nested item. It then compares the IDs of the items that existed before the update and the array of IDs that got updated. It then iterates over the IDs that remain and deletes them.

Activity icon

Replied to Permission Brainstroming

Could you expand on what you are trying to achieve? What is a permission? Is it something you have set up as a many-to-many relation ship? Is it a field within the teams table? etc.

Feb
02
5 months ago
Activity icon

Commented on Prime Factors Kata

How does he get auto-complete on test? When I type that into phpstorm I get some plethora of options (i.e: public function runTest() {...})

Jan
27
5 months ago
Activity icon

Replied to Many To Many - Retrieve Multiple Records Through Pivot Table

What error do you get with the first statement?

Activity icon

Replied to Creating A Back-end And Front-end

When you refer to two different front ends, do you mean two different pages?

Everything you describe here is pretty standard stuff for Laravel and so if you follow the framework conventions you should have no issues.

I recommend you look at the https://laracasts.com/series/laravel-6-from-scratch course

Or, alternatively, this YouTube: https://www.youtube.com/watch?v=eD4yMI-IR8g&list=PLpzy7FIRqpGC8Jk6gyWdSVdxCVXZAsenQ

Jan
13
6 months ago
Activity icon

Replied to Sharing Model With All Views Via ASP Breaks Unit Tests

@tykus Would that be in the AppServiceProvider class?

Activity icon

Replied to Sharing Model With All Views Via ASP Breaks Unit Tests

@tykus

Thank you, is there a better way I should be sharing a model to all views that does not break migrating/unit tests?

Activity icon

Started a new Conversation Sharing Model With All Views Via ASP Breaks Unit Tests

Hello,

Since I added the following to my AppServiceProvider.php class:

    public function boot()
    {
        View::share('statuses', Status::all()); 
    }

All of my unit tests now error out with the following returned from phpunit:

57) Tests\Feature\StaffTest::staffValidationActiveMustBoolean
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table: statuses (SQL: select * from "statuses")

Caused by
PDOException: SQLSTATE[HY000]: General error: 1 no such table: statuses

My tests are using the RefreshDatabase trait and are configured to use sqlite in memory for the testing enviroment via phpunit.xml:

        <server name="DB_CONNECTION" value="sqlite"/>
        <server name="DB_DATABASE" value=":memory:"/>

Is it possible to resolve this without deleting the call the View facade every time?

Activity icon

Replied to Excel Export With Date Format

@bhhuassain

Looking at the error, I believe you are implementing the WithMapping interface

class AccountExport implements WithMapping

If this is the case, you will need to write the method that the WithMapping interface dictates; such as this example from the docs:

{    
    /**
    * @var Invoice $invoice
    */
    public function map($invoice): array
    {
        return [
            $invoice->invoice_number,
            $invoice->user->name,
            Date::dateTimeToExcel($invoice->created_at),
        ];
    }
}

See: https://docs.laravel-excel.com/3.1/exports/mapping.html

If this does not resolve your issue, please repost your entire class with your error.