AshleyP

AshleyP

Member Since 2 Years Ago

Experience Points
3,250
Total
Experience

1,750 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
28
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 1
3,250 XP
12 Apr
5 months ago

AshleyP left a reply on Response->json($array) Giving Out Too Much Input And Not Just Json?

@STEREOH - Oh...wow...

Stereoh thankyou so much! I've been trying to find this for nearly 2 hours!

AshleyP left a reply on Response->json($array) Giving Out Too Much Input And Not Just Json?

Hmm - Maybe it's an issue with guards...

AshleyP left a reply on Response->json($array) Giving Out Too Much Input And Not Just Json?

@TYKUS - Thanks TYKUS. This is my ApiLoginController that i'm overriding some functions. Am I doing something really dumb?:

class ApiAuthentication extends Controller
{

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function index(Request $request)
    {
        $this->login($request);
    }


    public function login(Request $request)
    {

        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

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

        if ($this->attemptLogin($request)) {

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

        $this->incrementLoginAttempts($request);

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

    protected function sendLoginResponse(Request $request)
    {
        return $this->authenticated($request, $this->guard()->user());
    }

    protected function authenticated(Request $request, $user)
    {
        if ($user) {
            $token = Str::random(16);
            $user->api_token = $token;
            $user->save();
            $authentication_array = ['api_token' => $token];
            echo(response()->json($authentication_array));
        }
    }

    protected function guard()
    {
        return Auth::guard();
    }
}

AshleyP left a reply on Response->json($array) Giving Out Too Much Input And Not Just Json?

@TYKUS - Thanks for the response!!!

Oh, I was running this in the "authenticated" section of the LoginController:

protected function authenticated(Request $request, $user)
 {
        if ($user) {
            $token = Str::random(16);
            $user->api_token = $token;
            $user->save();
            $authentication_array = ['api_token' => $token];
            return response()->json($authentication_array);
        }
 }

Which if I return then nothing echos out. Where should I output the api_token after login?

AshleyP started a new conversation Response->json($array) Giving Out Too Much Input And Not Just Json?

Hi,

I'm hoping for a clean response using:

$authentication_array = ['api_token' => $token];
echo response()->json($authentication_array); 

Like so:

{"api_token":"n4dmXOAjWwmt3mOR"}

Instead I get this:

HTTP/1.0 200 OK Cache-Control: no-cache, private Content-Type: application/json Date: Fri, 12 Apr 2019 09:39:51 GMT {"api_token":"n4dmXOAjWwmt3mOR"}

Any idea what I need to edit?

09 Apr
5 months ago

AshleyP started a new conversation Prevent Multiple Logins

HI there,

So I'm using jwt authentication currently, and laravel as an api. I want to prevent a user logging in on multiple devices.

If one device logs in, it should log the other out.

I've thought about adding the JWT token to the database of the user, and then if an api call is made and the token is different to the one stored, it logs them out.

Is there any advice on whether this is a good mechanism?

Thankyou :)

05 Apr
5 months ago

AshleyP started a new conversation Laravel - Where To Find Minimum Mysql Version?

Hi,

I've ploughed the documentation and I can't find the minimum mysql version for laravel. My server requires 5.6 mysql and I also want to use laravel nova - so I need to use laravel 5.6.

How do I find the minimum mysql version?

Thanks

09 Dec
9 months ago

AshleyP started a new conversation Nova - Tabs And Displaying Data

Hi all,

So, I wanted to update the User Detail view to show some data for a user. I have a table called user_game_results and a table called user_test_data (which in the tables it contains the user id and then a json column with the data).

I wanted to have two tabs that could be pressed to show the game results in one tab and the test results in another tab.

I have a custom method of visualising the results that I want to add. One is in a line graph the one is a d3 visualisation.

At first I thought - a 'Resource' tool should enable me to customise a view and add it to the user detail view. But then I realised that it wouldn't enable me to put this into tabs.

Any suggestions on how best to approach adding custom data visualisations into tabs in nova?

Thanks =)

18 Sep
2 years ago

