jeffreyvanrossum

jeffreyvanrossum

PHP developer at vanrossum.dev

Member Since 3 Years Ago

Bennekom

Experience Points
23,470
Total
Experience

1,530 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
192
Lessons
Completed
Best Reply Awards
6
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,470 XP
Mar
30
14 hours ago
Activity icon

Replied to Select All Records Where Due_date = Tomorrow

@elanorriley now returns an instance of Carbon. :-)

If I'm not mistaken, with whereDate, the time is omitted. So the example I provided earlier should work.

Activity icon

Replied to Select All Records Where Due_date = Tomorrow

I think you can use the whereDate method, or you'll have to specificy the date format on the tomorrow method.

Example:

Task::whereDate('due_date', '=', \Carbon\Carbon::tomorrow())->get();
Activity icon

Replied to BelongsToMany

Easiest way I think, is to set the role upon user creation. If you are using Laravel's authentication, you could add that part to the store method in your RegisterController.

For example:

protected function create(array $data)
{
    $user = User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
    ]);

    // Assign user to role
    $user->roles()->sync(Role::where('name', 'user')->first());
}
Mar
25
5 days ago
Activity icon

Awarded Best Reply on Change Request Via Trait In Model

The error refers to, if I'm not mistaken, to the column main_image not existing on your database table.

Mar
24
6 days ago
Activity icon

Replied to Hi, Which Best Way To Save Product Colors In Migration Table Or The Database With Laravel Please

What is it that you would want to do with the colors? Can you give a use case?

Activity icon

Replied to Localization Blade Directive Not Working Next To Numbers.

I don't find that weird to be honest with you. Since you're typing directly against the directive, the directive name is no longer recognized. You've provided a couple of alternatives that make more sense to use in this scenario.

Activity icon

Replied to Change Request Via Trait In Model

The error refers to, if I'm not mistaken, to the column main_image not existing on your database table.

Activity icon

Replied to Great Hosting For Laravel

I use DigitalOcean myself. For setup and deployment I'm using Laravel Forge. No complaints as of yet.

Activity icon

Replied to Countries Package For Laravel 7.3

You're not the only one running into this issue: https://github.com/antonioribeiro/countries/issues/144

Appears to be an issue with the ia-arr package.

While there is no update for the package, you could fork the repository and try and fix it yourself. You could also check if there are any recent forks that fix the issue and fork or reference that repository in your composer.json.

Mar
16
2 weeks ago
Activity icon

Awarded Best Reply on How Signed Routes Works In Laravel?

It isn't extracted from the hash. When the URL signature is validated it will look to see if the URL has been modified. This includes the expires-parameter.

This is an example of a signed URL:

http://sandbox.test/unsubscribe?expires=1584372721&signature=917ac911f04a7172c01329408cfe8008fb7d1b8b22d6a3fe43b672b65ecfc77d

If you modify the value the URL, it will no longer match the signature. Therefore, it is safe to for Laravel to use the expires parameter to see if the URL is expired.

Signed URLs in the documentation

Laravel source code

Quick video explaining how it works

Activity icon

Replied to How Signed Routes Works In Laravel?

It isn't extracted from the hash. When the URL signature is validated it will look to see if the URL has been modified. This includes the expires-parameter.

This is an example of a signed URL:

http://sandbox.test/unsubscribe?expires=1584372721&signature=917ac911f04a7172c01329408cfe8008fb7d1b8b22d6a3fe43b672b65ecfc77d

If you modify the value the URL, it will no longer match the signature. Therefore, it is safe to for Laravel to use the expires parameter to see if the URL is expired.

Signed URLs in the documentation

Laravel source code

Quick video explaining how it works

Activity icon

Replied to How Signed Routes Works In Laravel?

All URL-parameters are implemented in the signature hash so that later it can be compared and checked if the URL has been modified. So if you modify a parameter in the URL, including the expires-paramter - it will no longer be valid.

Taylor explains it here: https://youtu.be/yM7K7jd92Sw?t=266

Feb
25
1 month ago
Activity icon

Replied to Getting Key In JsonResource

Nice solution @sinnbeck! Quite a bit cleaner this way ;-)

Activity icon

Replied to Getting Key In JsonResource

There doesn't seem to be a nice way of doing this indeed. I'm doubtful about sharing this "solution", since it is a bit of a "hacky" way. But you could do it by altering your User resource class.

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;

class User extends JsonResource
{
    public $preserveKeys = true;

