jonassiewertsen

jonassiewertsen

Member Since 1 Year Ago

Experience Points 38,530
Experience Level 8

1,470 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 373
Lessons
Completed
Best Reply Awards 1
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

11 May
1 month ago

jonassiewertsen 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

10 May
1 month ago

jonassiewertsen left a reply on Duplicate Fields In Migration

Thats exactly how i did it. Thanks!

29 Mar
2 months ago

jonassiewertsen started a new conversation Duplicate Fields In Migration

I got a site online on production and now i need to change the database structure.

i do have a column named 'date', with a plain dates like '2019-02-20' and a new added column named 'date_time'.

I want to:

  1. Fetch the value from date
  2. Do something with it to make a datetime out of it (we don't need to worry about that)
  3. write it into the the field date_time

What is the best approach to do so in a migration file?

07 Mar
3 months ago

jonassiewertsen left a reply on Passport Oauth_access_tokens

In the next 1-2 days i will try to reproduce the error on a fresh laravel installation.

It does not make sense to me ... so lets see how it goes with a fresh laravel version.

jonassiewertsen left a reply on Passport Oauth_access_tokens

Request failed with status code 401

jonassiewertsen left a reply on Laravel Passport

Check this out: https://laravel.com/docs/5.8/passport#consuming-your-api-with-javascript

By adding the CreateFreshApiToken middleware to your web middleware group in your app/Http/Kernel.php file, it will do is automaticly.

jonassiewertsen left a reply on Passport Oauth_access_tokens

Hej Techguru

It seems not to work for me. I tried Passport::withoutCookieSerialization(), but the problem stayed the same.

Personal access tokens are now saved in the database, but the problem stays the same on mobile phones only.

Step to reproduce on mobile:

  1. login in
  2. after the session_lifetime expired (for testing i set it to 1)
  3. login in again
  4. Request is unauthorized (even with the old token revoked ...)
06 Mar
3 months ago

jonassiewertsen started a new conversation Passport Oauth_access_tokens

Dear community

I am playing around with Laravel Passport and i got an issue. After an amount of time, i am getting an unauthenticated error back via axios.

I did set my App like this: https://laravel.com/docs/5.8/passport#consuming-your-api-with-javascript

php artisan passport:install -> check! migration of db -> check! CreateFreshApiToken -> check! HasApiTokens added to User model -> check! php artisan passport:install -> check!

Great. It is working, but only after a few hours, even with new login, i am getting an unathenticated error via axios.

Looking into my database, it seems like the cookie has not been stored. Is it correct like that?

The personal access clients are in there, but the oauth_access_tokens are totaly empty. That doesn't make sense to me or did i oversee something?

11 Feb
4 months ago

jonassiewertsen left a reply on Laravel Passport - Iphone Needs To Delete History?

As well the docs are writing:

This Passport middleware will attach a laravel_token cookie to your outgoing responses. This cookie contains an encrypted JWT that Passport will use to authenticate API requests from your JavaScript application. Now, you may make requests to your application's API without explicitly passing an access token:

axios.get('/api/user')
    .then(response => {
        console.log(response.data);
    });

So that is what i am doing :-)

jonassiewertsen left a reply on Laravel Passport - Iphone Needs To Delete History?

From my AuthServiceProvider


public function boot()
    {
        $this->registerPolicies();

        Passport::routes();
        Passport::personalAccessClientId('client-id');
        Passport::tokensExpireIn(now()->addDays(15));
        Passport::refreshTokensExpireIn(now()->addDays(30));
    }

I am using Passport only to consume my own API. So i am working as written in the docs with the web middleware to refresh the token.

'web' => [
    // Other middleware...
    \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
],

As well i am listening to the following events as written in the docs:

/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    'Laravel\Passport\Events\AccessTokenCreated' => [
        'App\Listeners\RevokeOldTokens',
    ],

    'Laravel\Passport\Events\RefreshTokenCreated' => [
        'App\Listeners\PruneOldTokens',
    ],
];

Hmmmm ....

jonassiewertsen started a new conversation Laravel Passport - Iphone Needs To Delete History?

Does anybody had a similar problem with Passport on the Iphone using chrome?

After deleting my history on iphone, it works great again. But of course it is a bad solution to delete the history from time to time to get the authentication working ...

03 Feb
4 months ago

jonassiewertsen started a new conversation Safari Authorization Header

Dear community

I am using the basic api authentication which is working in chrome and locally in safari. On the live server safari is returning unauthenticated, chrome ist still working.

Does anybody knows the problem?

On the local machine the Bearer token is shown in the get request:

Authorization: Bearer XXX

On my server the header hasn't been sent. Does safari this for security reasons? Still, my server runs https ...

31 Jan
4 months ago

jonassiewertsen left a reply on WhereBetween Does Not Exist

@TYKUS - I just commented the test out. Opening the page up in my browser works perfectly, running it on the same machine via phpunit throws the error.

The method is listed in Collection class. Just weird.

Composer update doesn't change anything. I can't figure it out ...

29 Jan
4 months ago

jonassiewertsen left a reply on WhereBetween Does Not Exist

Hmmm ... its weird.

I checked and both versions are the same


Laravel Framework 5.7.24

jonassiewertsen started a new conversation WhereBetween Does Not Exist

Does anybody has a clue, why i'm getting this error?

It is working perfectly, exactly as i want it to on my dev server. Still, PHP Unit is squawking and giving me an error. It just doesn't makes sense ...

BadMethodCallException: Method Illuminate\Database\Eloquent\Collection::whereBetween does not exist.

My Controller looks like:


$bookings = auth()->user()->bookings()->get();