AshleyP started a new conversation Validation: Ranking Items.

Hi,

I currently have these rules - and the user is asked to rank Workshops/mentoring/tutoring in order of their preferences.

 'workshops' => 'required|different:tutoring|different:mentoring',
 'tutoring' => 'required|different:workshops|different:mentoring',
 'mentoring' => 'required|different:tutoring|different:workshops',

This was working well...until I added a 4th option which was "Not interested"...so now the "different" no longer works because all 3 options could be "Not interested".

So, I need to create a validation rule which means that these 3 are ranked in order or preference.

I've looked at the custom validation rules in laravel documentation:

https://laravel.com/docs/5.0/validation#custom-validation-rules

But i'm really quite confused where the custom validation extend thing goes.

Could I ask, firstly where this is meant to go(and how I should know this, i've probably completely missed some part in the documentation somewhere)? Or if there is another validation option for laravel for ranking (or a better solution that a custom rule)?

Thankyou :)

02 Sep
2 years ago

AshleyP left a reply on Where Is The Register View Loaded?

@Snapey thankyou Snapey I understand now!

AshleyP left a reply on Where Is The Register View Loaded?

hi @ejdelmonico ,

Thankyou for you response =).

I don't need to override the create user - as it already adds the user type. I need to redirect from the registration page to another page if the url doesn't contain a parameter a?

(I may have misunderstood your response, sorry!)

AshleyP started a new conversation Where Is The Register View Loaded?

Hi,

I'm wondering how the auth.register view is loaded! I can find the Register controller - but there is nothing in here which indicates "store" user.

I found showRegistrationForm() (in the RegistersUsers.php) but in here I can't get the request information.

    public function showRegistrationForm()
    {
    return view('auth.register');   
    }

The reason I ask is because we have a parameter in the registration: http://laravel.app/register?a=mentor http://laravel.app/register?a=student

At the moment in the view we get the parameter a and generate an input type. But I'd like to have something that says:

    if(a == null)
        redirect()

I could put this in the view I suppose. But wondering if there was a better way?

Thankyou :)

02 Aug
2 years ago

AshleyP left a reply on Invalid Argument Supplied For Foreach() When Using ToJSon

(totally in accident realised I can toArray this. Whoop!! Thankyou!)

AshleyP left a reply on Invalid Argument Supplied For Foreach() When Using ToJSon

@36864 wow thankyou so much for taking the time to do that! Have a much better understanding of these relationships and how useful they are!

I'm a bit stuck on the last part though - which is get the "accepted_date_times" from the "users_schedules" table.

So I can see this:

Auth::user()->ownedSchedules->first()->users;

Which will get me a list of user's for first (owned) schedule.

So I updated user's to this:

public function users() { return $this->belongsToMany(User::class, 'users_schedules', 'schedule_id', 'user_id')->withPivot('accepted_date_time'); }

So now I have this pivot:

accepted_date_time: "["2017-08-01 16:12:09", "2017-08-01 16:12:09", "2017-08-01 16:12:09"]

And when I do:

$user->ownedSchedules()->first()->users

I get the following result:

$user->ownedSchedules()->first()->users
=> Illuminate\Database\Eloquent\Collection {#770
     all: [
       App\User {#787
         id: 1,
         first_name: "Bob",
         last_name: "Bobby",
         email: "[email protected]",
         created_at: "2017-08-01 16:12:09",
         updated_at: "2017-08-01 16:12:09",
         pivot: Illuminate\Database\Eloquent\Relations\Pivot {#777
           schedule_id: 1,
           user_id: 1,
           accepted_date_time: "["2017-08-01 16:12:09", "2017-08-01 16:12:09", "2017-08-01 16:12:09"]",
         },
       },
       App\User {#764
         id: 2,
         first_name: "Donkey",
         last_name: "Parcel",
         email: "[email protected]",
         created_at: "2017-08-02 11:08:52",
         updated_at: "2017-08-02 11:08:52",
         pivot: Illuminate\Database\Eloquent\Relations\Pivot {#782
           schedule_id: 1,
           user_id: 2,
           accepted_date_time: "["2017-08-01 16:12:09", "2017-08-01 16:12:09", "2017-08-01 16:12:09"]",
         },
       },
     ],
   }

