alanholmes

alanholmes

Senior Developer at Visualsoft

Member Since 6 Years Ago

Coulby Newham

Experience Points
74,470
Total
Experience

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
970
Lessons
Completed
Best Reply Awards
20
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]asts.com 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 15
74,470 XP
Feb
25
17 hours ago
Activity icon

Awarded Best Reply on Route::view Name

Hi @scooby

It has created a route, but you have not told it what to name itself.

If you want it to be a named route, you need to do this

Route::view('/welcome', 'welcome')->name('welcome');

See: https://laravel.com/docs/6.x/routing#named-routes

Activity icon

Replied to Route::view Name

Hi @scooby

It has created a route, but you have not told it what to name itself.

If you want it to be a named route, you need to do this

Route::view('/welcome', 'welcome')->name('welcome');

See: https://laravel.com/docs/6.x/routing#named-routes

Feb
24
1 day ago
Activity icon

Replied to Sending A Welcome Email After User Verify His Account

hi @nana-odai

It looks like you might not have imported the Illuminate\Auth\Events\Verified class in your listener, so it is looking for a Verified class within the App\Listeners namespace

Feb
17
1 week ago
Activity icon

Replied to Extending/Replacing A Core Trait

hi @booni3

I dont think there is a way you can fully replace it in core, as the way traits are loaded.

However, for traits that you are including in your own app files, you certainly can.

So, for example, in my app I am using Spaties permissions package, but I wanted to do some custom things when calling actions like assignRoles.

This package provides a HasRoles trait to include in your models, so that I did was create my own HasRoles trait, and then use the spatie one within my trait.

When you include a trait, you can have it rename/alias any of the methods within it, which will allow you to replace that method with a method of the same name, but will allow you to retain the option to call the original method as well (kind of similar to extending a parent class, and using parent::method).

Example:

namespace App\Permissions;

use Spatie\Permission\Traits\HasRoles as SpatieHasRoles;

trait HasRoles
{
    use SpatieHasRoles {
        assignRole as protected spatieAssignRole;
        syncRoles as protected spatieSyncRoles;
    }

    public function assignRole(...$roles)
    {
        $this->spatieAssignRole(...$roles);

        // custom logic here

        return $this;
    }

Activity icon

Replied to Proof Of Concept Of Dynamic Relationships Loading

Hi @ekhawlah

The include[]= option is the route I have gone down, as it is a feature available in the package I am using for these API endpoints: https://docs.spatie.be/laravel-query-builder/v2/features/including-relationships/

I think it works pretty well, means you only load what you need when you need it

Feb
12
1 week ago
Activity icon

Replied to Is It Required To Make Relation Functions In Both Models While We Just Wanna Use One Model.

@singhwithlaravel

not entirely sure what are trying to acheive, but if you are wanting to include soft deleted records you can use the withTrashed() scope

Activity icon

Replied to Is It Required To Make Relation Functions In Both Models While We Just Wanna Use One Model.

Hi @singhwithlaravel

No you dont have to define the relationships in both models, you only need to define the ones that you want to use.

Feb
10
2 weeks ago
Activity icon

Replied to How To Deal With Shopping Cart Processing?

Hi @burano

Not used the pacakge above, but I work for an eCommerce company (and have done eCommerce before here), and this is the general process that we use:

  • User adds an item to their basket
  • this creates a session with that product in the basket
  • They can add other products if they wish
  • They proceed to through the checkout, and the basket is saved as an order (with the product details at the time of purchase - eg the price at that point)
  • The payment is processed through the payment gateway.
  • Successful payments get updated as such, and things like bank transfer get marked as Pending Payment
  • At this point we clear the basket from the session

So, should the user start a new order either straight away or after a few days, it is treat as that, a new order.

And each order, is a snapshot of the details of that time (customer details, product details, etc), but they are still liked by having the IDs, but this means that should any details change for the product/customer, it doesnt effect previous orders.

So going back to your question, yes I would certainly start a new basket session for each order (unless you are also adding functionality to amend orders, in that case you would need to resume a previous basket session)

Activity icon

Replied to Spatie Role Permissions And Gates Help

Hi @sigalz

Glad you have it working :)