    protected static function getValueByKeyFromObject($keyValue, $object)
    {
        foreach ( $object->getAttributes() as $keyName => $objectKeyValue ) {
            if ( $keyValue == $objectKeyValue ) {
                return $keyName;
            }
        }
        return null;
    }

    protected static function appendKeysToCollectionObjects($collection)
    {
        foreach ( $collection as $keyName => &$object ) {
            $object->resource->preservedKeyValue = $keyName;
            $object->resource->preservedKeyName = self::getValueByKeyFromObject($keyName, $object);
        }
        return $collection;
    }

    public static function collection($resource)
    {
        return tap(new AnonymousResourceCollection($resource, static::class), function ($collection) {
            if (property_exists(static::class, 'preserveKeys')) {
                $collection->preserveKeys = (new static([]))->preserveKeys === true;
                $collection = self::appendKeysToCollectionObjects($collection);
            }
        });
    }
}

This would result in:

=> App\Http\Resources\User {#959
     +preserveKeys: true,
     +resource: App\User {#956
       id: 1,
       name: "Mrs. Agustina Sporer MD",
       email: "[email protected]",
       email_verified_at: "2020-01-27 11:16:17",
       created_at: "2020-01-27 11:16:17",
       updated_at: "2020-01-27 11:16:17",
       preservedKeyValue: 1,
       preservedKeyName: "id",
     },
     +with: [],
     +additional: [],
   }
Feb
23
1 month ago
Activity icon

Replied to How To Image Upload Using Dropzone ?

Dropzone has pretty good documentation available, check it out: https://www.dropzonejs.com/#usage

For starters, in your demo, you would have to change the url so that it points to the right function in a controller.

Feb
15
1 month ago
Activity icon

Awarded Best Reply on Update The Value Of The Object

Assuming these are User models, you could do something like this:

$users = User::hydrate( \DB::select("CALL get_users_halls") );

foreach ( $users as $user ) {
  
  $user->invoice_number = '123456';
  $user->save();

}
Feb
12
1 month ago
Activity icon

Replied to Call To A Member Function Store() On String When Testing Uploads

It might have something to do with the file extension. You created an image with jpg not jpeg. I think test fails because of that.

Activity icon

Replied to Laracasts Quizzes

I don't know if it's an issue, but when I first took the quiz I made some mistakes (whoops). Then restarted with the button at the end of the test and did the test again. However, if I now go to the test - I see my previous result and not the latest one.

Very cool btw!

Activity icon

Replied to Update The Value Of The Object

Assuming these are User models, you could do something like this:

$users = User::hydrate( \DB::select("CALL get_users_halls") );

foreach ( $users as $user ) {
  
  $user->invoice_number = '123456';
  $user->save();

}
Activity icon

Replied to Call To A Member Function Store() On String When Testing Uploads

Just to be sure, have you checked if your files are stored in the storage/public/images directory?

Activity icon

Replied to Call To A Member Function Store() On String When Testing Uploads

I think you'll have to make sure that your filename property in your test is an array in that case.

Activity icon

Replied to Call To A Member Function Store() On String When Testing Uploads

You are doing a foreach on filename, does this mean you are handling multiple files?

In your test you are only submitting one file.

Feb
09
1 month ago
Activity icon

Replied to Best Practices For Occasional Coding On A Large Project?

First thing that comes to mind is, maybe you can define a MVP of your project? This could make an initial usable version of your project maybe achievable in a 2-3 month burst like you mentioned.

Feb
01
1 month ago
Activity icon

Awarded Best Reply on File Storage In Local And Public Storage At The Same Time.

You could set up a route for that. If you know the path to the file, you can download it using the storage download method.

See this example:

public function download(UserFile $file)
{

   return \Storage::download($file->location);
}

I have used this in the past with a comparable use case and the above works with files located on a non-public directory.

Jan
27
2 months ago
Activity icon

Replied to Exception Thrown When Trying To Use Database Notifications

For what it's worth, I just created a fresh Laravel application (6.12.0), did the user and notification -migrations and added the NewFollower class (copied your code). I also copied your /test route code. And I did not run into any errors.

Sequel Pro screenshot

Activity icon

Replied to File Storage In Local And Public Storage At The Same Time.

You could set up a route for that. If you know the path to the file, you can download it using the storage download method.

See this example:

public function download(UserFile $file)
{

   return \Storage::download($file->location);
}

I have used this in the past with a comparable use case and the above works with files located on a non-public directory.

