JohnBraun

JohnBraun

Member Since 1 Year Ago

Netherlands

PhD candidate: Organic Chemistry at VU University Amsterdam

Experience Points 109,040
Experience Level 22

960 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 821
Lessons
Completed
Best Reply Awards 43
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.

12 Jul
6 days ago

JohnBraun left a reply on OnDelete Cascade Not Deleting References

@lemmon

When using "bigIncrements", which is the default datatype in the migration stub for the id, I must use "unsignedBigIncrements" for the foreign key reference so the data types match.

You mean unsignedBigInteger (or bigInteger()->unsigned) not increments I suppose.

JohnBraun left a reply on Passing A Laravel Object Conditionally To A Vue Component.

There are two options: 1) performing a check at Vue's end, 2) create a Null object in your controller

In this situation, I would prefer to new up a profile in the controller:


$profile = $user->profile ?? new Profile();

return view('my.view', compact('profile'));
11 Jul
1 week ago

JohnBraun left a reply on Htmlspecialchars() Expects Parameter 1 To Be String, Object Given

Then, marking @tray2 's answer as the 'Best answer' would be the nice move.

JohnBraun left a reply on Find And Replace In Laravel Collection

I didn't have a thorough look at your (rahter complex looking) code, but what I do see is that you have:

  1. an unended where() in the query

  2. you are not saving after updating a value

You can try this code:

foreach ($rslt as $row) {
    // retrieve the first hit
    $getacc = $acc->where('code',$row->code)->first();

    // update one of the column's value
    $getacc->clbal = $row->total;

    // save the entry
    $getacc->save();
}

Alternatively, you can also update a column's value and save at the same time by using the update() method, which would lead to the following code:

foreach ($rslt as $row) {
    // retrieve the first hit
    $getacc = $acc->where('code',$row->code)->first();

    // update+save of the column's value
    $getacc->update(['clbal' => $row->total]);
}

Let me know if it worked for you.

JohnBraun left a reply on Htmlspecialchars() Expects Parameter 1 To Be String, Object Given

// In your controller

$services = DB::table('services')->pluck('id', 'name');

// in your template 

@foreach ($services as $keyService => $service)
    <option value="{{$keyService}}">{{$service}}</option>
@endforeach

Also, see https://laravel.com/docs/5.8/queries#retrieving-results

10 Jul
1 week ago

JohnBraun left a reply on Deploy Error: In PredisConnector.php Line. Class 'Predis\Client' Not Found

