CorCronje

CorCronje

Devloper, PHP, Laravel, Vue.js at phpweb.co.za

Member Since 4 Years Ago

Bloemfontein, South Africa

Experience Points
23,280
Total
Experience

1,720 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
202
Lessons
Completed
Best Reply Awards
4
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
23,280 XP
May
09
2 weeks ago
Activity icon

Replied to Wanted To Start Lerning Nativejs Using Backend Laravel

I have gone down this path.

  1. The difference between Nativescript and Nativescript-Vue is the latter is Vue.js wrappers for the Typescript UI components, which is compiled down to native Android or IOS UI components. I like Vue.js, but in this case preferred the standard Typescript setup and process. I also found more and concise examples in Typescript as opposed to Nativescript-Vue

  2. If I remember correctly, Axios is not supported, you need to use another HTTP wrapper.

  3. Checkout Jen Looper's blog https://www.nativescript.org/blog/author/jen-looper for some neat and helpful Nativescript-Vue related stuff.

  4. Here's a repo of a simple weather app I made in NS-Vue https://github.com/CorCronje/Yawa

All the best!

Activity icon

Replied to Error In Pagenation

Hi,

You're passing an array $assessment_list to the front-end. A standard array do not have a links() method.

I don't see the need for the foreach loop, why don't you pass the $assessments collection to the front-end instead and then access each attribute by using {{ $value->first_name }}.

Best,

Dec
13
5 months ago
Activity icon

Replied to Video Upload And Show After Uploading

Hi,

You can upload video files like you would any other file. This article explain the process it quite well.

Once you have the file in your storage, you can have the user's browser stream the file, or use the HTML5 video component,, or alternatively wrap a JavaScript video player plugin in a Vue component to stream the video from you app.

best,

Activity icon

Replied to How To Call A Function When Element Is Loaded ?

Hi,

You can call the elementIsLoaded() method from axios' .then() method:

.then(response => {
    this.makeCompetenceLogs(response.data.nextDate); });
    this.elementIsLoaded();
}
Activity icon

Replied to I Want To Response True Or False If Latitude & Longitude Is Available Inside My Radius

Hi,

Have a look at watchers, that way you can watch your latitude and longitude for changes and fire a function or axios call to your backend when your coordinates are within bounds of the radius.

Best,

Activity icon

Replied to How Does Laravel Pass API Keys To External Services?

Hi there, sorry if I don't understand your question.

You can set the base64 encoded token in the authorization header using Guzzle's auth() method when making a request:

http://docs.guzzlephp.org/en/stable/request-options.html#auth

$client->request('GET', '/get', ['auth' => ['username', 'password']]);

On the receiving-end you can inspect the authorization token using Laravel's Illuminate\Http\Request object:

https://laravel.com/api/6.x/Illuminate/Http/Request.html

$token = $request->header('Authorization');

Best,

Dec
12
5 months ago
Activity icon

Awarded Best Reply on Bubbling Up Exceptions

Hi @bigweld86

a ModelNotFoundException will yield a 404 response page. By looking at your code, it appears you're building an API and if I'm right, you're looking for a JSON response to the ModelNotFoundException. In that case you can change your method to something like this:

public function findAttributeById(int $id) {
    $result = $this->model->findOrFail($id);
    if ( ! $result) {
            return response()->toJson([
                'message' => 'Record not found',
            ], 404);
    }
    return $result;
}

Alternatively if your entire app is an API backend, you could change this behavior for your entire app by changing the render method of your app/Exceptions/Handler.php file:

public function render($request, Exception $exception)
    {
        if ($exception instanceof ModelNotFoundException)
        {
            if ($request->ajax())
            {
                return response()->toJson([
                    'message' => 'Record not found',
                ], 404);
            }
        }
        
        return parent::render($request, $exception);
    }
Dec
10
5 months ago
Activity icon

Replied to Bubbling Up Exceptions

Hi @bigweld86

a ModelNotFoundException will yield a 404 response page. By looking at your code, it appears you're building an API and if I'm right, you're looking for a JSON response to the ModelNotFoundException. In that case you can change your method to something like this:

public function findAttributeById(int $id) {
    $result = $this->model->findOrFail($id);
    if ( ! $result) {
            return response()->toJson([
                'message' => 'Record not found',
            ], 404);
    }
    return $result;
}

Alternatively if your entire app is an API backend, you could change this behavior for your entire app by changing the render method of your app/Exceptions/Handler.php file:

public function render($request, Exception $exception)
    {
        if ($exception instanceof ModelNotFoundException)
        {
            if ($request->ajax())
            {
                return response()->toJson([
                    'message' => 'Record not found',
                ], 404);
            }
        }
        
        return parent::render($request, $exception);
    }
Activity icon

Replied to Retrieve Images From Database

Looks as if the "public" directory is missing in the path, could also be an issue with the image's file permissions.

<img src="{{ asset('storage/public/image/'.$post->image_path)}}" alt="image_post" height="250">
Dec
09
5 months ago
Activity icon

Replied to How To Retrieve Image From Storage's Custom Directory.

Okay I see.

composer require intervention/image
// CampaignsController
public function campaignImage(Request $request, Campaign $campaign)
{
    // validate access or authorization logic

    $fileName = $campaign->id . '/image.jpg';
    if(Storage::disk('campaign')->exists($fileName)) {
        return Image::make(Storage::disk('campaign')->get($fileName))->fit(50, 50)->response('png');
    } else {
        return Image::make(Storage::get('/some/generic/image.png'))->fit(50, 50)->response('png');
    }
}

// routes.php
Route::get('/campaigns/{id}/image', '[email protected]')->name('campaign.image');

// blade
@foreach($campaigns as $campaign)
    <div>
        <image src="{{ route('campaign.image', $campaign); }}" class="thumbnail" />
    </div>
@endforeach

Please excuse typo's if any, but I hope you get the general idea.

Just a side note. The public directory is "public" and thus not secure, meaning anyone can access it. You have to proxy the user's access to the image through a controller action or other function in order to validate if the user is authorized to access that image or file.

Activity icon

Replied to How To Retrieve Image From Storage's Custom Directory.

In terms of performance, looping through each image and then outputting or streaming that to the user's browser would certainly have a negative effect.

I'm not sure about your objective, but I would go with ajax to load the images as the user needs it, for example when the user scrolls the page down, more images are loaded via ajax and rendered. Should you instead want for the user to download all the images, I would recommend wrapping the images in a archive, like .tar.gz or .zip and then have the user download that.

Lastly I try and refrain from using for loops as far as possible. Laravel has a cool collection library built in that makes working with arrays a blast, for example.

//make a collection from an array
$images = collect(['image1.jpg', 'image2.jpg', ... ]);

$images->each(function($image) {
    // do something with the image ...
});

Activity icon

Replied to How To Retrieve Image From Storage's Custom Directory.

I think streaming the file or image may be a way to solve this, from inside your controller you can do something like, the Laravel docs have a section file responses.

return response()->file('storage/app/campaign_image/'. $id . '/imageName.jpg');

Another option, if you're working specifically with images, is to use the intervention image library, and then you can do something like:

return Image::make('storage/app/campaign_image/'. $id . '/imageName.jpg')->response('png');