Jan
26
2 months ago
Activity icon

Replied to File Storage In Local And Public Storage At The Same Time.

You make the symbolic link on the storage/app/public directory. So storage/user-files will not be impacted by that and thus not be publicly accessible. You should not make a symbolic link on the entire storage folder, just the part that you want public.

Jan
23
2 months ago
Activity icon

Replied to Starting From Scratch Series Laravel 6

There is an error in your syntax, are all your blade elements opened and closed correctly?

It is best to share your code here when you run into an error, that's easier to debug.

Activity icon

Awarded Best Reply on Delete Not Working With Resource Route

I think it's because you are wrapping your button with an a-tag (link).

<form action="{{ route('admin.users.destroy', $user) }}" method="POST">
    @csrf
    @method('DELETE')
    <button class="btn btn-warning" type="submit">Delete</button>
</form>

If you'd like to ask the user to confirm the submit of the form, you could do something like this:

<form action="{{ route('admin.users.destroy', $user) }}" onsubmit="return confirm('Are you sure?');" method="POST">
    @csrf
    @method('DELETE')
    <button class="btn btn-warning" type="submit">Delete</button>
</form>
Activity icon

Replied to Delete Not Working With Resource Route

I think it's because you are wrapping your button with an a-tag (link).

<form action="{{ route('admin.users.destroy', $user) }}" method="POST">
    @csrf
    @method('DELETE')
    <button class="btn btn-warning" type="submit">Delete</button>
</form>

If you'd like to ask the user to confirm the submit of the form, you could do something like this:

<form action="{{ route('admin.users.destroy', $user) }}" onsubmit="return confirm('Are you sure?');" method="POST">
    @csrf
    @method('DELETE')
    <button class="btn btn-warning" type="submit">Delete</button>
</form>
Activity icon

Awarded Best Reply on Stack On Query String With Vuejs Using AJAX

You could append parameters to the URL when the value of an input changes. Then after trigger a new request to fetch new results.

What have you got so far, in terms of code?

Activity icon

Replied to Stack On Query String With Vuejs Using AJAX

You could probably check if the input has a value before you append it. That would prevent the empty parameters.

Not too long ago I made something familiar to this and I don't know if it is the best way to do it, but it works and I think it's a pretty good solution.

Activity icon

Replied to Stack On Query String With Vuejs Using AJAX

You could append parameters to the URL when the value of an input changes. Then after trigger a new request to fetch new results.

What have you got so far, in terms of code?

Jan
22
2 months ago
Activity icon

Replied to Api_token Working - But How To Authorize Access To API's By Roles/permissions?

I think you could handle those things like you would do with regular routes. You can use Policies or apply middelware to the API-routes.

https://laravel.com/docs/5.7/middleware#defining-middleware https://laravel.com/docs/5.7/authorization#creating-policies

Activity icon

Replied to Problem With Laravel Relations And Latest, Paginate

Do you have anything for pagination in your view?

For pagination use:

{{ $category->links() }}

https://laravel.com/docs/5.8/pagination#displaying-pagination-results

Edit: I only now notice you are saying "i want to paginate items reached from article model". So you want to go through articles, not categories?

In that case, why are you starting with the Category model in the first place?

Why not just do something like this:

$articles = Article::whereHas('categories', function($query) use ($slug) {
  $query->where('slug', $slug);
})->latest()->paginate(12);

In your article model, you should implement a categories method.

use App\Category;

public function categories()
{
   return $this->belongsToMany(Category::class);
}
Activity icon

Replied to How To Fetch Login User And Insert Details To Login User

I have edited my controller snippet, I was using app()->user() but it should be auth()->user(). If you run into errors, please share them.

Activity icon

Replied to Problem With Laravel Relations And Latest, Paginate

Is there a created_at column in your category table? By default latests will use that for sorting.

https://laravel.com/docs/6.x/queries#ordering-grouping-limit-and-offset

Activity icon

Replied to How To Fetch Login User And Insert Details To Login User

If you only wan't to edit the currently logged in user through this form, you don't need to submit the user's id but you can instead just call auth()->user() to get the current user, which you could do in your controller function.

If my above assumption is correct, it might be good to rename your store method to update. You also use the PATCH method, instead of POST.

This is a very basic (not tested) example to give you an idea:

edit.blade.php