I almost dont dare to ask, but did you try `composer dump-autolo yet? (On the server)

JohnBraun left a reply on Deploy Error: In PredisConnector.php Line. Class 'Predis\Client' Not Found

Did you include the predis/predis package locally?

If so, do you see it in your composer.json?

Did you commit your composer.json?

Did you composer install on the server?

If all else fails, run this on your server:

composer require predis/predis

JohnBraun left a reply on How Can I Structure My Database?

@ Did you make any progress in the meantime?

JohnBraun left a reply on Remove Response Header

@movepixels Did you manage to get it to work?

JohnBraun left a reply on Citywise Job Print Dropdown In Laravel

@van1310 did you manage to get it to work?

JohnBraun left a reply on Compile Of Code Change It To Default App.css

@prabin19 Did you manage to get it to work?

JohnBraun left a reply on Best Place In Project To Define Query Scope If There Is No Model?

@djolefjc Did you make any progress in the meantime?

JohnBraun left a reply on Broadcast Event Guard: How Does It Work?

@ideasfera Did you manage to get it to work?

JohnBraun left a reply on Mockery Executing Original Method

You are now mocking the eloquent model, while you should be mocking the payment class. And I think you would even be better of with a Fake instead of a mock.

One option, is to create a PaymentGatewayInterface. This interface can be implemented by a StripePaymentGateway and a FakePaymentGateway.

In the service container you bind the StripePaymentGateway as the concrete implementation of the PaymentGatewayInterface.

So, when your model needs an instance of a PaymentGatewayInterface, it will be resolved (via dependency injection) to your StripePaymentGateway concrete class.

Now, in your tests, you can swap the binding in the service container to use the FakePaymentGateway whenever an instance of the PaymentGatewayInterface is requested.

Im on mobile now, but Ill try to add some code snippets to this reply later.

09 Jul
1 week ago

JohnBraun left a reply on Confused With Laravel's HasOne Eloquent Relationships

If you want to define that the Login model hasOne Data model, the data table should contain a login_id.

The inverse of this relationship defines that the Login model belongsTo a Data model, which requires a data_id on the logins table.

This is also explained in the documentation: https://laravel.com/docs/5.8/eloquent-relationships#one-to-one

JohnBraun left a reply on Calling The Function Of Other Vue Component

You can pass data to child Vue components by passing data as props.

You can update data on the parent Vue component by emitting an event from the child.

Is there a specific example that you would like to see? What do you want to achieve in your particular case?

JohnBraun left a reply on Trying To Get Foraign Key Records Where Every Connected Records Are Deactive ( Laravel Elequent Query )

So, you want to get Categories where all sub_categories should be soft deleted.

You can use:

Categories::doesntHave('sub_categories', function ($query) {
    return $query->whereNull('deleted_at');
})->get();

JohnBraun left a reply on Law Of Demeter.

If you're new to programming, my advice would be to focus on other things first. These "laws" are things you can worry about later. First get things working and slowly improve your code style along with your learning curve.

JohnBraun left a reply on Trying To Get Foraign Key Records Where Every Connected Records Are Deactive ( Laravel Elequent Query )

Categories::whereHas('sub_categories', function ($query) {
    return $query->whereNotNull('deleted_at');
})->get();

JohnBraun left a reply on Ajax Post

Could you check which error message you get from your Chrome/Firefox/... webtools?

Look for XHR requests and look for the message that comes along with the 500 error.

The error happens on the server and I don't think the root of this problem is within the scope of your posted code.

08 Jul
1 week ago

JohnBraun left a reply on Upload File To Disk

The 'url' property is used when you generate a URL for a file you've stored. So, if the APP_URL = http://your-domain.com:

$url = Storage::disk('public')->url('test.txt');

// returns http://your-domain.com/storage/test.txt

Now, if you wanted to store them elsewhere, you need to adjust the way the URL is generated.

07 Jul
1 week ago

JohnBraun left a reply on Calendar - Scheduler

Are you building a system in which a user can book predefined slots or do you need something like Google Calendar?

06 Jul
1 week ago

JohnBraun left a reply on Process.env.MIX_<variable> Not Working

And you are using Webpack to compile the javascript assets?

JohnBraun left a reply on What's The Difference Between Running Commands From Ssh And Without

I think the question you're asking is: "Where should I run the commands, in the virtual box or on the main OS command line".

The idea of running Homestead is that you have a development environment available which always works the same way, regardless of the operating system you are working on. Therefore, it is best that you do everything within Vagrant, since it comes with a handy set of pre-installed dependencies.

On your question related to the failing npm run dev command:

I see that there is an error that tells you:sh: 1: cross-env: not found. I think that might be due to not having run npm install previously. Is that correct? If so, try running npm install first and then npm run dev.

JohnBraun left a reply on Dynamic Custom Fields: JSON, Pivot, MorphToMany?

I think this package by Spatie might set you quickly on the right track! ?

https://github.com/spatie/laravel-schemaless-attributes

JohnBraun left a reply on Calendar - Scheduler

Is there somthing in particular that you need some help with?

JohnBraun left a reply on Route To Auth\[email protected] Not Working

In LoginController, I just dd and the action is not called because the output is always the one of the /home route.

That seems strange, since the request types are different. Your home route is defined as get request, your 'custom login' route as a post request.

  • Are you sure you're makeing a post request to the correct endpoint?
  • Did you import the Iluminate\Http\Request class in your LoginController?

I tried it out, and for me the following setup just works:

// routes/web.php:

Route::get('/', 'Auth\[email protected]');

// LoginController.php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    use AuthenticatesUsers;

    protected $redirectTo = '/home';

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function index(Request $request)
    {
        return 'hello';
    }
}
04 Jul
2 weeks ago

JohnBraun left a reply on Broadcast Event Guard: How Does It Work?

Allright, first make sure you've uncommented the BroadcastServiceProvider in your app/config.php file.

Then, make sure your Event implements the ShouldBroadcast interface.

class MyEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function __construct(Planner $planner)
    {
        $this->planner= $planner;
    }

    public function broadcastOn()
    {
        return new PrivateChannel(
          "planner.{$this->planner->id}"
        );
    }
}

Now you should setup a rule to listen to your 'planner' channel. For example: the 'Planner' user id should be equal to the currently authenticated user.

Broadcast::channel('planner.{id}', function ($user, $id) {
  return $user->id === Planner::find($id)->user_id;
});

Then, you can listen for the event in (e.g.) your Vue component:

created() {
            window.Echo.private(`videos.${this.video.id}`)
                .listen("VideoWasProcessed", (e) => {
                    this.processing = false;
            });
},

JohnBraun left a reply on Best Place In Project To Define Query Scope If There Is No Model?

I assume you are applying your search filter to certain Models, right?

Then, you could make a trait:

<?php 

trait Searchable
{
    public function scopeFilterOne($query, $parameter)
    {
        return $query->where('filter', $paramter);
    }

    public function scopeFilterTwo($query)
    {
        // ...etc
    }
}

Next, on certain models you want to apply this filter to:

<?php

class Item extends Model
{
    use Searchable;

    // ....
}

And in your controller:

<?php

namespace App\Http\Controllers;

public function search() 
{

    // perform your query scope
   $items = Item::filterOne($parameter)->filterTwo()->get();
}
03 Jul
2 weeks ago

JohnBraun left a reply on Process.env.MIX_<variable> Not Working

And you did compile your assets with webpack? (i.e. npm run dev / npm run prod)

JohnBraun left a reply on Disable All Textarea In Loop While Commenting On A Post In Vuejs

The code you've provided looks incomplete. Could you also please format the code?

There is this guide by @mstnorris showing how to ask your question in an accessible way: https://laracasts.com/discuss/channels/general-discussion/guidelines-for-posting-on-laracastscom

02 Jul
2 weeks ago

JohnBraun left a reply on Queuing File Transformation After File Upload

@HUNTERHAWLEY - Allright, good luck! If you have any questions don't hesitate to ask them on the forum. Thanks for your nice words regarding my weblog :-)

JohnBraun left a reply on Laravel Ignoring Testing Database And Uses Main One Instead

@R123 - Please look more careful, I am suggesting you use an sqlite connection. If you want to go with the testing database, look at the suggestion by @diegoaurino

JohnBraun left a reply on Queuing File Transformation After File Upload

I dont know if the approach Im going to describe is the best, but this is how I would do it in your situation.

When a user uploads multiple videos, loop over them and store them in a unprocessed-videos database and assign an upload_uuid, to easily get all videos that belong together. This table should also store the file path and a user_id.

Then, you can either pass all these videos as an Iluminate collection to the Job class or just pass the uuid and let the job collect all videos from the unprocessed videos table.

When the job is finished, you can fire an event (or hook into Laravels own event when a job is finished) and make a listener which (for example) sends an e-mail to the user to inform them that their videos were processed.

Does this help you to get started?

JohnBraun left a reply on Laravel Ignoring Testing Database And Uses Main One Instead

<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
01 Jul
2 weeks ago

JohnBraun left a reply on What To Do With Entries Created By Tests?

The trick is to use the RefreshDatabase trait, but use a different database for your tests. You can specify that in your phpunit.xml file. For example, if you want to use an in-memory SQLite database you add:

<server name=“DB_CONNECTION” value=“sqlite” />

<server name=“DB_DATABASE” value=“:memory:” />

JohnBraun left a reply on Help With Querys

If you want to use Eloquent, make a Video model and a migration.

Then you can use the query builder as described in the documentation

https://laravel.com/docs/5.8/eloquent

JohnBraun left a reply on Queuing File Transformation After File Upload

I am not sure if you are asking for a general flow, or for a practical code example.

I guess, the general flow could be:

In your controller:

  • Accept the request
  • Store every uploaded video on your server
  • Pass the uploaded files to a job, e.g. ProcessVideos($videos)

In your job:

  • Make the job implement ShouldQueue
  • Handle all logic for processing the videos
  • [optional] Fire an event that the processing was succesful

In your environment file:

  • Set the appropriate queue driver (e.g. redis), making sure that you've installed the required driver

Optionally, you could also listen for that VideoProcessingSucces event and broadcast that back to that user, let me know if you want more info on that as well.

JohnBraun left a reply on Compile Of Code Change It To Default App.css

I guess you're editing your public/css/app.css file, while you should be editing resources/sass/app.scss.

The npm run dev / npm run prod / npm run watch scripts will convert the sass file to the actual app.css file, overriding the currently existing public/css/app.css file.

JohnBraun left a reply on Test Case Can't Open File In Public Directory?

Have you looked at the Laravel public_path() helper, yet?

return fopen(public_path('courses.csv'), 'r');

More info: https://laravel.com/docs/5.8/helpers#method-public-path