J5Dev

Software Engineer at Employed

Experience

34,360

4 Best Reply Awards

  • Member Since 3 Years Ago
  • 717 Lessons Completed
  • 30 Favorites

16th October, 2017

J5Dev left a reply on Auth::user() Returns Unexpected User • 1 week ago

Thank you thank you thank you, I was banging my head against a wall for ages...

I use GUIS's rather than incrementing ID's, and I always forget the damn setting to turn off incrementing ids!

I feel stupid (again), lol.

30th September, 2017

J5Dev left a reply on Accessing Environment Variables Inside A Database Seeder • 3 weeks ago

A good approach to this is to have the variable inside your config, allowing for a default, and use the Environment variables to set/override what is in the config.

That way, you can keep what is configuration, being accessed via the config() helper.

J5Dev left a reply on Picking The Modified Fields In Request Variable In UPDATE • 3 weeks ago

The above will still work for you, simply capture the data from your form (the one with the reason capture), and store it in some kind of approvals table as json.

Though you shouldn't need to play around with permisisons.

Have an admin check for awaiting approvals, it simply pulls the appropriate model, fills it and saves it then.

Something like....

class CreateApprovalsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('approvals', function (Blueprint $table) {
            $table->increments('id');
            $table->string('model_type');
            $table->integer('model_id');
            $table->text('new_model_data'); // json of data user submitted
            $table->string('reason');
            $table->boolean('approved');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('approvals');
    }
}

Once approved, simply have a process which retrieves the model, fills it with the relevant data and saves it, then, just mark the request as approved.

:)

J5Dev left a reply on Picking The Modified Fields In Request Variable In UPDATE • 3 weeks ago

You could do this using a combination of the isDirty/getDirty methods on a model, then check if the fields you need to have justified are within the list, and if so, redirect to your capture form.

You could flash the changed values, and have them as part of the form submission on the next page.

So....

Your model

