bobbybouwmann

bobbybouwmann

Developer at Enrise

Member Since 5 Years Ago

Apeldoorn, The Netherlands

Experience Points
1,700,895
Total
Experience

0 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
1638
Lessons
Completed
Best Reply Awards
2208
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 50
1,700,895 XP
Apr
04
21 hours ago
Activity icon

Awarded Best Reply on How To Safely Update Users From Api

I think I misread your question. To make sure that you only accept requests from your own frontend app you should set up your CORS-headers. They can help you prevent getting requests from other sources, other than your own site.

Laravel 7 has this by default: https://laravel.com/docs/7.x/routing#cors

You can configure your domain in config/cors.php. If you're not on Laravel 7 you can install this package: https://github.com/fruitcake/laravel-cors

Activity icon

Replied to Need Suggestion On Checkout Page Name Fileds

If you already have their information and they are logged in you should be good to use that data ;) Another option is pre-filling the form with that data so they can update it if they want to.

Activity icon

Awarded Best Reply on Redirect To Back Method Not Working

The back method is basically a wrapper around response()->back(). The problem here is that you forgot to return the result.

Try this

return back();

// Or

return response()->back();
Activity icon

Awarded Best Reply on Updating Model Does Not Work???

It sounds to me that you assigned some model to $data and now you try to update it. This is not an array, so you need to handle it as an object instead.

Try this

$data = Model::first();

$data->score = $request->input('tries') * $request->input('score');
$data->save();
Activity icon

Awarded Best Reply on Building API SDK

There are a lot of SDK's available on the internet and on Github. Take a look at those and see how they do it.

I assume you have your API build in Laravel and you probably also want a Laravelish package for your SDK. The Forge SDK might be exactly what you're looking for. You can use that as a basis ;)

Forge SDK: https://github.com/themsaid/forge-sdk

Activity icon

Awarded Best Reply on New To Queues! What Does Everything Mean?

A few months ago someone asked this as well! The best reply from there should put you in the right direction

Thread: https://laracasts.com/discuss/channels/laravel/what-is-queue-connection-name-and-what-is-the-use-of-queue-name-connection

Activity icon

Replied to Middleware For Roles Not Working As Supposed To.

Because you redirect to the intended URL. This URL is most of the time the URL before you got redirected to the login screen. Since you don't want to allow the user to have access you should redirect them to a page where they can actually login

class AdminRole
{
    public function handle($request, Closure $next)
    {   
        if (Auth::user()->hasRole('Admin')) {
            return redirect('/login');
        }

        return $next($request);
    }
}
Activity icon

Replied to Make A Table Row Clikkable Using Laravel 6.x And Laravelcollective Form

@jahstation You can't wrap an <a href=""> tag around a table row. This is not possible in HTML. You can add a link in a <td> element, but that's it. If you want to click the whole row you need to use JS.

In your case, this should work

<tr>
    <td>
        <a href="{{ route('patientDetails') }}">{{ $paziente['display'] }}</a>
   </td>
</tr>
Activity icon

Replied to Nova Resource Route Redirect

Aah sorry about that, you need to add \ in front of it. By default, it's only looking in the App/Http/Controllers namespace

return redirect()->action('\Laravel\Nova\Http\Controllers\[email protected]', ['resource' => 'q-requests', 'resourceId' => $qri]);
Activity icon

Replied to Optional Form Inputs

I'm not sure what your problem is right now. First, it was validation, not it's logging in...

Activity icon

Replied to How To Test A Queued Closure

Laravel has a lot of helpers for testing your jobs. For example

// ActionJobTest.php
Bus::fake();

// Perform your action

Bus::assertDispatched(ActionJob::class, function ($job) {
    return $job->data['action'] === 'deleteAllFiles';
});

However, this doesn't support closure based jobs.

My recommendation would be creating a job class, which makes this more testable as well ;)

Activity icon

Replied to Does Laravel Protect SQL Injection When Using Raw SQL?

Yeah, it's still safe to use raw SQL. However, you can still pass the variable in there which makes it insecure.

Here is an example of how you can use it

$users = DB::select('select * from users where active = ?', [1]);

The second argument is used to pass arguments to the query.

Note: All values passed to the second argument will be parsed as strings in the query. In theory, someone can still perform SQL injection. So if you want to be sure, do a double-check the values before you pass them to the query. Using Eloquent is the safest way in Laravel, which will prevent this by default ;)

Activity icon

Replied to Laravel Nova Policy Issue