$thisWeek = $bookings->whereBetween('date', [
   now()->format('Y-m-d'), now()->endOfWeek()->format('Y-m-d')
  ]);

$this->withoutExceptionhandling();

$booking = create('App\Booking', [ 'user_id' => $this->user->id, 'date' => now()->format('Y-m-d'), ]);

$this->get(route('dashboard')) ->assertOK() ->assertSee($booking->date);


  Does anybody has a clue?
21 Jan
5 months ago

jonassiewertsen started a new conversation Best Practice For Saving "global Settings"

Dear Community

I am looking for the best way to save "global settings". What i mean: Imagine your project has a superAdmin, to configure some things in the system relevant to all users.

For example that 10 posts will be shown as default per page. Normally i would write it into a config file, but how to do it best, if i want a superAdmin to change it for the whole system via his Admin UI.

Of course i could write it into a database, but that feels wrong, since this settings won´t be changed that often, but will affect nearly every request from each user. Do you know best practices? caching? storing into a file?

I am thrilled to hear you think :-)

13 Jan
5 months ago

jonassiewertsen left a reply on Video Upload | One To Many Relationship

Of course you need to pass it into the method as second argument.

As well you need to pass the business Model or the explicit Business ID to the controller.

Do it fx via your submit form, where the user can select the business or pass the idea via your route.

12 Jan
5 months ago

jonassiewertsen left a reply on Video Upload | One To Many Relationship

@ZIBEN69 - There are many ways, but to keep your code as it is, without refactoring, just pass your business_id into the controller and you are done. Maybe not the cleanest way, but it will work just fine:

public function addVideo(Request $request, $business_id)
{
    // ...
    $video = Video::create([
    'business_id' => $business_id,
    // ...  
}

jonassiewertsen left a reply on My First Big App - Controller Issue

There are some Rules available like 'available_if' or 'available_unless' which can sometimes help out.

https://laravel.com/docs/5.7/validation#available-validation-rules

I think in your case, it's not the solution.

I would recommend to check out custom rules for more complex validation. https://laravel.com/docs/5.7/validation#custom-validation-rules

Otherwise, check out: https://laravel.com/docs/5.7/validation#form-request-validation

I hope it's showing into the right direction.

jonassiewertsen left a reply on How To Auto Select Current Auth

Still it´s not clear what you want. If i should guess, your are trying to get fx posts belonging to the authenticated user. This could work like this.

In your Controller your are writing:

// Make sure the user is logged in. You could use middleware
$posts = auth()->user()->posts();

Your User Controller then should have the posts method / relation:

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

You can find more informations about it here: https://laravel.com/docs/5.7/eloquent-relationships

Are you talking about Nova itself? Then forget what i have written :-) Thats another approach.

jonassiewertsen left a reply on Video Upload | One To Many Relationship

I am not shure if i'm overseeing something, but i would guess that you should change your approach.

If i understood you right, you simply want to add the Video to your database? Thats the problem? Right?

public function addVideo()
    {
    
    // Validation. Of course you can keep your validation in you own validation class
    $video = request()->validate([
        // You should validate your inputs here. It could be something like
        'business_id' => 'required|exists:business,id',
        'filename' => 'VALIDATIONRULES',
        'title' => VALIDATIONRULES',
        'description' => 'VALIDATIONRULES',
        'layout' => 'VALIDATIONRULES',

    ]);

    Video::create($video);

        return redirect()->action('[email protected]');
    }

Thats how i would do it. Of course you can use your approach as well, i just like to use the helper method. You don't need to.

public function addVideo(Request $request)
    {
    // validation !

     Video::create([
                'business_id' => $request...
                // etc
            ]);

        return redirect()->action('[email protected]');
    }

Im not sure if its helping. You named your method AddVideo, so im not assuming that you are saving multiple videos at once. Otherwise i would like to see what you got in $request->videos.

Simply said, i don't know what you want to use the foreach loop for. Save it simple as shown or update me on what we would recieve in the $request->videos attribute :-)

jonassiewertsen left a reply on Test Mail And Number Of Emails Send

Hi

It should be pretty strait forward, though it´s not written in the documentation, but can be found in the laravel API and is part of the MailFake:

https://laravel.com/api/5.7/Illuminate/Support/Testing/Fakes/MailFake.html#method_assertSentTimes

Just use

Mail::assertSentTimes(NewBroadcastMessage::class, 4);

Regards

08 Jan
5 months ago

jonassiewertsen left a reply on Unit Test For Morph Many To Many

@D9705996 - Thanks for the right direction!

Actually i'm asserting for a plain Collection. It's working and looking clean.


$desk = create('App\Desk');

$this->assertInstanceOf(
   'Illuminate\Database\Eloquent\Collection', 
   $desk->categories
);
07 Jan
5 months ago

jonassiewertsen started a new conversation Unit Test For Morph Many To Many

Hej

I am looking for an elegant way for a Unit test.

my database is looking like:

categories
- id 
- name

desks
- id
- name
- something else

categoryable
- categorie_id
- categoryable_id
- categoryable_type

The morph relations itself are working. Now im pulling some arrays from the collections to test via, which seems like a really ugly way of doing it.

$this->assertEquals()

Is there something similar, just for many to many relations?

$this->assertInstanceOf()
22 Sep
9 months ago

jonassiewertsen left a reply on Seeding Data Using Factory And Eloquent Models

Try

 // First remove existing books records
        Book::truncate();

        factory(App\Book::class, 2)->create()->each(function ($book) {
            // Add book rating
            $ratings = factory(App\Rating::class, 1)->create(['book_id' => $book->id]);
        });

As i see it, you are saving twice into the database. Remove, as seen above: ´´´ $book->ratings()->saveMany($ratings); ´´´ and you should be fine.