CorCronje

CorCronje

Member Since 3 Years Ago

Bloemfontein, South Africa

Experience Points 18,780
Experience Level 4

1,220 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 167
Lessons
Completed
Best Reply Awards 3
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.

17 May
2 months ago

CorCronje started a new conversation Add A Trait To A Class As A Private Variable

Hello there!

I've got a trait that wish to use in an abstract way inside a class, my objective is to use the trait in the following manner,

$this->trait->method();

I've attempted the following, but it does not work as expected,

trait NumberFormatter
{
    function toCurrency($float)
    {
        return number_format($float, 5 , '.', ' ');
    }
}

class Sales {

    use NumberFormatter;

    private $format;

    public function __construct()
    {
        $this->format = NumberFormatter::class;
    }

    public function getSalesAmount()
    {
        return $this->format->toCurrency('123456.3210');
    }
}

Is it possible to do something like this in PHP?

Thanks.

16 May
2 months ago

CorCronje left a reply on Count Distinct Children Within Relationship

Hello,

Your objective is _"count how many distinct keys are in a session"_, thus this should theoretically work, I haven't tested it out.

$count = Session::->whereBetween('end_time', ['2018-05-19 04:42:00', '2019-05-19 04:42:00')
->events->pluck('key')->unique()->count();

Best.

CorCronje left a reply on Count Distinct Children Within Relationship

Hello,

Your objective is _"count how many distinct events.key are in a session"_, thus this should theoretically work, I haven't tested it out.

$count = Session::find([1, 3, 4, 13])->events->pluck('key')->unique()->count();

Best.

CorCronje left a reply on Integrity Constraint Violation: 1052 Column 'id' In Where Clause Is Ambiguous

Hello,

You could spend time to hack that function to possibly work, but it would probably still be a hack and look messy. Why don't you try this instead.

On your Group model, add the inverse of the relation,

public function members() {
    return $this->hasMany('App\User');
}

Then you can easily find the members of multiple groups by passing the groups.id as an array into the model's find() method,

$members = Group::find([1, 3, 9, 35, 8])->members; // non-distict

$unigueMembers = Group::find([1, 3, 9, 35, 8])->members->unique(); //distinct

Just a note, the $members variable will hold a Collection instance and if I'm right, the a user may be listed in the collection multiple times, depending on how many groups the user is a member off. Thus you can use the unique() method on the to get only unique users.

CorCronje left a reply on Laravel + Vue.js: [Vue Warn]: Failed To Mount Component: Template Or Render Function Not Defined.

Hi there!

Have you tried moving these two "require" lines up so that the files are loaded before the "import" statement is called?

require('./components/Navbar.vue').default
require('./components/Customers.vue').default
15 May
2 months ago

CorCronje left a reply on Date Format In Laravel Controller

Awesome! Glad I could assist.

CorCronje left a reply on Date Format In Laravel Controller

Pleasure man!

This line will return a string,

$d = DB::table('student_data')->value('date_of_birth');

Now lets overwrite $d with a Carbon instance from the string $d and reformat it like so,

$d = Carbon::createFromFormat('Y-m-d H:i:s', $d)->format('d/m/Y');

Then you can pass $d to the view/blade as before,

...['mydate' => $d]...

Then in blade you can do,

{{ $mydate }}

CorCronje left a reply on DataTables Error

I had the same issue late last year.

Open your composer.json file and add "yajra/laravel-datatables": "^1.2",

"require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.8.*",
        "laravel/tinker": "^1.0",
        "yajra/laravel-datatables": "^1.2"
    },

Then update composer,

composer update

Regards,

CorCronje left a reply on Date Format In Laravel Controller

@KONRMS - It is a bit difficult to see without the code for retrieving the entity.

Lets work on a cleaner approach. are we still talking about the "student_data" table and is there a StudentData model?

CorCronje left a reply on Date Format In Laravel Controller

Yes, or I completely forgot about about date casting:

You can add this to your StudentData model:

protected $casts = [
    'date_of_birth' => 'datetime:d/m/Y',
];

Casting works with serialization, thus this should work,

$objStudent = StudentData::first(); // get the first row
$arrStudent = $objStudent->toArray(); //serialize to an array
dd($arrStudent['date_of_birth']); //15/05/2019

// can also string it together
$d = StudentData::first()->toArray()['date_of_birth']; //15/05/2019

Anyhow, hope this helps.

CorCronje left a reply on Date Format In Laravel Controller

Hi there,

Please try as per the following:

$d = DB::table('student_data')->first()->date_of_birth //returns a string value via the query builder

$d = App\StudentData::first()->created_at //returns a Carbon instance via Eloquent

$d->format('d/m/Y'); // "12/05/2019"

Then in you blade template you can do somethong like,

{{ $student->date_of_birth->format('d/m/Y') }}

Regards,

CorCronje left a reply on Date Format In Laravel Controller

Hi,

Haven't tested but I think the following code would return a string value,

$d = DB::table('student_data')->value('date_of_birth'); //string

Please try with the line updated to this,

