jonassiewertsen

jonassiewertsen

Member Since 1 Year Ago

Experience Points
46,110
Total
Experience

3,890 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
440
Lessons
Completed
Best Reply Awards
2
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.

Level 10
46,110 XP
Nov
05
1 week ago
Activity icon

Awarded Best Reply on Mock XML Stream

Afterwards, it sounds like a stupid mistake, but it wasn't clear for me in the beginning. So in case, somebody else does run into such a problem, this article will give a great reference. Check it out:

https://freek.dev/1232-handcrafting-mocks

For fetching the stream, I generated a class and did did bind it into the service container. Shown here in a simplified version:

class Stream {
 public static function fetch() {

  self::$shows

  $pathGoesHere = 'fooBar'; // better pass it via the constructor

  StreamParser::xml($pathGoesHere)->each(function(Collection $show) {
            self::$shows->push($show);
        });

        return self::$shows;
 }
}

In this class, I did pass the API URL. In the mocked version, simply add the path to your local file, wherein my case the XML stream is stored.

Via this method, I do have the same input for every test and am not attached to any external API. That's exactly what I need for my tests. :-)

Activity icon

Replied to Mock XML Stream

Afterwards, it sounds like a stupid mistake, but it wasn't clear for me in the beginning. So in case, somebody else does run into such a problem, this article will give a great reference. Check it out:

https://freek.dev/1232-handcrafting-mocks

For fetching the stream, I generated a class and did did bind it into the service container. Shown here in a simplified version:

class Stream {
 public static function fetch() {

  self::$shows

  $pathGoesHere = 'fooBar'; // better pass it via the constructor

  StreamParser::xml($pathGoesHere)->each(function(Collection $show) {
            self::$shows->push($show);
        });

        return self::$shows;
 }
}

In this class, I did pass the API URL. In the mocked version, simply add the path to your local file, wherein my case the XML stream is stored.

Via this method, I do have the same input for every test and am not attached to any external API. That's exactly what I need for my tests. :-)

Nov
04
1 week ago
Activity icon

Replied to Mock XML Stream

You need to bind the XMLStream class, then you can mock it :-)

Activity icon

Replied to Forge: Changed PHP Version And Am Getting Redis Error

I just had the same error yesterday. Setting up a fresh Server with 7.3 did remove the warning, so the update has been the problem in my case. But then you would need to move your application. I don't know if that is an option for you.

As I could read me through, sometimes the error could be resolved with updating all server packages, but not in my case. As well did I test a few things and everything did run smoothly, so it seems that you could ignore the warning as written in another forum which link i forgot. But yeah, it feels wrong to do so ...

If you can and want, move your project to a fresh forge server with php 7.3

Activity icon

Replied to Mock XML Stream

I found this article and that's what I have been looking for. It will make it possible to get always the same input: https://stefanzweifel.io/posts/create-mocks-for-api-clients-in-laravel/

So I moved the function into its own class XMLStream and did write a basic test, to test the mocking:

/** @test */
    public function testing_movies()
    {
        $this->mock(XMLStream::class, function ($mock) {
            $mock->shouldReceive('fetchShows')->once()->andReturn('test response');
        });

        dd((new MovieController)->fetchMovies());
    }

But instead of getting my test response, the API will still be called. The mocking is not taking place. What did i miss?

Nov
03
1 week ago
Activity icon

Replied to Mock XML Stream

That sounds already pretty good. Thanks for the link!

Do you know if there are other common practices out there as well?

Activity icon

Started a new Conversation Mock XML Stream

I want to write a test for processing an XML stream, which will be fetched online.

For my tests, I don't want to fetch the data online every time and want to make sure, to deliver the same input every time.

My Code does look something like that.

public function fetchShows() {
  self::$shows = collect();

  StreamParser::xml(config('stream_url'))->each(function(Collection $show) {
    self::$movies = self::$movies->push($show);
   });

 return self::$movies;  
}

How to mock the stream and make sure, that I will deliver the same stream input for my tests.

Oct
11
1 month ago
Activity icon

Replied to Prevent Duplicate Relationships In Factory.

You could try to use the random Element from Faker.

 randomElement($array = array ('a','b','c')) // 'b'

Maybe something like this?

'tag' => $faker->randomElement(App\Tag::pluck('tag'))
Oct
04
1 month ago
Activity icon

