bobbybouwmann

bobbybouwmann

Developer at Enrise

Member Since 5 Years Ago

Apeldoorn, The Netherlands

Experience Points
1,617,165
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
1598
Lessons
Completed
Best Reply Awards
2077
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 50
1,617,165 XP
Jan
28
12 hours ago
Activity icon

Replied to Authentication Within Authentication

Not sure what you mean, but I think you want to connect the authenticated user to one of the companies you have in the database. So in general, you need two tables for this. One for users and one for companies. Whenever you register you can adjust the form to create both.

You can do all of this with just one user logging in and just sending them to the right page depending on user dashboard or company dashboard

Activity icon

Replied to How To Check If Other There Is Other 'npm Run Watch' Still Running ?

You can probably see if npm is still running by checking it using this

ps aux | grep npm

All the results you get will have a PID. You can stop them by running the following with the PID

// If PID is 64850
kill -9 64850
Activity icon

Replied to How To Refresh Page When "back" Button Is Clicked Vue.JS

So, it's pretty hard to actually refresh the page whenever you click on the back button. However, it's possible with a small work around.

This should work on most browsers

window.onpopstate = function () {
    location.reload()
};

Note: I said most browsers, in some edge cases it might not work. This is the hard part about controlling the history of a browser ;)

Jan
27
1 day ago
Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

Well, the error must show more than just this right?

Activity icon

Awarded Best Reply on How To Return Back() With Passwords Status And After 5 Sec Redirects To Another Page?

This should work in your JS

<script>
        setTimeout(function () {
            window.location.replace('{{ url('home') }}');
        }, 5000);
</script>
Activity icon

Replied to Laravel - Required Own Package, Can't Find Route

I think you need to prefix the namespace of the route with a \ before it

Route::get('visitors', '\Rainieren\Visitors\Http\Controllers\[email protected]');

Also, what happens when you run php artisan route:list? It should show up.

Activity icon

Replied to Conversion For Documents With Libreoffice

All options are probably fine. Use whatever you already know ;)

Also, if you're toying with AWS it might be nice to look into lambdas. Basically a function you can fire for each document on AWS. No server needed ;)

Activity icon

Replied to How To Return Back() With Passwords Status And After 5 Sec Redirects To Another Page?

This should work in your JS

<script>
        setTimeout(function () {
            window.location.replace('{{ url('home') }}');
        }, 5000);
</script>
Activity icon

Awarded Best Reply on Project Planning App Dates

Dates can be though, but Laravel makes this a breeze! Laravel can handle dates as Carbon objects. Then you can simply call the format method on the object. So something like this

$model->created_at->format('Y-m-d');

This link shows you all the possible options for the formats: https://www.php.net/manual/en/function.date.php

If you don't get the date from a model, you can simply create a new Carbon object and use format on that as well

\Carbon\Carbon::now()->format('l j F Y');

\Carbon\Carbon::createFromFormat('Y-m-d', '2020-01-20')->format('l j F Y');

You can just play around with this ;)

Activity icon

Replied to How To Validate Fields In Maatwebsite Excel Import

This should get you started: https://docs.laravel-excel.com/3.1/imports/validation.html

Let me know if you're stuck with one of the rules :D

Activity icon

Replied to Project Planning App Dates

Dates can be though, but Laravel makes this a breeze! Laravel can handle dates as Carbon objects. Then you can simply call the format method on the object. So something like this

$model->created_at->format('Y-m-d');

This link shows you all the possible options for the formats: https://www.php.net/manual/en/function.date.php

If you don't get the date from a model, you can simply create a new Carbon object and use format on that as well

\Carbon\Carbon::now()->format('l j F Y');

\Carbon\Carbon::createFromFormat('Y-m-d', '2020-01-20')->format('l j F Y');

You can just play around with this ;)

Activity icon

Awarded Best Reply on Calender In Laravel

Spatie has a package for this and it’s pretty good! You can find all the information you need here: https://github.com/spatie/laravel-google-calendar

Activity icon

Replied to Calender In Laravel

Spatie has a package for this and it’s pretty good! You can find all the information you need here: https://github.com/spatie/laravel-google-calendar

Activity icon

Replied to Laravel And Jigsaw

You can't just register the service provider, so it seems. Instead, you can bind all classes yourself like shown in the DatabaseServiceProvider class itself.

