JohnBraun

JohnBraun

Developer at Enrise

Member Since 2 Years Ago

Netherlands

Experience Points
138,900
Total
Experience

1,100 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
954
Lessons
Completed
Best Reply Awards
68
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 28
138,900 XP
Mar
15
2 weeks ago
Activity icon

Replied to Error With Camel Case Commands - Laracast Generators

I was thinking of submitting a PR, but then found this closed PR (https://github.com/laracasts/Laravel-5-Generators-Extended/pull/107) explaining the SeedMakeCommand will be deprecated soon anyways in favor of Laravel's php artisan make:seeder.

Mar
13
3 weeks ago
Activity icon

Awarded Best Reply on Does Laravel Need CAPTCHA

The CSRF token is not meant to prevent spamming, but from preventing form submissions from other websites (the cross site request forgery). Spambots visiting your website can still submit your form, as the CSRF token is included when they visit your page.

The idea of a CAPTCHA is that spambots can't easily get the answer/value. To block spambots you could and should implement a captcha.

Mar
12
3 weeks ago
Activity icon

Replied to Does Laravel Need CAPTCHA

The CSRF token is not meant to prevent spamming, but from preventing form submissions from other websites (the cross site request forgery). Spambots visiting your website can still submit your form, as the CSRF token is included when they visit your page.

The idea of a CAPTCHA is that spambots can't easily get the answer/value. To block spambots you could and should implement a captcha.

Feb
18
1 month ago
Activity icon

Awarded Best Reply on Tips On Streamlining CSS

Did you have a look at Tailwind CSS yet? This utility first CSS framework allows you to modularly add classes to style elements exactly how you'd like. Also, you can create standard "presets" called components to apply a bunch of classes at the same time.

https://tailwindcss.com

Activity icon

Replied to Trying To Build Web App For Daily Costs For Members In Work And Want Help About The Guidlie

I'm sure that if you'll follow this course here on Laracasts you can get up and running quite fast: https://laracasts.com/series/laravel-6-from-scratch

Just get Laravel running on your machine and experiment a bit. After you're somewhat familiar with the concept of the specifics of anMVC framework, you'll get a better understanding in how to set up your project.

Activity icon

Replied to Trying To Build Web App For Daily Costs For Members In Work And Want Help About The Guidlie

Try to follow along with the videos on Laracasts regarding development with Laravel, and try to build something that just works and implements basic functionality. Afterwards you can refactor/refine/add more features or ask more specific questions regarding your codebase on the forum.

For now, I think the question is a little broad...

Activity icon

Replied to Telescope 405 Method Not Allowed

Could you elaborate on your problem some more?

Did you change anything in the default Telescope serviceprovider?

/**
 * Register any application services.
 *
 * @return void
 */
public function register()
{
    $this->hideSensitiveRequestDetails();

    Telescope::filter(function (IncomingEntry $entry) {
        if ($this->app->isLocal()) {
            return true;
        }

        return $entry->isReportableException() ||
            $entry->isFailedJob() ||
            $entry->isScheduledTask() ||
            $entry->hasMonitoredTag();
    });
}
Activity icon

Replied to Tips On Streamlining CSS

Did you have a look at Tailwind CSS yet? This utility first CSS framework allows you to modularly add classes to style elements exactly how you'd like. Also, you can create standard "presets" called components to apply a bunch of classes at the same time.

https://tailwindcss.com

Activity icon

Replied to Error: Property [kpi_description] Does Not Exist On This Collection Instance

You define a relationship within your AppraisalGoal model that hasMany "appraisalgoaldetails, however you want to fetch a single "appraisalgoaldetail" in the$goal->appraisalgoaldetail->kpi_description` call in your view. That is not going to work.

Did you mean to implement a belongsTo relationship to AppraisalGoalDetail instead, perhaps?

Edit: basically what @sinnbeck says

Feb
17
1 month ago
Activity icon

Replied to Laravel Broadcast - Disconnect Previously Authorized User

Couldn't you listen to an additional event using Echo, redirecting the user (and therefore closing off access to the channel) whenever a RevokeAccess Event is broadcasted or something like that?

Activity icon

Replied to Using Socialite Not Able To Get Linkedin Id

Hi @shawdow

This is what LinkedIn calls a "vanity name" and can be requested using their profile API using the obtained access token. See https://docs.microsoft.com/en-us/linkedin/shared/integrations/people/profile-api?context=linkedin/consumer/context#request

Does this solve your problem?

Activity icon

Replied to Livewire Not Refreshing Data After Wire:Change

Dear @wallyj

I tried to reproduce your problem, using a simple array instead of a model (for simplicity sake), and the code is working as expected on the Livewire side of things. As soon as a task is checked off, it (directly) applies the completed class to the <span> element. Unchecking the task, it removes the class again (also without refreshing the page).

Livewire blade component

<div>
    <ul class="list-group">
        @foreach($this->tasks as $task)
            <li class="list-group-item d-flex-justify-content-between align-items-center">
                <div>
                    <input
                        type="checkbox"
                        wire:click="toggleTask({{ $task['id'] }})"
                        class="mr-4"
                        {{ $task['completed'] ? 'checked' : '' }}
                    >
                    <span class="{{ $task['completed'] ? 'completed' : '' }}">
                        {{ $task['body'] }}
                    </span>
                </div>
            </li>
        @endforeach
    </ul>
</div>

Livewire PHP component

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class Tasks extends Component
{
    public $tasks = [
        ['id' => 1, 'completed' => false, 'body' => 'First task'],
        ['id' => 2, 'completed' => false, 'body' => 'Second task'],
        ['id' => 3, 'completed' => false, 'body' => 'Third task'],
    ];

    public function toggleTask(int $taskId)
    {
        $this->tasks[$taskId - 1]['completed'] = !$this->tasks[$taskId - 1]['completed'];
    }

    public function render()
    {
        return view('livewire.tasks');
    }
}

The strikethrough can be achieved by defining the CSS class:

.completed {
  text-decoration: line-through solid gray;
}
Activity icon

Replied to Passport: Login From External Website

It is definitely possible to use Socialite on one end while using Passport on the other. I wrote a blog about that here: https://johnbraun.blog/posts/oauth2-authentication-across-laravel-projects

Let me know if that has been of any help. Good luck!

Feb
14
1 month ago
Activity icon

Commented on What I Learned About Cypress On Day 2

Thanks for the videos Jeffrey! I would be in favor of your suggestion to create a Cypress series on Laracasts. I hadn't heard of Cypress before, but it seems like a really useful tool.

Dec
30
3 months ago
Activity icon

Replied to Socialite With Twitter And Instagram?

Ah, right. Thanks for the update.

Activity icon

Replied to Socialite With Twitter And Instagram?

Instagram states that it allows (https://developers.facebook.com/docs/instagram-basic-display-api/):

  • Getting an Instagram User Access Token and permissions from an Instagram user
  • Getting an Instagram user’s profile
  • Getting an Instagram user’s images, videos, and albums

However, it might be that they changed their API and you'll need to update the Instagram driver for Socialite.

Dec
29
3 months ago
Activity icon

Awarded Best Reply on Socialite With Twitter And Instagram?

Twitter

Twitter requires you to add a link to your app's privacy policy and terms of service (in the App/Details section at https://developer.twitter.com/en/apps/).

Then, you switch to the Permissions tab and choose edit. From here, you should now be able to check the field "Request email address from users".

After that change, it should all work fine.

Instagram

I don't see any problems if you want to use Instagram. You can register to use their API here (https://www.instagram.com/developer/register/) and there is a driver for Socialite over here: https://socialiteproviders.netlify.com/providers/instagram.html.
Activity icon

Replied to Socialite With Twitter And Instagram?

Twitter

Twitter requires you to add a link to your app's privacy policy and terms of service (in the App/Details section at https://developer.twitter.com/en/apps/).

Then, you switch to the Permissions tab and choose edit. From here, you should now be able to check the field "Request email address from users".

After that change, it should all work fine.

Instagram

I don't see any problems if you want to use Instagram. You can register to use their API here (https://www.instagram.com/developer/register/) and there is a driver for Socialite over here: https://socialiteproviders.netlify.com/providers/instagram.html.
Activity icon

Replied to Too Few Arguments Error In Service Controller

How does the VideoPlayer class look like? Does it accept more than 1 argument in the constructor?

Dec
24
3 months ago
Activity icon

Replied to Json_encode

I mean in your Product(?) model

Activity icon

Replied to Json_encode

Did you override the toArray() method on the model? Do you have a custom getter (getNameAttribute()) ?

Activity icon

Replied to Json_encode

That's weird. I don't see what we're missing here now...

Activity icon

Replied to Json_encode

In that case, you could use $data['product']->toJson() instead of encoding the object yourself. I think it goes wrong when you try to json_encode the paginator object, which first needs to transform itself to an array.

Activity icon

Replied to Json_encode

Allright, so far so good. What if you dump the return value in the toJson() method?

dd(json_encode($this->jsonSerialize(), $options));
Activity icon

Replied to Json_encode

How I would debug this, is by checking what the value of $this->items->toArray() is in the toArray() method of the paginator class (by using the dd() function before the return statement. What does this give you?

Activity icon

Replied to Json_encode

The LengthAwarePaginator class implements the Jsonable interface, as you can see here.

This means that it has a method toJson as you can see below. This in turn makes use of the toArray() method which returns the result as you posted after the json_encode() transformation.

class  LengthAwarePaginator
{
    // other methods...

    /**
     * Get the instance as an array.
     *
     * @return array
     */
    public function toArray()
    {
        return [
            'current_page' => $this->currentPage(),
            'data' => $this->items->toArray(),
            'first_page_url' => $this->url(1),
            'from' => $this->firstItem(),
            'last_page' => $this->lastPage(),
            'last_page_url' => $this->url($this->lastPage()),
            'next_page_url' => $this->nextPageUrl(),
            'path' => $this->path(),
            'per_page' => $this->perPage(),
            'prev_page_url' => $this->previousPageUrl(),
            'to' => $this->lastItem(),
            'total' => $this->total(),
        ];
    }

    /**
     * Convert the object into something JSON serializable.
     *
     * @return array
     */
    public function jsonSerialize()
    {
        return $this->toArray();
    }

    /**
     * Convert the object to its JSON representation.
     *
     * @param  int  $options
     * @return string
     */
    public function toJson($options = 0)
    {
        return json_encode($this->jsonSerialize(), $options);
    }
}
Dec
22
3 months ago
Activity icon

Replied to How To Change Date Format In Dd/mm/yyyy For Database

To solve the error you mention in the code block, you should first create a Carbon object from the 'estimate_shipping' request parameter. You can even define how the 'estimate_shipping' parameter is formatted when it comes in, using the createFromFromat() method.

Carbon::parse(request('estimate_shipping'))->format('d/m/Y');
// or
Carbon::createFromFormat('m-d-Y', request('estimate_shipping'))->format('d/m/Y');
Dec
19
3 months ago
Activity icon

Awarded Best Reply on Laravel 6 Custom Package Development: How To Auto Publish The Package Config File?

@emilmoe I don't think it is diserable to have packages automatically publish their config files either.

@amitshahc You can't automatically publish them, but you can make it easier for users of your package by providing an Installation command which does the trick for you. Then your users may run php artisan your-package:install and it will publish the config files / migrations / etc.

In the handle() method of the command you can use:

/**
 * Execute the console command.
 *
 * @return void
 */
public function handle()
{
  $this->callSilent('vendor:publish', ['--tag' => 'advertisement-config']);
  $this->info('[Your-package-name] was installed successfully.');
}
Activity icon

Awarded Best Reply on Auto Serial Number

Laravel offers a $loop variable which holds information about the foreach loop you're using. It looks like you want to get the current iteration.

@foreach($item as $item)
<tr>
  <td> {{ $loop->iteration }}</td>
  <td> {{ $item->id }}</td>
  <td> {{ $item-> td_item_desc }}</td>
  <td> {{ $item-> td_qty }}</td>
  <td>{{number_format($item->td_unit_price,3)}}</td>
  <td> {{ number_format($item->td_unit_price * $item->td_qty,3) }}</td>
</tr>
@endforeach  

See the documentation to see what else you can do with $loop.

Activity icon

Awarded Best Reply on Disable Auto Exception Handling In A Situation

This is the case because you let Laravel automatically resolve/instantiate the Advertise class via route model binding (due to the Advertise typehint in the function's parameters).

To circumvent the 404, you should resolve the object yourself:

public function show(int $advertiseId)
{
  $advertise = Advertise::find($advertiseId);

  return response($advertise, Response::HTTP_OK);
}
Activity icon

Replied to Route Parameter Validation

The simple and straight forward approach:

public function Afunc($param)
{
  $validParameters = ["A", "B"];

  if (! in_array($param, $validParameters)) {
    // throw an exception / redirect back with a message
  }
  
  // the parameter is in the defined array, so continue...
}

A cleaner approach would be to create a Custom Validation Rule.

Update: I see @tisuchi posted a solution regarding the use of regex to validate the parameter. This could also be a really good solution, but it depends on your situation. If you always expect a certain format of the parameter (for example in the case of a phone number / email address, etc.), go with @tisuchi's solution. If the parameter doesn't have a strict format but needs to be in a predefined set, go with the solution I posted above.

Activity icon

Replied to Get All Data

Sure, don't forget to send them to the view:

public function index()
{
  $emps = Emps::all();
  $users = User::all();
  $salaries = Salary::all();
  $corps = Corp::all();

  return view('admin.dashboard', compact('emps', 'users', 'salaries', 'corps'));
}
Activity icon

Replied to Disable Auto Exception Handling In A Situation

To return a json response, use response()->json($data, $http_status) where $data is the data you want to return and $http_status is a status code.

However, maybe this article will help you: https://medium.com/@DarkGhostHunter/laravel-convert-to-json-all-responses-automatically-c4a72b2fd3ac

Activity icon

Replied to Auto Serial Number

Laravel offers a $loop variable which holds information about the foreach loop you're using. It looks like you want to get the current iteration.

@foreach($item as $item)
<tr>
  <td> {{ $loop->iteration }}</td>
  <td> {{ $item->id }}</td>
  <td> {{ $item-> td_item_desc }}</td>
  <td> {{ $item-> td_qty }}</td>
  <td>{{number_format($item->td_unit_price,3)}}</td>
  <td> {{ number_format($item->td_unit_price * $item->td_qty,3) }}</td>
</tr>
@endforeach  

See the documentation to see what else you can do with $loop.

Activity icon

Replied to Disable Auto Exception Handling In A Situation

I don't completely understand what you're asking here. Could you clarify?

Did you read the documentation regarding json responses? https://laravel.com/docs/6.x/responses#json-responses

Activity icon

Replied to Laravel 6 Custom Package Development: How To Auto Publish The Package Config File?

@emilmoe I don't think it is diserable to have packages automatically publish their config files either.

@amitshahc You can't automatically publish them, but you can make it easier for users of your package by providing an Installation command which does the trick for you. Then your users may run php artisan your-package:install and it will publish the config files / migrations / etc.

In the handle() method of the command you can use:

/**
 * Execute the console command.
 *
 * @return void
 */
public function handle()
{
  $this->callSilent('vendor:publish', ['--tag' => 'advertisement-config']);
  $this->info('[Your-package-name] was installed successfully.');
}
Activity icon

Replied to Disable Auto Exception Handling In A Situation

This is the case because you let Laravel automatically resolve/instantiate the Advertise class via route model binding (due to the Advertise typehint in the function's parameters).

To circumvent the 404, you should resolve the object yourself:

public function show(int $advertiseId)
{
  $advertise = Advertise::find($advertiseId);

  return response($advertise, Response::HTTP_OK);
}
Dec
18
3 months ago
Activity icon

Replied to What Is Queue Connection Name And What Is The Use Of That

Yes, you can use onConnection() to specify which driver should handle the queued job, see https://laravel.com/docs/6.x/queues#customizing-the-queue-and-connection

Activity icon

Awarded Best Reply on What Is Queue Connection Name And What Is The Use Of That

My explanation wasn't quite right, so I updated it. The high and low are queue names indeed which you define using the onQueue() method. You can specify the order in which the queues should be processed by providing a list of queues to the --queue flag of the worker command (in order of high importance first, lowest importance last).

From the documentation:

Sometimes you may wish to prioritize how your queues are processed. For example, in your config/queue.php you may set the default queue for your redis connection to low. However, occasionally you may wish to push a job to a high priority queue like so:

dispatch((new Job)->onQueue('high'));

To start a worker that verifies that all of the high queue jobs are processed before continuing to any jobs on the low queue, pass a comma-delimited list of queue names to the work command:

artisan queue:work --queue=high,low
Activity icon

Replied to What Is Queue Connection Name And What Is The Use Of That

My explanation wasn't quite right, so I updated it. The high and low are queue names indeed which you define using the onQueue() method. You can specify the order in which the queues should be processed by providing a list of queues to the --queue flag of the worker command (in order of high importance first, lowest importance last).

From the documentation:

Sometimes you may wish to prioritize how your queues are processed. For example, in your config/queue.php you may set the default queue for your redis connection to low. However, occasionally you may wish to push a job to a high priority queue like so:

dispatch((new Job)->onQueue('high'));

To start a worker that verifies that all of the high queue jobs are processed before continuing to any jobs on the low queue, pass a comma-delimited list of queue names to the work command:

artisan queue:work --queue=high,low
Activity icon

Replied to Filter GET Requests From Telescope

In Telescope's Service Provider you can enable what should be logged. As you can see, by default every incoming entry is logged when the environment is local. However, you could change that to return $entry->isReportableException() ||$entry->isFailedJob(); instead of return true; for example.

/**
 * Register any application services.
 *
 * @return void
 */
public function register()
{
    $this->hideSensitiveRequestDetails();

    Telescope::filter(function (IncomingEntry $entry) {
        if ($this->app->isLocal()) { // update this statement or remove it entirely
            return true;
        }

        return $entry->isReportableException() ||
            $entry->isFailedJob() ||
            $entry->isScheduledTask() ||
            $entry->hasMonitoredTag();
    });
}
Activity icon

Replied to Difference Between Queue:listen & Queue:work

The difference is that queue:listen will continue to work after altering your code (you don't have to manually restart the worker), while queue:work needs to be restarted before reflecting the changes you made. However, the queue:work command is more efficient than the queue:listen version.

Also, see https://laravel.com/docs/5.8/queues

Activity icon

Replied to What Is Queue Connection Name And What Is The Use Of That

Queue priorities

It only matters when you have a lot of different tasks and a large volume of tasks that can be queued. In those cases, it might be that you want to prioritize a core business task over - let's say - sending a welcome e-mail.

Setting priorities make it easy to allow processing of queued high priority tasks over low priority tasks. For example by running --queue=high,low you will give more priority to queued jobs coming in defined as 'high priority'. Additionally, you might put more workers on the high priority queue.

Dec
17
3 months ago
Activity icon

Awarded Best Reply on Primary Route

Why don't you move the logic to that controller, which checks if the user is authenticated and based upon that, it returns the corresponding view (with additional data).

// Dashboard Controller

public function index()
{
  if (! auth()->check()) {
    return view('login');
  }

  // the rest of the controller logic
  return view('homepage');
}
Activity icon

Replied to Primary Route

Why don't you move the logic to that controller, which checks if the user is authenticated and based upon that, it returns the corresponding view (with additional data).

// Dashboard Controller

public function index()
{
  if (! auth()->check()) {
    return view('login');
  }

  // the rest of the controller logic
  return view('homepage');
}
Activity icon

Replied to Primary Route

Would this do it for you?

Route::get('/', function () {
  return auth()->check() ? view('homepage') : view('login');
});

You can of course also move this logic to a dedicated controller.

Dec
16
3 months ago
Activity icon

Replied to Primary Route

Then just use the Auth middleware, which will redirect to the login page when a user visits the route without being authenticated.

What's the problem in that?

Activity icon

Replied to Primary Route

If you don't want to redirect the user, you can use the @auth blade directive to determine what is shown to each type of visitor.

@guest
  @include('login_form') 
@endguest

@auth
  Content that will be shown to authenticated users. 
@endauth

Alternatively, you could create a a Vue component which determines what to show based on an "authenticated" prop or so.

Dec
12
3 months ago
Activity icon

Awarded Best Reply on Package Commands Registration!

I don't see the advantages of one method over the other. Personally, I always use the first approach you mentioned.