Replied to PHP 7.4 And Preloading Laravel

I heard a PHP talk by Rasmus L. (Creator of PHP), covering as well a few functions about PHP 7.4

He said that there will be performance improvements by preloading the framework, but not that drastically. If i remember correctly, he said something about 10%. (Maybe someone else has a source?) This information is a few month old.

Oct
03
1 month ago
Activity icon

Replied to Global GetAttribute For All Dates Format

To make the production or later changes as easy as possible, i would suggest to stay with the Laravel default, saving all dates as Carbon instance in your Database.

Cast the DB Field as dates:

protected $dates = ['name_of_date_field'];

In your specific Models you can create getters, as written by Talion to get specific formats or output special formats in your views etc.

This is the easiest way, if you want to keep it simple to work with dates later. Calculation hours between them, searching for them etc ... i have been down that road :-D

Activity icon

Replied to How To Push A GIT Branch To A Live Testing Server

You can do it by using a post-receive hook.

Short form:

  1. Create an empty git on your server, via git --init --bare
  2. Create the post receive hook
  3. Add a remote repository on your local machine
  4. Then push to your remote repository (you can select a brach for the hook)

Your will find more detailed informations here: https://gist.github.com/Nilpo/8ed5e44be00d6cf21f22

Activity icon

Replied to Prevent Duplicate Relationships In Factory.

If you are using words for tags, this could be an easy solution:

'tag' => $faker->unique()->word,

From the Faker readme: Faker provides three special providers, unique(), optional(), and valid(), to be called before any provider.

Activity icon

Replied to Validate Datetime

Thanks!

actually i am using the date_format now, because its more explicit. Still, the date validation rule is working as well.

Internally i am using Carbon, but for the api end in this test, i want to test against the most simply errors which could happen :-)

Activity icon

Replied to Validate Datetime

I found the solution. The problem hasn't been in my Model or the validation, but in the Factory instead.

It seems, that i cant overwrite the time fields with a not correct date format (what i wanted to test against for an api)

Instead of doing:

factory('App\Event', )->make(['start' => '20. March 2019 20:30'])->toArray();

you need to overwrite the array, after creating it:

$data = make('App\Event')->toArray();
$data['star'] = '20. March 2019 20:30';

Now the Invalid Argument wont be thrown and the test behaves like it should.

Activity icon

Started a new Conversation Validate Datetime

I want to validate a given input. I am storing the datetime in the standard datetime format.

I am getting an Exception instead of a session error. Does somebody has an idea?

InvalidArgumentException : Unexpected data found.
Unexpected data found.
Data missing

My basic Test

/** @test */
   public function the_start_input_must_be_a_datetime()
   {
       $data = factory('App\Event', )->make(['start' => '20. March 2019 20:30'])->toArray();

   $this->post(route('api.event.store'), $data);
       ->assertSessionHasErrors('start');
   }

My Validation

$validatedData = $request->validate([
            'start'       => 'required|date',
]);

My Model has

 protected $dates = ['start',];
Aug
07
3 months ago
Activity icon

Replied to CircleCI Vs. Travis Ci

Sounds great!

Does anybody knows something about the pricing?

Aug
06
3 months ago
Activity icon

Started a new Conversation CircleCI Vs. Travis Ci

Do you prefer CircelCi or Travis Ci and why?

May
11
6 months ago
Activity icon

Started a new Conversation Download PDF In Laravel Nova Action

I want do generate a pdf in Laravel Nova and download theme. I can't get it working

The code is in an Laravel Nova Action (php artisan nova:action)

public function handle(ActionFields $fields, Collection $models)
{
   $pdf = PDF::loadView('pdf.test');
   
   // This is saving the pdf. So the $pdf->download does work
   // Storage::put('/pdfs/testsave.pdf', $pdf->download('save.pdf')); 

   // NOT Working in the Nova Action
   // return $pdf->download

   // NOVA says to do something like this. 
   return Action::download('url_here', 'file_name.pdf');

    }

Maybe i could save the pdf on the server, pass the path and delete it again?

Any ideas how to get it to work?

In the best possible, i don not need to save the pdf on my server.

Regards, Jonas

May
10
6 months ago
Activity icon

Replied to Duplicate Fields In Migration

Thats exactly how i did it. Thanks!