Jan
26
2 days ago
Activity icon

Replied to Laravel And Jigsaw

You need to install illuminate/database first using

composer require illuminate/database

After that, you probably need to load the database service provider: https://github.com/laravel/framework/blob/1bbe5528568555d597582fdbec73e31f8a818dbc/src/Illuminate/Database/DatabaseServiceProvider.php

After that this should work I guess (I also never tried this)

Activity icon

Replied to How To Create New Database For Every Session

I would create a separate middleware for this ;)

Activity icon

Replied to How To Create New Database For Every Session

Well, the basic steps are as followed

  • Create a new .sqlite file for the session
  • You need to migrate and seed that database (not sure if you really want this, it might take some time while the user is logging in. You should show a loading screen then or something)
  • Change the config based on the session (you need to do this in a middleware, so it always sets the database correctly based on the session)
Config::set('database.connections.sqlite.database', database_url($sqliteFileName));
  • You need a way to remove the databases that are old and not used anymore.
Activity icon

Awarded Best Reply on API Route Based On Authenticated User?

You can adjust the route to just the doctor like so

Route::get('bookings/{docter}', function (Docter $docter) { 
    return BookingResource::collection($doctor->bookings()->get());
});

Both solutions are fine, it just depends on your needs ;)

Activity icon

Replied to Laravel Resources Lost Meta When I Added Mapping

Because whenever you map over the results and return the models you get a regular collection. However, when you call pagination you get a different kind of object back. One with information about the pagination. This data is used for the metadata as well. Since you map over it, there is no pagination object anymore.

Now, resources are actually made for this. It seems that you have two relations you need to add.

Documentation: https://laravel.com/docs/6.x/eloquent-resources#conditional-relationships

Also, it's a good pattern to use the resource classes inside the collections

class AdCollection extends ResourceCollection
{
    public static $wrap = 'ads';

    public function toArray($request)
    {
        $this->collection->transform(function ($ad) {
            return new AdResource($ad);
        });

        return parent::toArray($request);
    }
}
Activity icon

Replied to API Route Based On Authenticated User?

You can adjust the route to just the doctor like so

Route::get('bookings/{docter}', function (Docter $docter) { 
    return BookingResource::collection($doctor->bookings()->get());
});

Both solutions are fine, it just depends on your needs ;)

Activity icon

Replied to Edit Xml Nodes

You don't really need a package for this. This functionality can already be done with the internals of PHP

Source: https://stackoverflow.com/questions/20540592/replace-specific-node-value-in-xml-using-php

Activity icon

Replied to Multi-Auth In Laravel 6 (Login Using Multiple Table But On Single Login Page)

Well, the problem here is that you check for the student one. But if it fails you return the sendFailedLoginResponse. Because of that you never get to the staff auth

Try this instead

if (Auth::guard()->attempt($this->studentcredentials($request), $request->filled('remember')) == true) {
    $request->session()->regenerate();
    $this->clearLoginAttempts($request);

    return redirect()->intended('dashboard/student');
} else if (Auth::guard('staff')->attempt($this->credentials($request), $request->filled('remember')) == true) {
    $request->session()->regenerate();
    $this->clearLoginAttempts($request);

    return redirect()->intended('dashboard/staff');
} else {
    $this->incrementLoginAttempts($request);

    return $this->sendFailedLoginResponse($request);
}

Do you see the difference here?

Activity icon

Replied to How To Avoid Duplication Of Code

You can reuse the Request classes

