meredevelopment

meredevelopment

Member Since 4 Years Ago

Experience Points
9,600
Total
Experience

400 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
86
Lessons
Completed
Best Reply Awards
0
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 2
9,600 XP
Oct
16
4 days ago
Activity icon

Started a new Conversation Handling Null Object Values Passed In Prop

Hi, I'm passing an Object (a Laravel collection) to vue like this:

<contract-details :passed-application="{{ $application }}"></contract-details>

and running into problems when certain elements of the object are null. In order to manipulate the elements the way I want to (Validation, reactivity etc) it seems to be easier to make them strings like "".

I have it working, but it smells wrong, and I think there might be a better way to do it. Primarily I guess my questions are:

  1. Is this.passedApplication.contract_value == null) ? "" : this.passedApplication.contract_value the most efficient way to do this check? (assuming we can't use ?? yet in the wild)

  2. In the Validation config, value can be all over the shop. Number, String, Null (object). This is why I'm using toString(). Is there a better approach?

Stripped down example here.

export default{
    props: {
        passedApplication: {
            type: Object,
            required: true,

            contract_value: {
                type: String,
                default: null,
            },

            deposit_amount: {
                type: String,
                default: null,
            }
        },
    },

    data() {
        return {
            application: {
                contract_value: (this.passedApplication.contract_value == null) ? "" : this.passedApplication.contract_value,
                deposit_amount: (this.passedApplication.deposit_amount == null) ? "" : this.passedApplication.deposit_amount,
            },
        }
    },

    validations() {
        return {
            application: {
                contract_value: {
                    required,
                    maxValue: function(value) {
                        return value.toString().replace(/[^\d]/g, "") <= 30000;
                    },
                    minValue: function(value) {
                        return value.toString().replace(/[^\d]/g, "") >= 1;
                    },
                    money,
                },
                deposit_amount: {
                    required,
                    maxValue: function(value) {
                        return value.toString().replace(/[^\d]/g, "") <= (this.application.contract_value / 10);
                    },
                    minValue: function(value) {
                        return value.toString().replace(/[^\d]/g, "") >= 1;
                    },
                    money,
                },
            },
        }
    },
}

Thanks!

Sep
05
1 month ago
Activity icon

Started a new Conversation Mailed Notifications Don't Use 'mail.markdown.theme' Setting...

Hi, I'm using a custom theme for my markdown Mailables which works fine.

But Notifications don't get the custom theme and I can't work out why.

Here's an example if you want to test:

Create resources/views/vendor/mail/html/themes/mytheme.css and make an obvious change:

.body {
    background-color: red;
    /* etc... */
}

Set theme in config/mail.php:

'markdown' => [
    'theme' => 'mytheme',

    'paths' => [
        resource_path('views/vendor/mail'),
    ],
],

Create Notifications/ThemeTestNotification.php:

// etc...
public function toMail($notifiable)
{
    return (new MailMessage)
                ->line('This is a theme test.')
                ->action('Test button', url('/'));
}
// etc...

Add a test route to routes/web.php:

Route::get('mailtest', function () {
    Notification::route('mail', '[email protected]')
        ->notify(new App\Notifications\ThemeTestNotification());
});

The resulting emailed notification WON'T have the new theme...

If the theme method is used to set the theme manually - as per docs - inside the notification like so:

public function toMail($notifiable)
{
    return (new MailMessage)
                ->theme(config('mail.markdown.theme')) //this is pulling the one set in mail config, but it could be set directly to 'mytheme'.
                ->line('This is a theme test.')
                ->action('Test button', url('/'));
}

...then the new theme WILL be used.

I guess my question is: Why doesn't Notifications just respect the setting in mail config. Is this worth flagging as a bug/enhancement? Or have I just got it all wrong (again).

Thanks!

Sep
01
1 month ago
Activity icon

Replied to Allowing Session-based Users To Access API - Is There A Nicer / Safer Way?

Thank you @audunru and @pciranda, I had completely overlooked CreateFreshApiToken in the docs. It's working perfectly!

Aug
30
1 month ago
Activity icon

Started a new Conversation Allowing Session-based Users To Access API - Is There A Nicer / Safer Way?

I have a Passport protected API as part of a public-facing App, with external parties connecting with Personal Access Tokens. This ideally needs to stay as-is.

'Users' with accounts (plain old username/pass) also login to this App, and need to query some parts of the API with Vue in Views. This is where I'd like help and suggestions please:

At present I have the following sort of setup:

api.php

Route::group(['middleware' => 'auth:api'], function () {
    Route::apiResources(
        [
            'example' => 'API\ExampleController',
            // all the other resources

        ],
        ['except' => ['destroy']]
    );
});

web.php

Route::group(['middleware' => 'auth'], function () {
    Route::resources(
        [
            'example' => 'API\ExampleController',
            // all the other resources
        ],
        ['only' => ['index','show']]
    );
});

And in Views I'm doing stuff like this:

axios.get('/members/'+this.query)
.then(response => {
    // etc
})
.catch(error => {
    // etc
})

This all works fine... but a few questions:

  • Is there a way to not have to list all the Resources/Controllers in both Routes files? Maybe a way to import them from one place? I did attempt to add the EncryptCookies and StartSession middleware to the api group in Kernel.php but no luck, I get not authenticated errors when GETing the data.

  • Is this sort of access to the API via a session safe? I have the appropriate CSRF fields added to the Axios config (as it is out the box these days).

  • Finally, it strikes me that this sort of setup, i.e. having both an API and local users on one App must be quite common? How are others doing it if not this way?

Thanks for reading 👍

Activity icon

Replied to AuthenticateSession Middleware

Just a small note that AuthenticateSession is now partially documented here: https://laravel.com/docs/5.8/authentication#invalidating-sessions-on-other-devices

However @kfirba's article does a fantastic job of actually explaining it!

Aug
22
1 month ago
Activity icon

Replied to Using Passless Driver For Passwordless Login AND Registration.

Fixed it! Just in case someone has a similar problem, I had to make the auth attempt directly, and only then was the Passless driver used.

In my RegisterController I swapped:

$this->guard()->login($user);

with

Auth::attempt($user->only('email'));

(making sure to add use Illuminate\Support\Facades\Auth; to the opening declarations)

Aug
21
1 month ago
Activity icon

Replied to Using Passless Driver For Passwordless Login AND Registration.

I've not found a fix to this yet. I asked the Passless developer for suggestions and his reply looked hopeful, but I think I've misunderstood the instructions.

If anyone here is familiar with Passless please take a look at the issue: https://github.com/DarkGhostHunter/Passless/issues/10

Thank you.

Activity icon

Replied to Passing Additional Data To The Registered Event

Thanks! Ok I've gone with the first option and ended up with two events being fired by the RegisterController which works fine:

event(new Registered($user = $this->create($request->all())));
event(new UserCreated($user, $validated['memnum']));
Aug
19
2 months ago
Activity icon

Started a new Conversation Passing Additional Data To The Registered Event

I'm using my own register function in RegisterController.php:

public function register(Request $request)
{
    // Gets validated request data.
    $validated = $this->validator($request->all())->validate();

    // Checks if member is migrated to this system. If not passes to old system.
    $member = new Member;
    if (!$member->migrated($validated['memnum']))
    {
        return redirect()->away('http://example.com?' . http_build_query($validated));
    }

    // Creates new user and passes it to registered event. ALSO WANTS TO PASS Member Number.
    event(new Registered($user = $this->create($request->all()), $validated['memnum']));

    $this->guard()->login($user);

    return $this->registered($request, $user)
        ?: redirect($this->redirectPath());
}

The registration form has a new field for memnum, which I don't want to be part of the User record in the DB, but I do need to collect at registration time.

I have a listener setup to fire on Registered events, and this listener needs access to both $user and $memnum.

I can't work out how to get $memnum to the listener without sending it as an Event arg. Plus for my code above to work, I need to edit Illuminate\Auth\Events\Registered and add $memnum as a public... whatever it's called. Obviously I can't do this (hack the core).

I could fire a second custom event after event(new Registered ... but... it just seems messy.

Any better ideas? Thanks!

Jul
12
3 months ago
Activity icon

Replied to Using Passless Driver For Passwordless Login AND Registration.

Thanks for the suggestion but I spent quite a while trying to use the bundled verification without password and getting it to auto-login after the verification link is clicked and... nope. Days of pain. As the Passless driver works so well for the login I'd love to get that working after registration too.

Activity icon

Started a new Conversation Using Passless Driver For Passwordless Login AND Registration.

I'm using https://github.com/DarkGhostHunter/Passless for password-less login. It works as expected, users can login by entering their email address, then clicking on a link in the a validation email that get's sent.

When it comes to registration, by default when users register they are automatically logged-in. Instead I want to generate the same type of validation email that's generated at login so they have to wait for email.

I can't work out why the RegistrationController's register method doesn't already do this?

To explain a bit more: In my RegistrationController I have this function (copied from core):

public function register(Request $request)
    {
        $this->validator($request->all())->validate();
        event(new Registered($user = $this->create($request->all())));

        $this->guard()->login($user);

        return $this->registered($request, $user)
                        ?: redirect($this->redirectPath());
    }

The line $this->guard()->login($user); uses - I believe - the same login method that LoginController does, so I don't understand why the new driver isn't being used.

My grasp of Laravel Auth is thin, I'm trying to understand it more!