class Person extends Model {

protected $thingsToJustify ['name', 'email'];

...
Other stuff here
...

public function shouldJustify()
{

    if (! $this->isDirty()) {
        return false;
    }

    foreach ($this->thingsToJustify() as $justify) {
        if (in_array($justify, $this->getDirty()) {
            return true;
        }
    }

    return false;
}

}

Your controller...

class PersonController extends controller {

...
stuff here
...

public function update(Person $person)
{
    ...
    do validation or anything else here
    ...


   $person->fill(request()->all());

    if ($person->shouldJustify()) {
        return redirect('/some-route')->withInput();
    }

    $person->save(); // or whatever else you need to do if nothing needs to be justified

}

}

Then simply have hidden fields on your next page that collect this data, and any other data you want to be captured notes on why it changed etc.

Then post that form, and simply grab the data and save the model, along with the notes or data taken as additional.

J5Dev left a reply on Route::group(['middleware' => ['auth','throttle:20,1']], Function () { • 3 weeks ago

This appliers the defined middleware against each route within the group.

So, each route will only allow 20 requests per minute on that route, it isn't a collective across all routes.

23rd August, 2017

J5Dev left a reply on Model Calculations On Load • 1 month ago

Just to add to what @Swaz has added...

If you want the values to be available when casting the model to an array, or JSON, i.e. when returning through an api, or needing to pass to somethinig like Vue or React, you can also add the property to the Models appends property

eg:

class Product extends Model
{
    protected $appends = ['calculated_price'];

    public function getCalculatedPriceAttribute()
    {
        return $this->price * $this->quantity;
    }
}

J5Dev left a reply on TDD Forum Lesson 29: Vue Component Not Displaying • 1 month ago

Have you ensured that your styling has been built correctly, and cleared your caches?

When changing view files its good to get into the habit of clearing out Laravels cached version of the files... been caught out a few times with that one :)

You can find them in storage>framework>cache

J5Dev left a reply on Code Refactoring • 1 month ago

Glad to see you have solved your blocker, and been able to move on... the tutorials are great for that.

What I would advise is to take a look at the tutorials on testing, especially some of the project based ones (Like the recent Forum series).

Having tests that enforce the behaviour of your application so to speak are your best weapon when it comes to refactoring, and can prevent you from getting stuck, introducing bugs and of course gives you lots of freedom to be able to play with alternative approaches... all whilst maintaining your apps functionality.

22nd August, 2017

J5Dev left a reply on Seeding With Real Data? • 2 months ago

Just wanted to drop onto this one, and offer a little more to the discussion.

I have used migrations for this very purpose as well for some time, and spoke to many people who, for some reason, think its the devils work.

Firstly, it isn't, as some have said its a very valid way to get data into the db as part of a roll out, be it first install or update.

Secondly, the environment is irrelevant, I have seeders across my 3 environments, dev, staging, production. Dev seeders create the usual nonsensical dummy data, which is fine for that level. My staging/UAT environment uses a data set generated from a nightly dump of the live db (with some processing to get it into files), to ensure a better testing experience. Live seeding is explained below...

One thing I have been doing for a while is using a system similar to how the framework tracks migrations.

Any seed data that I need for a production environment is added to files, which are read by the seeders and inserted accordingly. Upon doing so, they add the file information to a table, including last edited dates etc.

This means that should we need to change, add to, or remove anything from our seeded data, it can still be managed by the automated install process (We have db:seed run every time just like migrations).

Put simply, when a seeded runs, it collects the files it needs (hosted outside our version control to ensure data is not in there... obviously not making that rookie error), and checks the files last edited date against that stored in the db, if it hasn't changed, it does nothing, if it has been updated, it clears out the data and adds the new set.

What you have is a nice way to maintain default, or internal running data, as part of your migration workflow.

9th June, 2017

J5Dev left a reply on Required Only If A Checkbox Is Not Checked • 4 months ago

Yes, going for checking for a 1 would remove the ned for having a hidden field, but it also removes the ability to switch the requirement, thats why I mentioned a presumption of having a mechanism which set the hidden field according to some other event/status.

Having some more information would allow me to suggest something that may be better... It could be that neither approach is required, based on how the form is being put together... I noticed the checkboxes are added via js, so, it may better to only add them SHOULD they be needed, then simply set the to sometimes within the Laravel validation.

J5Dev left a reply on It Is Ok To Use LetsEncrypt Free SSL? • 4 months ago

Seconded, if security is your only concern (it should be), then LetsEncrypt is more than adequate.

8th June, 2017

J5Dev left a reply on @foreach Error • 4 months ago

Sorry, I'm now confused... Your original question was about a Bladeloop, which i based my answer on.

If you are wanting to get the data using Angular (noticed the ng-model), then you will have to use that to pull the data via a call, and have it update the dom accordingly.

J5Dev left a reply on It Is Ok To Use LetsEncrypt Free SSL? • 4 months ago

And sadly, that's the end result of good commercial strategies by those who sell the certificates... (and a handful of others involved in the web.. cough Google cough)

Teach the public that only the big nice ones are secure, then companies will have to buy them instead of creating them ;)

Actually had this with a client a few years back, who was insisting on a £1400 Verisign (now Symantec), for his simple internal doc system, as it was definitely going to be more secure than the self-signed one we created!

We argued, showed him the facts, gave up and charged him way over the odds to install it, as it was 'big and complicated' lol, cant teach some people.

J5Dev left a reply on Vue Instance Inside Vue Instance Do Or Do Not? • 4 months ago

I see your point, and yes, if just thrown in, it would get a bit messy.

But then, that's where I would start utilising components.

Basically, have the components hold the logic for getting, handling and displaying the data, and functionality.

That way, a page is only ever doing what it needs, nothing more. And from a visual point of view, having the components out inn separate files makes for a nicer coding experience ;)

Maybe worth checking out one of the @laracast series' covering either Vue itself, or the latest TDD forum example, which covers porting an app over to use Vue... all will give great examples of how to organise things a bit better :)

J5Dev left a reply on Route Parameters Causing Wrong URLs For Static Images And AJAX Requests (L 5.4) • 4 months ago

Glad you got it sorted :)

J5Dev left a reply on View Composer For All Views Except A Single View • 4 months ago

Yes that will work, but this would be a bit cleaner :)

View::composer('*', function ($view) {
    if ($view->getName() != 'partials.not-this-view') {
        $view->with('variable', 'Set variable');
    }
    
});

J5Dev left a reply on MySQL - Comma Separated List Or Another Table For Many To Many Relations? • 4 months ago

You could go down the route of a pivot table, it depends on how often you feel they will be updated.... I'm guessing something like this won't be often, so a column of 'countries' could be fine.

I would however, suggest a json array, rather than a comma separated list, purely as it is easier to pull the countries out as objects, should you need any functionality or additional fields on them.

J5Dev left a reply on It Is Ok To Use LetsEncrypt Free SSL? • 4 months ago

The thing to remember with certificates, is that the security comes from the encryption, not whether it was paid for and supplied.

I could have a self generated certificate that is more secure than one costing thousands, purely because when i create it a do so with a 4096 bit encryption, instead of the current base default of 20148.