But I'm not really sure how to make it look like this:

 0 => {#265 ▼
    +"id": 1
    +"state": "unconfirmed"
    +"created_user_id": 1
    +"event_name": "My Event"
    +"event_details": "Details of My event"
    +"address1": "4 Holmside Rise"
    +"address2": "4 Holmside rise"
    +"postcode": "wd197qx"
    +"users" : [{ user_id: 1, username: "Bob", accepted_dates: [ Monday, Tuesday, Wednesday]},  { user_id: 2, username: "Joe", accepted_dates: [Tuesday, Wednesday, Thursday]}, ]
    +"dates": array:2 [▶]
    +"created_at": "2017-08-01 16:12:09"
    +"updated_at": null
  }

When I do

$user->ownedSchedules()->first()->get()

Sorry does this make sense?

AshleyP left a reply on Invalid Argument Supplied For Foreach() When Using ToJSon

@36864

Thanks for your reply!

Well - I have a "schedules" table. This contains the user_id of the user whom created it but not the user's who are added to it. The user's who are added to it can then select the time they are free (like doodle).

Then I have a "user_schedules" table - which has

added_user_id, schedule_id, accepted_date_times

I guess the reason I was converting to json was so that I could get a list of all the user's who were added to a particular schedule - and their accepted date times. Alongside the schedule so that I get something like this in the result:

 0 => {#265 ▼
    +"id": 1
    +"state": "unconfirmed"
    +"created_user_id": 1
    +"event_name": "My Event"
    +"event_details": "Details of My event"
    +"address1": "4 Holmside Rise"
    +"address2": "4 Holmside rise"
    +"postcode": "wd197qx"
    +"users" : [{ user_id: 1, username: "Bob", accepted_dates: [ Monday, Tuesday, Wednesday]},  { user_id: 2, username: "Joe", accepted_dates: [Tuesday, Wednesday, Thursday]}, ]
    +"dates": array:2 [▶]
    +"created_at": "2017-08-01 16:12:09"
    +"updated_at": null
  }

So I guess I felt converting it to json then added the "users" part would be the best idea?

AshleyP started a new conversation Invalid Argument Supplied For Foreach() When Using ToJSon

So I get my results from the database and convert them to json:

$schedules = Schedule::find($users_schedules_ids);
$schedules = $schedules->toJson(); 

However when I then try and display them in blade:

 public function index() {
        $schedules = $this->getSchedules(Auth::user()->id);
        return view('schedules.index', compact('schedules'));
    }

I get this: Invalid argument supplied for foreach()

So OK - I look and see that toJson is a string. Fair enough, can't loop through a string. So I convert it and now I get this:

"Array to string conversion"

Well OK...it should be an array. Dumping gives me this:

array:2 [▼
  0 => {#265 ▼
    +"id": 1
    +"state": "unconfirmed"
    +"created_user_id": 1
    +"event_name": "My Event"
    +"event_details": "Details of My event"
    +"address1": "4 Holmside Rise"
    +"address2": "4 Holmside rise"
    +"postcode": "wd197qx"
    +"dates": array:2 [▶]
    +"created_at": "2017-08-01 16:12:09"
    +"updated_at": null
  }
  1 => {#273 ▼
    +"id": 2
    +"state": "unconfirmed"
    +"created_user_id": 1
    +"event_name": "My Event 2"
    +"event_details": "Details of My event"
    +"address1": "4 Holmside Rise"
    +"address2": "4 Holmside rise"
    +"postcode": "wd197qx"
    +"dates": array:2 [▶]
    +"created_at": "2017-08-01 16:12:09"
    +"updated_at": null
  }
]

So why doesn't blade want to loop through it?

(I'm trying to cast to json so I can insert another result i.e an additional list of dates called "accepted dates", which will be an array or accepted dates).