Yes, this is a known issue in Nova. We used CSS to hide the extra empty row.

Hacky, but works ¯_(ツ)_/¯

Activity icon

Replied to Laravel 7 Blade Component Strategy

The components look correct, except for the text component. This one always requires the label variable, which isn't passed to it.

Activity icon

Replied to Laravel 7 Blade Component Strategy

You need to pass the $label variable to your input component. You do reference it in your text.blade.php file, but it is never passed to that component.

Activity icon

Replied to How Can I Get A Full Tokens List In Sanctum?

$user->tokens()->all() should already work. You then get a collection of those tokens. If you only want the tokens you can do something like this

$user->tokens()->all()->pluck('token')
Activity icon

Replied to Redirect Exceptions And Errors To File

Laravel should automatically log all errors to the storage/logs directory for you unless you changed something in your app/Exceptions/Handler.php file or your config/logging.php config. Did you change anything there?

Activity icon

Replied to A Doubt About The Code And Relationship Between Two Tables

The code looks good to me. Give it a go and see if you get any errors ;)

Activity icon

Replied to Accessor With Advanced Joins "Property [total_laps] Does Not Exist On The Eloquent Builder Instance"

Before I start digging into your query, I have a question.

Why don't you just count the number of pledges specifically for that athlete_id by some date range? A pledge is equal to one lap, right? You can achieve the same by simply counting all the laps right?

Let me know if I'm thinking incorrectly, but to me, it seems you're making this very difficult.

Activity icon

Replied to Can't Seem To Set Expiry In A Cookie

Are you sure the dealer is set in the request? Just double-checking

Activity icon

Replied to Make A Table Row Clikkable Using Laravel 6.x And Laravelcollective Form

You basically need a link to another page, right?

Well, you can add <a href="URL HERE>CLICK HERE</a> to your table row.

If you want to have the whole row clickable you need some javascript to make this work, this is not supported in HTML itself.

Activity icon

Replied to Nova Resource Route Redirect

The problem here is that Nova doesn't have a named route that's called nova.resource or something. So instead you need to use the action here

return redirect()->action('Laravel\Nova\Http\Controllers\[email protected]', ['resource' => 'q-requests', 'resourceId' => $qri]);
Activity icon

Replied to Sorting An Associative Array By A Specific Key In Laravel ?

Here you go

$array = array(
    array('name' => 'Bob',    'weight' => 200),
    array('name' => 'Rachel', 'weight' => 345),
    array('name' => 'Arthur', 'weight' => 460),
    array('name' => 'Paige',  'weight' => 120),
    array('name' => 'Chris',  'weight' => 135),
);

$orderedItems = collect($array)->sortBy('weight');

$array = $orderedItems->toArray();
Activity icon

Replied to Creating Helper Function Or Add It To Macros ?

You won't really notice any performance differences. Both the service provider or helpers file will be loaded and called.

If it's only string methods, I would personally go for the macros ;)

Activity icon

Awarded Best Reply on Translation From Json Using __()

Aah, of course. The JSON structure indeed doesn't support the nesting of translations. You should use the PHP translation files for that

// resources/lang/en/global.php

<?php

return [

    'title' => 'Title',

    'nex' => 'Next page',

];

{{ __('global.title') }}

This should work for you ;)

Activity icon

Replied to Optional Form Inputs

What exactly is the error you get?

The only "bug" I can spot in your code is that you always get the bio out of the $data array, but it can be empty. This probably means that this key doesn't exist in the array which breaks it. Instead, you need to check if the field exists before you assign it

return User::create([
    'name' => $data['name'],
    'email' => $data['email'],
    'password' => Hash::make($data['password']),
    'userlevel' => $data['userlevel'],
    'avatar' => '/uploads/avatars/'. $proimgname,
    
    // Optional field
    'bio' => array_key_exists('bio', $data) ? $data['bio'] : null,
]);

Well, you get the idea.

Activity icon

Awarded Best Reply on Consuming Your Web Api On Mobile

Like @atef95 says, HTTP calls are stateless. You need to send the token along to know which user you're dealing with.

You need a login route that returns the access token for the user. Ideally, you also want to have a refresh token, if the previous token got expired. There are different kinds of tokens available in Passport. You first need to figure out which one you want to use ;)

Activity icon

Awarded Best Reply on TO Load Some Data Only Once In A Multiple Pages App

PHP itself is HTTP based, which means it doesn't remember anything from the previous request. It needs to rebuild it all the time. Luckily Laravel supports caching. You can build in your own cache for say one hour or one week and so on.