In terms of when the super admin check is being done, as you have added the Gate::before in AuthServiceProvider this tells the Gate to run this check before any other (whether that being direct through a can() call, ot through a permission check).

So if the Super admin check passes, it doesn't need to run any of the other checks. Which is also why you need to return null if it doesn't in the Gate::before, as it is looking for the first boolean response, and once it finds it, then it breaks there.

Think of it as a list of checks, and should any of them return a boolean, then that is where the check will exit.

Feb
06
2 weeks ago
Activity icon

Replied to Spatie Role Permissions And Gates Help

Hi @sigalz

So, the Gate function works with things like Auth()->user()->can('edit', $model) (which would go of to a policy for the model, and check the edit method).

The spatie package extends this, so that you can pass permissions in there, eg Auth()->user()->can('manage-users')

Which will check if the user has been assigned the Permsion manage-users (either directly, or if the permission has been assigned to a role).

So, as this runs through the gate, and Super Admin is set to pass all, it would pass.

Admin would also pass, if it had the permission assigned by givePermissionTo()

however, the Role Middleware is not going to using Gate, and is just checking if the user has a role directly assigned.

I went down the route of having everything limited by permissions, cause I was going to need different users with different permissions, and a possible mix of anything.

But if you are only having Super Admin, Admin and User roles, then using the roles would be enough, but you would need to check for the other roles too.

Eg, if checking User role, you would also need to check for Admin and Super Admin roles.