<form method="POST" action="{{ route('admin.customers.update') }}">
   @csrf 
   <div class="form-group">
      <label for="name">{{ __('Name') }}</label>
      <input type="text" name="name" value="{{ auth()->user()->name }}">
   </div>

   <div class="form-group">
      <label for="email">{{ __('Email') }}</label>
      <input type="email" name="email" value="{{ auth()->user()->email }}">
   </div>

   <button type="submit" class="btn btn-primary">{{ __('Save') }}</button>
</form>

AdminCustomersController.php (part)

public function update()
{
   $attributes = request()->validate([
      'email' => 'required|email'
      'name' => 'required'
   ]);

   auth()->user()->update($attributes);
   
   return redirect()->back();
}
Jan
20
2 months ago
Activity icon

Replied to File Storage In Local And Public Storage At The Same Time.

You create a symbolic link from public/storage to storage/app/public. You can store your PDF files within another storage directory which is not publicly accessible.

Activity icon

Replied to Check To Remove Expired Posts Laravel

Assuming boosted_untill is a datetime, you could already handle your if-statement within your DB-query.

Example (not tested):

$boosted = Post::whereIn('status_id', [4, 5, 6])
   ->where('boosted', 1)
   ->whereDate('boosted_untill', '<', Carbon::now())
   ->get();
Activity icon

Replied to Controller Not Validating After First Error

That's probably because on the second submit, your form inputs are empty. You can use the old function to make sure submitted values are set again after a failed validation.

Example:

<input type="text" name="example_input" value="{{ old('example_input') }}">

See: https://laravel.com/docs/6.x/helpers#method-old

Jan
16
2 months ago
Activity icon

Replied to Laravel Many-to-Many

I am guessing this is not your complete template? I am missing a the form-tag. Within the form tag you would specify the endpoint in the action attribute. The endpoint could then point to a specific controller action.

Activity icon

Replied to API Authentication

I'm not sure I completely understand, but maybe you could look into using the CSRF-token for this? This token is used to determine the request is coming from the app itself, and not from an external source.

https://laravel.com/docs/6.x/csrf

Jan
15
2 months ago
Activity icon

Commented on Server-Fetched Partials

I used to just run tests from the terminal by actually typing in the command. Found this useful extension: https://github.com/calebporzio/better-phpunit

Guess who made it... Thanks Caleb ;-)

Activity icon

Replied to Laravel And Mandrill.

For anyone looking to use Mandrill, the driver is no longer in Laravel by default. You can get it here: https://github.com/therobfonz/laravel-mandrill-driver

Jan
13
2 months ago
Activity icon

Replied to Has Many Through Relation On Pivot

Haven't used hasManyThrough before myself, but have you checked the code example in the docs? https://laravel.com/docs/6.x/eloquent-relationships#has-many-through

Looks the parameters are a bit different compared to your snippet. Maybe it has something to do with that?

public function users()
{
        return $this->hasManyThrough(
            EventPosition::class,
            User::class,
            'position_id', // Foreign key on positions table...
            'user_id', // Foreign key on users table...
            'id', // Local key on positions table...
            'id' // Local key on users table...
        );
}
Nov
26
4 months ago
Activity icon

Replied to Laravel-dompdf Queued Job

Have you checked your error log? This mostly means that in your script something is referenced which is not defined in the context of, in this case, the job. This could for example be your globals, or perhaps your $pdf variable. Your error log should probably provide more details on this.

Activity icon

Replied to Pagination Issue With Search Query

You are not asking for this in particular, but I am going to share this anyway. If your search term variable ($q) comes from a GET-request, you will notice that this parameter is lost on the links that the pagination returns.

To add it, you can append to it like this:

{{ $user->appends(['q' => $q])->links() }}
Activity icon

Replied to Is It Possible To OnClick And Href At A Time?

Is jQuery working at all? Can you check your dev-tools console for errors?

Activity icon

Replied to Suggestion For Many To Many Relationship, And Data Repentance Laravel

I am not entirely sure if I get what your trying to achieve. But in general, a many-to-many relation is established by the use of a so called pivot-table.

For example, let's say you are dealing with posts and post categories. A post may have multiple categories, so we need a pivot table which for could look something like this:

Table: posts
- id (primary key)
- name
- date

Table: categories
- id (primary key)
- name

Table (pivot): category_post
- post_id (foreign key reference to id on posts)
- category_id (foreign key reference to id on categories)

Maybe you already knew this, in that case, feel free to ignore my post ;-) If not, I hope it might give you some insight that gets you closure to a solution for your specific problem.