Take a look at this: https://laravel.com/docs/7.x/cache

In your case, you're fetching pages and albums. You can create a cache named sidebar-album-categories and clear the cache for this key whenever a new AlbumCategory is created. That is up to you!

Let me know if this is clear.

Activity icon

Replied to Laravel API Authentication Return {"message": "Unauthenticated."} But Not User Data.

Correct, the member-api guard doesn't have a token, so this won't work... You need to use passport here.

Activity icon

Replied to How To Safely Update Users From Api

I think I misread your question. To make sure that you only accept requests from your own frontend app you should set up your CORS-headers. They can help you prevent getting requests from other sources, other than your own site.

Laravel 7 has this by default: https://laravel.com/docs/7.x/routing#cors

You can configure your domain in config/cors.php. If you're not on Laravel 7 you can install this package: https://github.com/fruitcake/laravel-cors

Activity icon

Replied to Make A Table Row Clikkable Using Laravel 6.x And Laravelcollective Form

Not sure what you mean with table row clickable.

In general, if you want a table update the row of a table you need some kind of ajax request to fetch the data and insert that in the row.

Activity icon

Replied to TO Load Some Data Only Once In A Multiple Pages App

PHP itself is HTTP based, which means it doesn't remember anything from the previous request. It needs to rebuild it all the time. Luckily Laravel supports caching. You can build in your own cache for say one hour or one week and so on.

Take a look at this: https://laravel.com/docs/7.x/cache

In your case, you're fetching pages and albums. You can create a cache named sidebar-album-categories and clear the cache for this key whenever a new AlbumCategory is created. That is up to you!

Let me know if this is clear.

Activity icon

Replied to Hi , I Am Working On Multi Vendor Website I Want To Know The Steps To Make Login For Admin And Vendor , User

I would advise you to have one users table and either add roles or a user type in the database. After that, you can simply update your login controller and redirect them to the correct page based on their role or type.

Activity icon

Replied to Extending User Model

Awesome :D

Activity icon

Replied to How To Safely Update Users From Api

Most of the time you use an access token which can only be used for 1 hour for example, after that, your frontend should fetch a new token. So the basic term here is a shorted lived token for authentication.

Activity icon

Awarded Best Reply on Extending User Model

You have two options here. Extending the user as you do now, or use something like a role in the users table. Then everything stays a User, but you have to query specifically for athletes or coaches.

Looking at your current example it would be better to continue with this. However, I would still recommend you to add a role or type column to your users table. The reason for this is that it makes it a lot easier to query them

class Athlete extends User
{
    protected static function booted()
    {
        static::addGlobalScope('athlete', function (Builder $builder) {
            $builder->where('type', 'athlete');
        });
    }
}

This way you can simply do Athele::all() and you will only get users back with that specific type.

For your relationships, you need to be a little bit creative. You need a many-to-many relation between athletes and coaches. Since you extend the User model you only have those ids, but you can name them whatever you want. So this should work

class Athlete extends User
{
    public function coaches()
    {
        return $this->belongsToMany(Coach::class, 'athlete_coach', 'athlete_id', 'coach_id');
    }
}

class Coach extends User
{
    public function athletes()
    {
        return $this->belongsToMany(Athlete::class, 'athlete_coach', 'coach_id', 'athlete_id');
    }
}

Your migration might look like this

Schema::create('athlete_coach', function (Blueprint $table) {
    $table->bigInteger('athlete_id')->unsigned();
    $table->bigInteger('coach_id')->unsigned();

    $table->foreign('athlete_id')->references('id')->on('users');
    $table->foreign('coach_id')->references('id')->on('users');
});

Let me know if that makes sense ;)

Activity icon

Replied to Replace Method From Request Facade Not Replacing Data From Query Parameters #31683

@kalemdzievski Correct, but it's a breaking change in the framework.

You can create a PR to make this work if you wish ;) If it's accepted it will be added to Laravel 8 :D

Activity icon

Replied to Raw Expressions

You always need to call ->first() or ->get() at the end to actually perform the query.

$orders = DB::table("orders")
    ->select(DB::raw("created_at as stat_day, SUM(billing_totalprice) GROUP BY created_at order by created_at"))
    ->get();
Activity icon

Replied to Extending User Model

You have two options here. Extending the user as you do now, or use something like a role in the users table. Then everything stays a User, but you have to query specifically for athletes or coaches.