What buying a certificate does do ((depending on the level you buy), is provide additional benefits, such as @bashy mentioned around a waranty.

You can also go crazy, and spend thousands onn one, where the supplier will check your companies authenticity, credit status, history etc. In return you get a 'better' representation of your security (full green bars anyone, lol).

Even an expired certificate, in theory, is just as secure as an expired one, as it is still encrypting the request.... (Disclaimer, depending onn how expired and the encryption used to generate it).

So to answer your question, yes LetsEncypt certs are fine for security,m but if you want a visible 'status' of your security, be prepared to splash out a few hundred ££

J5Dev left a reply on Vue Instance Inside Vue Instance Do Or Do Not? • 4 months ago

I don't know about whether it will/wont work, as I haven't done it myself.

If I'm being honest, it does feel a bit like a code smell, in that, yes, multiple instances per page I can kind of get, but most times, just one per page is fine.

Essentially, why have them inside each other, what is the second one (child) allowing you to do that you couldn't do by just adding the functionality you need to the existing instance...?

J5Dev left a reply on Route Parameters Causing Wrong URLs For Static Images And AJAX Requests (L 5.4) • 4 months ago

It would help if we could see how/where you are populating either the variable used for the images src, as well as how you are including it in the template.

J5Dev left a reply on @foreach Error • 4 months ago

Given your example of how you are setting the variable (although a bit JS like), I guess that your variable is actually $copayers[]. If so, your loop should be: @foreach ($copayers as $copayer) Backup for Wallet {{copayer}}: @endforeach

J5Dev left a reply on How Do You Handle Routes When Using SPA? • 4 months ago

It depends on how you are handling your routing within React, what Tykus said is correct.

Essentially, yes you will maybe still on the home page, but React should have appended the url to identify the resource/page that it is current using... so refreshing, although you are technically reloading your index page, once React kicks in it will load in the page indicated in the url... eg /#posts

J5Dev left a reply on Required Only If A Checkbox Is Not Checked • 4 months ago

Firstly, Im presuming you have some mechanism (js?) that allows for the value of the hidden input to be set to 1... otherwise it would always force the inputs to be required, and a simple required would do. That said...

The suggestion by Screenbeetle, whilst good is not correct. Sometimes is used when you need to chain a check to another, for example:

['username' => sometimes|email]

It's like a softer required, in that it doesn't force the key to be in the request, but if it is, it enforces the validation rules against it. Whereas required would fail because its there... essentially, sometimes is an 'its optional' approach.

The better option would be to use one of the required options.... I would say that in this scenario, the most descriptive is either required_without or required_if (one you suggested yourself)... both working the same way.

There are maybe better ways to handle things from both a UI and UX point of view, but would need more info about what is happening around the form :)

24th May, 2017

J5Dev left a reply on Laravel Mix And PhpUnit • 4 months ago

Wow, really nice package @LasseHaslev Short & sweet, exactly how it should be!

Thank you :)

20th April, 2017

J5Dev left a reply on Laravel Relation For Different User Types • 6 months ago

Just as an additional top this, one thing to consider is what if you want to allow users to be both supplier and shop?

What you would be better off doing is actually extracting the concept of a user as a person, away from the concept of what a user can do.

So, for example you may have the following Class'

User (The actual person logging in, and only information related to authentication.) Shopper (Someone purchasing or who can purchase) Supplier (An entity/company that sells things) Order (A base class that holds logic for an order) Purchase extends Order (Holds logic specific to being placed by a Shopper) Sale extends Order (Holds logic specific to being serviced by a Supplier)

Then simply use relationships to manage the application flow, referencing Sale or Purchase respectively.

So...

User would simply house data and logic used for authentication, nothing more. A user could then register but without any constraints on what they can cant do.

Upon making a first purchase, a Shopper record is created, that is associated with a user, but with additional info needed to be able to service their purchase, both by the Supplier and the application. At this point a Purchase (order) is associated with the Shopper.

Lets say that User then wants to sell something, they list an item, at which time a Supplier record is created (and subsequent items etc). If a Shopper then buys their item, the order is created (by the user creating a Purchase), but it is managed as a Sale from the perspective of the Supplier.

Not only does this give a lot more freedom with regards to scaling the application, but it better represents the contextual business language commonly used within eCommerce.

All in all, much better, and all it requires is a couple of relationships, so much simpler!

Hope that helps :)

5th December, 2014

J5Dev left a reply on [L5] Date_default_timezone Error On Clear-compiled • 2 years ago

@winternight Yup, saw it after id posted (always the case!), thanks. Looks like thats all we can do.

J5Dev left a reply on [L5] Date_default_timezone Error On Clear-compiled • 2 years ago

Im having the exact same problem, but only when trying to use a local config, it seems to be overwriting the full config, as opposed to only overwriting the settings that are added.

Edit Your Profile
Update

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