// app/Http/Controllers/Api/UsersControllers.php
class UsersControllers extends Controller
{
    public function store(UserRequest $request)
    {
        $user = User::create($request->all();

        return response()->json(['user' => $user]);
    }
}

// app/Http/Controllers/Web/UsersControllers.php
class UsersControllers extends Controller
{
    public function create(UserRequest $request)
    {
        $user = User::create($request->all();

        return view('users.show', compact('user'));
    }
}

Documentation: https://laravel.com/docs/6.x/validation#form-request-validation

Activity icon

Replied to How To Avoid Duplication Of Code

I normally build service classes that I reuse in controllers. For example, you have a feature that lists all users. You can then create one API controller that returns all the users. Then you also create a web controller that returns all the users.

The fetching of the data can then be done in a service class or a repository so you can reuse it. Something like this

// app/Http/Controllers/Api/UsersControllers.php
class UsersControllers extends Controller
{
    public function index(UsersService $usersService)
    {
        $users = $usersService->all();

        return response()->json(['users' => $users]);
    }
}

// app/Http/Controllers/Web/UsersControllers.php
class UsersControllers extends Controller
{
    public function index(UsersService $usersService)
    {
        $users = $usersService->all();

        return view('users.index', compact('users'));
    }
}

// app/Services/UsersService.php
class UsersService
{
    public function all()
    {
        return User::all();
    }
}

This is just a basic example. This way you make all functionality flexible and only the controllers are duplicate ;)

Activity icon

Awarded Best Reply on Non-static Method Illuminate\Database\Eloquent\Model::update() Should Not Be Called Statically

You can't do this

Invoices::update($request->all());

This call basically means, update all Invoices models with the given data. That is not what you want!

Instead, you need to do something like this

Invoices::where('id', $id)->update($request->all());
Jan
25
3 days ago
Activity icon

Awarded Best Reply on Define Eloquent Relationships For Tables

@jackyvip You need to make sure all columns are fillable when saving

class CommentPost extends Model
{
    protected $fillable = ['message_id', 'user_id', 'name'];
}
Activity icon

Replied to How To Return Back() With Passwords Status And After 5 Sec Redirects To Another Page?

I actually meant that you should use it like so

header('refresh:5;url=' . url('home'));

return back()->withPasswordStatus(__('Password successfully updated.'));

Anyway, your way should work as well

return back()->withPasswordStatus(__('Password successfully updated.'))
    ->header('refresh', '5;url=' . url('home'));

If that doesn't work, I would suggest you to either use javascript for the redirect or a meta tag

<meta http-equiv="Refresh" content="5; URL=https://example.com/home">
Activity icon

Replied to Define Eloquent Relationships For Tables

@jackyvip You need to make sure all columns are fillable when saving

class CommentPost extends Model
{
    protected $fillable = ['message_id', 'user_id', 'name'];
}
Activity icon

Replied to Storing Unknown Data

@daugaard47 I would go with the three tables set up, so with the pivot table. In the pivot table, you can also store some extra data that might be useful for that relation like the confirmation and so on!

Activity icon

Replied to How To Filter Retrieved Data From Relational Tables

Well, your JobRecord table doesn't have a status column. Make sure that column exists!

Activity icon

Replied to Gates

Well, you have to determine that logic. Here are some examples

public function create(User $user)
{   
    // If you're logged in you can do this
    return auth()->user();
}

public function create(User $user)
{   
    // If the user is verified
    return $user->hasVerifiedEmail();
}

Basically anything, as long as you return a boolean.

Activity icon

Awarded Best Reply on Is Possible To Multiple Tables Imports Using Maatwebsite?

You can use the ToCollection option to achieve this

class UsersImport implements ToCollection
{
    public function collection(Collection $rows)    
    {
        foreach ($rows as $row) 
        {
            User::create([
                'name' => $row[0],
            ]);

            Client::create([
                'company' => $row[1],
            ]);
        }
    }
}

Documentation: https://docs.laravel-excel.com/3.1/imports/collection.html

Activity icon

Awarded Best Reply on How To Filter Retrieved Data From Relational Tables

Aah! Instead, you need to do this (if I understand it correctly)

$job_records = JobRecord::with('job:job_id,status,mfg_site,total_pges,due_out')
    ->where('status', 'In Progress')
    ->get();
Activity icon

Awarded Best Reply on Explanation Needed On Laravel Relationships

The difference here is that ->loans() will create a new query builder object, so basically performing a new query in all cases.

->loans will perform the action on the collection. If there are no loans loaded it will try to fetch them. If they have been loaded before by with with for example it will use that.

However for ->create you always need to use loans() as far as I know. Because you're performing a new query. It doesn't make sense to call create on the collection. In other cases, you need to think about if you want a new query or a collection.

Jan
24
4 days ago
Activity icon

Replied to Define Eloquent Relationships For Tables

Well, comment is just a model here. So basically it works the same as all the other relationships

class Comment extends Model
{
    public function commentMessages():
    {
        return $this->hasMany(CommentMessage::class);
    }

    public function posts():
    {
        return $this->hasMany(CommentPost::class);
    }