Looking at your current example it would be better to continue with this. However, I would still recommend you to add a role or type column to your users table. The reason for this is that it makes it a lot easier to query them

class Athlete extends User
{
    protected static function booted()
    {
        static::addGlobalScope('athlete', function (Builder $builder) {
            $builder->where('type', 'athlete');
        });
    }
}

This way you can simply do Athele::all() and you will only get users back with that specific type.

For your relationships, you need to be a little bit creative. You need a many-to-many relation between athletes and coaches. Since you extend the User model you only have those ids, but you can name them whatever you want. So this should work

class Athlete extends User
{
    public function coaches()
    {
        return $this->belongsToMany(Coach::class, 'athlete_coach', 'athlete_id', 'coach_id');
    }
}

class Coach extends User
{
    public function athletes()
    {
        return $this->belongsToMany(Athlete::class, 'athlete_coach', 'coach_id', 'athlete_id');
    }
}

Your migration might look like this

Schema::create('athlete_coach', function (Blueprint $table) {
    $table->bigInteger('athlete_id')->unsigned();
    $table->bigInteger('coach_id')->unsigned();

    $table->foreign('athlete_id')->references('id')->on('users');
    $table->foreign('coach_id')->references('id')->on('users');
});

Let me know if that makes sense ;)

Activity icon

Replied to Can't Seem To Set Expiry In A Cookie

I believe the cookie helper method is only used for retrieving cookies and not making them.

Try this instead

$cookieJar->queue($cookiejar->make('dealer', $request->dealer, time() + 60*60*24*10));

Also, make sure that the AddQueuedCookiesToResponse middleware is enabled ;)

// app/Http/Kernel.php

protected $middlewareGroups = [
   'web' => [
      \App\Http\Middleware\EncryptCookies::class,
      \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,

      // Other middlewares
   ],
];
Activity icon

Replied to Opposite Of Optimize:clear ?

It's on the top if you run php artisan. It has no extra namespace ;)

Available commands:
  clear-compiled                         Remove the compiled class file
  down                                   Put the application into maintenance mode
  env                                    Display the current framework environment
  help                                   Displays help for a command
  list                                   Lists commands
  migrate                                Run the database migrations
  optimize                               Cache the framework bootstrap files        <<<<--------
  serve                                  Serve the application on the PHP development server
  test                                   Run the application tests
  tinker                                 Interact with your application
  ui                                     Swap the front-end scaffolding for the application
  up                                     Bring the application out of maintenance mode
 auth
  auth:clear-resets                      Flush expired password reset tokens
 cache
  cache:clear                            Flush the application cache
  cache:forget                           Remove an item from the cache
  cache:table                            Create a migration for the cache database table
 config
  config:cache                           Create a cache file for faster configuration loading
  config:clear                           Remove the configuration cache file
Activity icon

Replied to How Can I Edit Table Column Settings In Production Using Laravel?

You can perform the change to make the field nullable on your database without losing data. It just changes the type of the column, not the value.

To apply this on production you create a new migration for the users table with that line. Then you only have to run the migrations and you're good to go.

To be sure I would test this out on your local environment of course ;)

Activity icon

Replied to Raw Expressions

Well, you forgot your quotes here

$orders = DB::table("orders")->select(DB::raw("created_at as stat_day, SUM(billing_totalprice) GROUP BY created_at order by created_at"));

Also, your query is a bit weird. Everything points to the created_at column and you only rename them in your query but you don't do anything with it...

Activity icon

Replied to Building API SDK

There are a lot of SDK's available on the internet and on Github. Take a look at those and see how they do it.

I assume you have your API build in Laravel and you probably also want a Laravelish package for your SDK. The Forge SDK might be exactly what you're looking for. You can use that as a basis ;)

Forge SDK: https://github.com/themsaid/forge-sdk

Activity icon

Awarded Best Reply on Opposite Of Optimize:clear ?

Yeah, you can run php artisan optimize for that ;) However, it might not cache everything you need to get cached since it only caches the framework bootstrap files.

Just running php artisan route:cache and so in is fine too ;)

Activity icon

Awarded Best Reply on Task Or Events?

You can find a lot of information here as well: https://laravel.com/docs/7.x/scheduling

Activity icon

Replied to Updating Model Does Not Work???

It sounds to me that you assigned some model to $data and now you try to update it. This is not an array, so you need to handle it as an object instead.

Try this

$data = Model::first();

$data->score = $request->input('tries') * $request->input('score');
$data->save();