$d = DB::table('student_data')->first()->date_of_birth; //Carbon instance
dd($d->format('dd/mm/Y));

Pls. let me know.

CorCronje left a reply on In Axios Request I Got Has Been Blocked By CORS Policy Error

This CORS thing again! I've tripped over it over it many times.

Checkout this Laracast where Jeffery discuss VueJS and CORS in detail.

Best,

CorCronje left a reply on Date Format In Laravel Controller

I believe when retrieving a datetime value from your DB via Eloquent, the returned property would be a Carbon instance, and thus the following should work.

''' dd($d->format('dd/mm/Y')); '''

Carbon Docs

Best,

CorCronje left a reply on DataTables Sorting & Searching Not Working

Hello there,

I believe there is a missing parameter true when setting the defaults.

Try changing your code as follow:

$.extend(true, $.fn.dataTable.defaults, {
    ordering: true,
    searching:true,
    select: true,
    "order": [[ 0, 'desc' ], [ 1, 'desc' ], [2, 'desc'], [3, 'desc']]
} );

Checkout this package, makes server-side pagination, sorting etc. a breeze!

yajra/laravel-datatables

Best,

CorCronje left a reply on SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'product_id' Cannot Be Null (SQL: Insert Into `category_product`

Hi Irankhosravi,

I encountered a similar issue before, and then realized that I was testing without a valid user login. If there is no user logged in, then auth()->user()->id is null and saving a null value to the DB in a table column with a foreign key or relation would break. At the time I was manually testing by hand, and simply registering a user and logging in, and then navigating to the page I was working on resolved the issue for me. I also fixed the the code by validating that a user was authenticated using a guard or middleware.

Hope this helps,

Best.

11 May
2 months ago

CorCronje started a new conversation Where To Store You JWT Token

Hello there!

I'm consuming a RESTful API using Guzzle and initially do an authentication request to JWT authorization token that is to be included in the header of all subsequent requests.

This token is typically valid for a predetermined period of time, 24 hours in this case, and thus I wish to store the token somewhere and optimally reuse it. I don't want to store it in a DB as this means that have to query the DB each and every time I call the class. Secondly I aiming to find some database / platform agnostic solution that I can apply to all my projects, as I'm consuming various APIs that works in a similar manner.

I am currently storing the token in a ".token" file in the root of my app, and then read the file each time the class is instantiated, but I am a bit concerned for security and performance.

How do you store your API tokens and is there some other efficient solution that I can implement over all my projects?

Thanks!

06 Aug
11 months ago

CorCronje left a reply on Slug

Hello,

make sure your models use the Sluggable and SluggableScopeHelpers trait, then you can do either of the following:

''' $post = Post::whereSlug($slugString)->get();

$post = Post::findBySlug($slugString);

$post = Post::findBySlugOrFail($slugString); '''

And for retrieving the slug:

''' echo $post->slug; '''

CorCronje left a reply on Laravel Mimes Validate Not Fully Working. Pleaes Help

It may be that your OS is hiding the actual file extension, I've seen it happen on Windows when you rename a file the file explorer actually hide the actual file extension so you may end up with "test.asd.jpg" instead of the intended "test.asd".

You can also supliment your validation logic with the mimestype rule ('mimetypes:image/jpeg') for additional confidence that the file under validation is really an image.

CorCronje left a reply on Changing From MySQL To MSSQL

No, certainly not hassle free.

The built in Laravel support for MSSQL works great, and running migrations against MSSQL worked perfectly in my experience. I believe that mostly your raw and custom DB queries may potentially hit errors, as some SQL operators and functions differ between MSSQL and MySQL. If you have stored procedures and views in your DB, that would likely have to be reworked also.

CorCronje left a reply on Laravel Authentication With Microsoft Active Directory

Hello,

Yes, it works great!

A few enterprise apps of mine authenticates using AD, I used a 90 day trail version of Windows Server 2012 to test whilst developing. I installed Windows Server in a local VirtualBox VM on my laptop and then promoted the the freshly installed Windows Server to a domain controller.

I use the Adldap2/Adldap2-Laravel package to bind to AD and Auth against AD.

I also employ AD Security groups in Laravel policies for restricting access to certain resources within the app.

Download Windows Server 2016 here. Its the new 2016 version, but is should work offer the same 90 day trial.

Regards!

CorCronje left a reply on Pagination And Search

It appears you're using JQuery Datatables.

I recommend you use a Laravel package like yajra/laravel-datatables. The documentation is clear and the package easy to implement.

Regards.

16 Jul
1 year ago

CorCronje left a reply on Issue With Mix Install On Centos 6

As @amitbhatia said,

installing build-essential on Ubuntu 8.04 using npm v5.60 and node v8.11.3 resolved the issue for me.

Regards

02 Feb
2 years ago

CorCronje left a reply on Posting XML Data To A Web Service

I haven't personally made use of these, but try one of the Packagist SOAP wrappers for Laravel. The package artisaninweb/laravel-soap looks like a good place to start.

https://packagist.org/packages/artisaninweb/laravel-soap

06 Feb
3 years ago

CorCronje left a reply on Yet Another Mailgun Question. Please Help.

Do each and every email message fail, or is the failure intermittent? It may be that the driver connects to smtp.mailgun.org but does not necessarily mean that it is making an SMTP connection.

Since you've used it previously without issue, and if each and every email message fail, it may be a good idea to go over the mail.php file and check your connection parameters. It may also be possible that your AV or firewall proxy the connection, or that there may be DNS related issue.

You could also try using the IP of the host, as opposed to the FQDN, although I recommend this for testing and faultfinding only.