    public function ratings():
    {
        return $this->hasMany(CommentRating::class);
    }
}

class CommentMessage extends Model
{
    public function comment()
    {
        $this->belongsTo(Comment::class);
    }
}

class CommentPost extends Model
{
    public function comment()
    {
        $this->belongsTo(Comment::class);
    }
}

class CommentRating extends Model
{
    public function comment()
    {
        $this->belongsTo(Comment::class);
    }
}

Documentation: https://laravel.com/docs/6.x/eloquent-relationships#one-to-many

Activity icon

Replied to Property [product_id] Does Not Exist On This Collection Instance !!!!!

You need to commit the query by calling first or get on the query. In your case there is no first, because of that, there is also no query performed. That's why you get this error.

Try this

$data = DB::table('invoice_packages')
    ->join('invoice_details', 'invoice_packages.inv_detail_id', '=', 'invoice_details.id_inv_detail')
    ->join('services', 'invoice_details.package_code', '=', 'services.product_treatment_code')
    ->join('service_details', 'services.id', '=', 'service_details.service_id')
    ->join('items', 'service_details.item_id', '=', 'items.id_item')
    ->where('invoice_details.package_code','LIKE', 'T-%')
    ->first();
Activity icon

Replied to Can Convert To Eloqoent

Seriously? What have you tried?

The documentation is pretty clear about joins, so it should be easy to get started at least ;)

Documentation: https://laravel.com/docs/6.x/queries#joins

Activity icon

Replied to How To Return Back() With Passwords Status And After 5 Sec Redirects To Another Page?

A cleaner solution might look like this

header('refresh:5;url=' . url('home'));
Activity icon

Replied to How To Return Back() With Passwords Status And After 5 Sec Redirects To Another Page?

You need to use this syntax

header( "refresh:5;url=/home" );
Activity icon

Replied to Gates

There should be a policy class, probably called SubmissionPolicy that has a method called create that returns a boolean based on if the user can perform this action or not

class SubmissionPolicy
{
    public function create(User $user)
    {
        return true;
    }
}

Documentation: https://laravel.com/docs/5.1/authorization#writing-policies

Activity icon

Replied to Login Pages Goes Blank If Put Wrong Credentials

@masumluf What is the error you get? It's completely unclear what's not working at this point. We can't help you if you don't provide enough formation. Please describe your flow and show code examples.

Activity icon

Replied to Can't Save Fetched Login User Name To Relationship

@hariprasatn I think it's better if you follow the laravel from scratch series first: http://laravelfromscratch.com/

Activity icon

Replied to FullCalendar Change Date Format?

You can probably just use the Laravel way of changing this

class EventModel extends Eloquent implements \MaddHatter\LaravelFullcalendar\Event
{
    protected $dates = ['start', 'end'];

    protected $dateFormat = 'm-d-Y';
    
    // The rest of your model
}

Note: I never tried the package, but I understand the framework ;)

Activity icon

Replied to Multiple @font-face In Scss Causes Build Issue

I've noticed this as well and couldn't find a workaround for it. It must be some kind of bug, but that can be anywhere. Laravel Mix uses a lot of different packages and it's really hard to pin this down to a specific package, at least for me it is hard at this point.

Activity icon

Replied to Traduction Arabe Laravel

Hee buddy, this is an English forum. We won't answer questions that are not in English.

Activity icon

Replied to How To Generate Only API_KEY And USER_SECRET In With Laravel Passport

Passport is a bit of a different way of authentication the user then just an API-key and secret. In general, this is connected to a user and also to the host they connect from (also called the client).

Anyway, you can easily generate a random string as API-key and secret for the user and check on that. No need for passport in this case.

Activity icon

Replied to Is Possible To Multiple Tables Imports Using Maatwebsite?

You can use the ToCollection option to achieve this

class UsersImport implements ToCollection
{
    public function collection(Collection $rows)    
    {
        foreach ($rows as $row) 
        {
            User::create([
                'name' => $row[0],
            ]);

            Client::create([
                'company' => $row[1],
            ]);
        }
    }
}

Documentation: https://docs.laravel-excel.com/3.1/imports/collection.html

Activity icon

Replied to Return View From Resourcefull Controller

Do you have an example of your controller?

In general something like this works:

public function create()
{
    return view('posts.create');
}