Another option, if you want to use the Gate stuff (like using the can(), you could create something like an is-admin permission, and assign that to the Admin role, then in your middleware group do

    'admin' => [
        'web',
        'auth',
        'role:is-admin'
    ],

And Super Admins would automatically pass that

Activity icon

Replied to Spatie Role Permissions And Gates Help

Hi @sigalz

From what I understand with the spatie pacakge, the permissions are running through Gate (using the can method), but the Role middleware doesn't appear to be.

I am using the pacakge, but I do all my restrictions based on permissions (which are assigned to roles), so the super admin passes that.

What you could try is when setting up the admin middleware group, is:


    'admin' => [
        'web',
        'auth',
        'role:admin|Super Admin'
    ],

I know you can do the above with permissions, as I have stuff like this on my routes

Route::get('/protected/route', '[email protected]')
     ->name('protected.create')
     ->middleware('permission:can-view|can-manage');

So I would assume you can do the same with roles

Feb
05
2 weeks ago
Activity icon

Awarded Best Reply on Validate A New Value Generated In Controller ?

hi @supunsam

If you are using Form Requests you can use the prepareForValidation method to alter/change any data before the validation.

For example, I have the following in one of mine to remove the trailing slash

protected function prepareForValidation()
    {
        $this->merge([
           'url' => rtrim($this->url, '/'),
        ]);
    }

So you could try something like this

protected function prepareForValidation()
    {
        $this->merge([
           'job_id' => $this->job_no . $this->cyc_no,
        ]);
    }
Activity icon

Replied to Validate A New Value Generated In Controller ?

hi @supunsam

If you are using Form Requests you can use the prepareForValidation method to alter/change any data before the validation.

For example, I have the following in one of mine to remove the trailing slash

protected function prepareForValidation()
    {
        $this->merge([
           'url' => rtrim($this->url, '/'),
        ]);
    }

So you could try something like this

protected function prepareForValidation()
    {
        $this->merge([
           'job_id' => $this->job_no . $this->cyc_no,
        ]);
    }
Jan
27
4 weeks ago
Activity icon

Replied to Is It Possible To Trigger A Password Reset Manually?

@damcclean

I implemented something similar (but more of an invite system via the admin), and this is where I started.

If you look at Illuminate/Foundation/Auth/SendsPasswordResetEmails in the sendResetLinkEmail method, you will see the following:

        $response = $this->broker()->sendResetLink(
            $this->credentials($request)
        );

This is actually what sends the password reset link, so all you really need to do is trigger that somehow.

I implemented another it under another route, as still needed the forgot password functionality, but I just have it extend the laravel controllers to reuse a lot of the logic

Jan
21
1 month ago
Activity icon

Awarded Best Reply on How To Redirect To A Page For Only First Time Login User

@siewlon6093

If you are using the Laravel auth scaffolding, there is a method that you can override in your login controller if you want custom actions after someone has logged in.

If this method doesn't return anything, then Laravel will default to redirecting to value set in $redirectTo`

So what you could do, is add another field to the table to see if the user has ever logged in, and if not redirect them to another page.

You could use a boolean field, or another timestamp, like last_login_at and just update that whenever they login, but have it as null by default

    /**
     * The user has been authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {
        if (is_null($user->last_login_at)) {
             // just set $this->redirectTo = 'redirect/url'
             // and laravel will then handle the redirect
        }

        // then here update the last_login_at timestamp
    }

Another approach, which would handle the register page login you in as well, is using a custom middleware (https://laravel.com/docs/6.x/middleware), that does the check to see if it is there first login, and redirect them if not.

Activity icon

Replied to How To Redirect To A Page For Only First Time Login User

@siewlon6093

Something as simple as this will do:

$user->update('last_login_at', now());

now() is just a helper function that uses Carbon under the hood

Activity icon

Awarded Best Reply on How To Perform Complex User Registration

@noblemfd

For the initial admin registration, you could do something similar to what I have done above, changing the create method on the register controller, but adding in the employee record as well:

   protected function create(array $data)
    {
        $company = Company::create([
            'name' => $data['company_name'],
            // other data
        ]);

        $employee = Employee::create([
            'company_id' => $company->id,
            'first_name' => $data['first_name'],
            'last_name' => $data['last_name'],
            'email' => $data['email'],
            // other data
        ]);

        $user = User::create([
            'company_id' => $company->id,
            'employee_id' => $employee->id,
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
            // other data
        ]);

        $employee->update(['user_id' => $user->id]);

        $user->assignRole('admin');

        return $user;
    }

Then, for the admin, there would be a screen for them to invite new employees, and that would do something similar in the store method

   protected function store(Request $request)
    {
        $employee = Employee::create([
            'company_id' => Auth()->user()->company_id, // ensure same company as logged in user
            'first_name' => $request->input('page.first_name'),
            'last_name' => $request->input('last_name'),
            'email' => $request->input('email'),
            // other data
        ]);

        $user = User::create([
            'company_id' => Auth()->user()->company_id, // ensure same company as logged in user
            'employee_id' => $employee->id,
            'email' => $request->input('email'),
            'password' => Hash::make({AUTO_GENERATED}),
            // other data
        ]);

        $employee->update(['user_id' => $user->id]);

        // response / redirect
    }

So then you are keeping your users table for simply handling auth, and using a one to one relationship, you would have an employees table that stores more detailed info about the user.

Jan
20
1 month ago
Activity icon

Replied to How To Redirect To A Page For Only First Time Login User

@siewlon6093

If you are using the Laravel auth scaffolding, there is a method that you can override in your login controller if you want custom actions after someone has logged in.

If this method doesn't return anything, then Laravel will default to redirecting to value set in $redirectTo`

So what you could do, is add another field to the table to see if the user has ever logged in, and if not redirect them to another page.

You could use a boolean field, or another timestamp, like last_login_at and just update that whenever they login, but have it as null by default

    /**
     * The user has been authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {
        if (is_null($user->last_login_at)) {
             // just set $this->redirectTo = 'redirect/url'
             // and laravel will then handle the redirect
        }

        // then here update the last_login_at timestamp
    }

Another approach, which would handle the register page login you in as well, is using a custom middleware (https://laravel.com/docs/6.x/middleware), that does the check to see if it is there first login, and redirect them if not.

Jan
09
1 month ago
Activity icon

Replied to Mocking A File In A Storage For A PHPUnit Test?

@zyxxyzyxz

You can use Illuminate\Http\Testing\File to simulate creating a file for upload

And you can use Storage::fake(DRIVER) to fake the upload, so that you can assert that the file has been uploaded. This will upload to /storage/framework/testing/disks/DRIVER

       Storage::fake('public');

       $logo = File::image('logo.png', 400, 100);

        $response = $this->actingAs($user)
                         ->putJson('/route', [
                              'logo' => $logo,
                         ]);

      $this->assertTrue(file_exists('path/to/saved/file'));
Jan
08
1 month ago
Activity icon

Replied to Is It Possible To Test If All Routes Are Redirected To Login Page When User Is Not Logged-id ?

@mostafalaravel

You could look to see how Illuminate\Foundation\Console\RouteListCommand gets a list of all available routes, and see if there is a way to get an array of them to loop through.

From there you would have to manually remove the login/register routes, as they are not meant to redirect you to login.

But you would also have to handle any routes that have params (eg /posts/{id})

Jan
07
1 month ago
Activity icon

Replied to Redirect Login

If you have used a custom auth setup, you can still acheive the same thing, all the intended part is doing is checking the url.intended session for a url, and if set, so it would just be a case of setting that

Activity icon

Replied to Redirect Login

@aronaman

If you use the Auth Middleware (https://laravel.com/docs/6.x/authentication#protecting-routes) - then it sends an intended url, which, if you are using the default laravel auth scaffolding, it will attempt to send them back using redirect()->intended($this->redirectPath())

Jan
06
1 month ago
Activity icon

Replied to Some Questions About The Laravel Testing

@mostafalaravel

Then you just need to add Use RefreshDatabase trait to your test class, so that it will run the migrations before your tests

Activity icon

Replied to How To Perform Complex User Registration

@noblemfd

For sending the email, I would use an event action. Laravel has something in core for verifying an email, and this would be a good starting point to see: https://laravel.com/docs/6.x/verification

As for Azure, unfortunately, I have no experience with that, so can't advise on that specifically.

Activity icon

Awarded Best Reply on HOD And Line Manager To See Only Staff Attached To Them

@noblemfd

Its just a case of adding another where to the query to filter the results.

HOD

HrEmployee::where('company_id', $userCompany)->where('department_id', Auth()->user()->department_id)->get();

Line Manager

HrEmployee::where('company_id', $userCompany)->where('line_manager_id', Auth()->user()->id)->get();

So just adding more if statements to determine when to add them.

Though, may I suggest, if this is something that you might need else where, you could add this as a query scope on the model (see https://laravel.com/docs/6.x/eloquent#local-scopes)

Activity icon

Replied to Some Questions About The Laravel Testing

@mostafalaravel

  1. Yeah you would generally not run the testing on the production env, it is for local (or through something like travis)

  2. For the DB, I've never used the .env.testing file, instead I set them ENV vars in the phpunit.xml file, and I also usually switch it to an in memory sqllite DB, so there is no need to setup a testing copy of the database as well (if this is an option for you)

Activity icon

Replied to HOD And Line Manager To See Only Staff Attached To Them

@noblemfd

Its just a case of adding another where to the query to filter the results.

HOD

HrEmployee::where('company_id', $userCompany)->where('department_id', Auth()->user()->department_id)->get();

Line Manager

HrEmployee::where('company_id', $userCompany)->where('line_manager_id', Auth()->user()->id)->get();

So just adding more if statements to determine when to add them.

Though, may I suggest, if this is something that you might need else where, you could add this as a query scope on the model (see https://laravel.com/docs/6.x/eloquent#local-scopes)

Activity icon

Replied to ErrorException (E_NOTICE) Compact(): Undefined Variable: Joinclass

@neeraj1005

That error is occuring, cause $joinclass will only be set, if the following condition is met:

if(Auth::user()->user_type ===0){
Activity icon

Replied to How To Perform Complex User Registration

@noblemfd

For the initial admin registration, you could do something similar to what I have done above, changing the create method on the register controller, but adding in the employee record as well:

   protected function create(array $data)
    {
        $company = Company::create([
            'name' => $data['company_name'],
            // other data
        ]);

        $employee = Employee::create([
            'company_id' => $company->id,
            'first_name' => $data['first_name'],
            'last_name' => $data['last_name'],
            'email' => $data['email'],
            // other data
        ]);

        $user = User::create([
            'company_id' => $company->id,
            'employee_id' => $employee->id,
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
            // other data
        ]);

        $employee->update(['user_id' => $user->id]);

        $user->assignRole('admin');

        return $user;
    }

Then, for the admin, there would be a screen for them to invite new employees, and that would do something similar in the store method

   protected function store(Request $request)
    {
        $employee = Employee::create([
            'company_id' => Auth()->user()->company_id, // ensure same company as logged in user
            'first_name' => $request->input('page.first_name'),
            'last_name' => $request->input('last_name'),
            'email' => $request->input('email'),
            // other data
        ]);

        $user = User::create([
            'company_id' => Auth()->user()->company_id, // ensure same company as logged in user
            'employee_id' => $employee->id,
            'email' => $request->input('email'),
            'password' => Hash::make({AUTO_GENERATED}),
            // other data
        ]);

        $employee->update(['user_id' => $user->id]);

        // response / redirect
    }

So then you are keeping your users table for simply handling auth, and using a one to one relationship, you would have an employees table that stores more detailed info about the user.

Jan
03
1 month ago
Activity icon

Replied to How To Perform Complex User Registration

@noblemfd

In my example, all employees are users, so there doesn't need to be a separate table.

Are your "employees" also users? as it looks like they belongTo a single user record.

So not sure, are you just using this employee table to store/link more details about each user? or do the employees not need to be able to log in and are just there to be stored as data? If so I may have misunderstood what you were trying to achieve here

Activity icon

Replied to How To Perform Complex User Registration

@noblemfd

For some reason the spatie link added a braket on the end: https://docs.spatie.be/laravel-permission/v3/introduction

My setup is similar to this

        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('company_id')->index();
            $table->string('first_name');
            $table->string('last_name');
            $table->string('email')->unique();
            $table->string('password')->nullable();
            $table->rememberToken();
            $table->timestamp('email_verified_at')->nullable();
            $table->timestamps();
        });

        Schema::create('company', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name')->index();
            $table->timestamps();
        });

Then in my User model I have:

    public function company()
    {
        return $this->belongsTo('App\Company');
    }

And in my Company model I have:

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

Then, I have changed the create method to in the register controller (overridden from RegistersUsers), to something like:

   protected function create(array $data)
    {
        $company = Company::create([
            'name' => $data['company_name'],
        ]);

        $user = User::create([
            'company_id' => $company->id,
            'first_name' => $data['first_name'],
            'last_name' => $data['last_name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);

        $user->assignRole('admin');

        return $user;
    }

So, I create the company, and then the user (assigning it to the company), and then attach the admin role (using the Spatie package).

The rest of the Laravel register/login system is largely the same as core.

Then, I have a screen where Admins can invite new users, which sends out a similar link to the forgotten password link, that allows them to set their own password (which is why the password field is nullable, it just creates a user entry with a null password, until they set it using the provided link).

Activity icon

Replied to How To Perform Complex User Registration

@noblemfd

I assume this is so you can link users under a company? have admins for a company, etc?

If that is the case, may I suggest an approach that I am using:

I have left the Users table largely the same as the default one, but I have added a company_id to that table.

This links to a Company table/model, and this is what is used to link them up.

So, when the first user signs up, it also creates the company, and they are set as the admin (using https://docs.spatie.be/laravel-permission/v3/introduction).

From there, they can invite other users to join their company, and these following sign ups only create an entry in the users table, with the company id set.

This way, I can filter by the company_id, so that each company admin can see the users within their company, but it means the users/auth system works out of the box.

Dec
09
2 months ago
Activity icon

Awarded Best Reply on How To Have Unique Session Id Per Web Browser's Tab

@drewlim7

You are going to struggle if you keep the ID in a session, very much so with the problems you have suggested.

You could maybe look into using the window.unloadto fire an ajax request that will clear the session, only anything but a next click - but tbh, I am not sure how reliable that would be.

Personally, for a multistep form, I would use something like https://binarcode.github.io/vue-form-wizard/#/ so the form is all within a single page, and just shown/hidden dependant on the step.

If you wanted to persist after each step, you could still fire the ajax request, and then just store the resultant ID in the hidden field and/or a JS variable, to pass along with the next request.

Another option, would be to pass the id via a querystring/post to the next page, but you would need to validate this against the user before continuing, and also if not present, they would have to be redirected back to the first step.

Dec
06
2 months ago
Activity icon

Replied to Laravel Role Based User Management

@brainyprb

I have not used them packages, but have setup a roles/permissions similar using Spatie's package, but had to do it myself.

From what I have seen, these packages generally give you the ability to create/assign roles/permissions, but how you use them is up to you.

All of my actions are controlled by permissions, which are assigned to roles, but I have a 'role level' to indicate the level a user must be at to be able to assign a role/permissions to another user, so something similar to that could be used.

So, if you assigned a level to each of the roles, then you could say any users wholes maximum role <= Auth Users max role (if they can be assigned more than one role).

With my levels, I made sure to leave large gaps inbetween, in case any more levels needs to be added between

Activity icon

Replied to Laravel Auditing For Event Create, Update, Delete By Using Api

@tali

I trialed laravel-auditing when I was first looking at auditing, but I ended up replacing it with https://docs.spatie.be/laravel-activitylog/v3/introduction/ when I wanted to manually log other things.

Activity icon

Replied to How To Have Unique Session Id Per Web Browser's Tab

@drewlim7

You are going to struggle if you keep the ID in a session, very much so with the problems you have suggested.

You could maybe look into using the window.unloadto fire an ajax request that will clear the session, only anything but a next click - but tbh, I am not sure how reliable that would be.

Personally, for a multistep form, I would use something like https://binarcode.github.io/vue-form-wizard/#/ so the form is all within a single page, and just shown/hidden dependant on the step.

If you wanted to persist after each step, you could still fire the ajax request, and then just store the resultant ID in the hidden field and/or a JS variable, to pass along with the next request.

Another option, would be to pass the id via a querystring/post to the next page, but you would need to validate this against the user before continuing, and also if not present, they would have to be redirected back to the first step.

Activity icon

Replied to It Is Possible Route A Url To Different Function?

Following on from what @snapey suggested, if you use a hypen, then you could do something similar to what we do at where I work

Route::get('{name}-p{id}', function($name, $id) {
    dd('product', $name, $id);
});

Route::get('{name}-c{id}', function($name, $id) {
    dd('category', $name, $id);
});

so after the hypen the p or c indicates what route you are intending to hit, and route them to the appropriate controller.

Dec
03
2 months ago
Activity icon

Awarded Best Reply on Github: We Found Potential Security Vulnerabilities In Your Dependencies.

@untymage

Looks like it is just warning you of a vulnerability in the version of symfony/http-foundation that you are using.

So in your composer.lock file it will have one of the versions mentioned in the details section.

And its recommending that you update the version you are using, which if you are already on the 4.3.* version, there shouldnt be any real issue in upgrading.

Activity icon

Replied to Github: We Found Potential Security Vulnerabilities In Your Dependencies.

@untymage

Looks like it is just warning you of a vulnerability in the version of symfony/http-foundation that you are using.

So in your composer.lock file it will have one of the versions mentioned in the details section.

And its recommending that you update the version you are using, which if you are already on the 4.3.* version, there shouldnt be any real issue in upgrading.

Nov
26
2 months ago
Activity icon

Replied to Eloquent With Morph And HasMany

@knubbe

If you are wanitng it by center, you could call it from the center model, and include the buildings, and their damages.

Center::with('damages', 'buildings.damages')->all();

Would get you all the centers, and egar load their damages, and all their damages

You could then use the whereHasMorph option to filter down to ones that have damages https://laravel.com/docs/6.x/eloquent-relationships#querying-polymorphic-relationships

Nov
25
3 months ago
Activity icon

Replied to Generate Serial Number With Current Year And Last Id Automatically Laravel

If it requires the id as part of the reference, I would look to set this using the created event fired by eloquent when a record is created, and update the reference then (so it will need to start as a null value).

https://laravel.com/docs/6.x/eloquent#events (or observers https://laravel.com/docs/6.x/eloquent#observers)

so in your event handler, you would just do something like:

$record->update([
    'serial_number' => 'Bill19-20-' . $record->id
])

And the 19-20 you would just need to add based on the dropdown selected.

Nov
22
3 months ago
Activity icon

Replied to Filter Models By Relationship Existence

@mirasmustimov

If you set up a foreign key on your pivot table, you can have it delete the entry from there when the product is deleted. https://laravel.com/docs/6.x/migrations#foreign-key-constraints

Alternatively, you could use an event to hook into when the product is being deleted, and delete the entry from the pivot table.

This way, your kits will only have products remaining in them, and you can just not show (or have some clean up) if the kit has no products left.

Another option, with a bit more work involved, would be to instead soft delete the products, and then on any kit, if the products are soft deleted, you could show recommended alternative products - which would require either manually setting alternative products to show when deleting, or some sort of algorithm. But it would act as a way to potentially retain users with those products in their kits.

Nov
20
3 months ago
Activity icon

Awarded Best Reply on Laravel Authentication

Hi @paduraruionutandrei

I am building something similar, but I have done it in the opposite way.

I have kept the users table as normal, and used that for the normal Laravel Auth, but then added a company_id to the users table.

So in the same way, a User will belong to a Company, and a Company will have many Users.

Then all the things that are linked to the company, have the user_id and/or the company_id added to it (which allows me, with permissions, allow some users to only see there own stuff, but company Admins to see stuff for all users in that company).

Nov
18
3 months ago
Activity icon

Replied to Avoid Deleting Parent Table Data While It Is Being Used In Child Table

@usmanbasharal

If you setup foreign keys (on the employee table), you can set them to prevent it deleting

$table->foreign('nationality_id')
                ->references('id')
                ->on('nationalities')
                ->onDelete('restrict');

https://laravel.com/docs/6.x/migrations#foreign-key-constraints

This would throw an error when trying to delete, which you are already handling with your JS.

If you didnt want to leave this down to the database to prevent, then in you delete method of your controller, you could preform a check to see if it has any employees assigned to it` and if it does, manually throw an error (that your JS is already catching)

Nov
15
3 months ago
Activity icon

Awarded Best Reply on Laravel Trying To Write Log Files To Local Project Location Instead Of Remote

@ctyler

Im not sure where it gets it from exactly, but it seems to be based on the basePath - which I assume it works out as part of the application boot.

if you are uploading files automatically, and it does have something to do with composer, then that Might explain it, at the very least it would be worth trying to run composer dumpautoload on the server.

Activity icon

Replied to Laravel Trying To Write Log Files To Local Project Location Instead Of Remote

@ctyler

Im not sure where it gets it from exactly, but it seems to be based on the basePath - which I assume it works out as part of the application boot.

if you are uploading files automatically, and it does have something to do with composer, then that Might explain it, at the very least it would be worth trying to run composer dumpautoload on the server.

Nov
13
3 months ago
Activity icon

Replied to How To Create Multiple Route::domain With The Same Routes?

@martinzeltin if the routes for these are going to be the same (as not sure if you can do it as you have suggested, and have never used the domain method, but that looks like its meant for sub domains).

But you could try something like below (untested) in the RouteServiceProvider

        Route::middleware('web')
             ->namespace($this->namespace)
             ->domain('www.first.com')
             ->group(base_path('routes/web.php'));

        Route::middleware('web')
             ->namespace($this->namespace)
             ->domain('www.second.com')
             ->group(base_path('routes/web.php'));

So it loads the same routes in twice under the 2 domains.

Like I said though, this is untested, so not sure if it woud work

Nov
12
3 months ago
Activity icon

Replied to URL & CSS Folder Same Name Problem

@kkhicher1

If you really want /css to be a url (assuming for a page), then the easy option would be to move the css folder, maybe into something like assets/css