Snapey

at Novate / Microlise

Member Since 5 Years Ago

Mansfield

Experience Points
1,675,115
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
1275
Lessons
Completed
Best Reply Awards
2366
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,675,115 XP
Apr
02
15 hours ago
Activity icon

Replied to Why Eloquent Result OrderBy Is Not Influenced By Collection SortBy

so everything else is pretty much irrelevant apart from

$results = $results->sortByDesc(function ($result, $key) {
	return $result -> xyz;
});

You have a collection of models. You add an extra value to each model? then sort.

What does $results look like before and after this function

Activity icon

Replied to Return "back()" Or "redirect()" Doesn't Stop The Main Function Execution

back is not some magic method that whisks you off somewhere else.

Your return goes back to whatever called checkStripe()

If that caller is not expecting a redirect as a response, then it will just ignore it.

Activity icon

Replied to Map Attributes To Model Fields

when you get() from the model, you can specify the attributes you want?

->get(['id','user'])

or use makeHidden https://laravel.com/docs/7.x/eloquent-collections#method-makeHidden

Activity icon

Replied to Having Trouble Looping Through Array In Blade (object Was Decoded From Json)

Maybe not all attributes have pizzaIngredients, or not all items have attributes?

try

@foreach($item->attributes->pizzaIngredients ?? [] as $ingredient)

@endforeach
Activity icon

Replied to Trying To Get Property 'orders' Of Non-object

start by considering WHAT you are trying to put in that table cell.

Activity icon

Replied to RPassword Manually By Answering The Security Questions - Laravel/auth

You cannot call Auth::user() if they are not logged in (well you can but you will just get null).

A user that cannot remember their password cannot be logged in.

Therefore you need to use a different layout file, or wrap your use of Auth::user with a check to see if they are logged in.

See Authentication Directives on this page https://laravel.com/docs/7.x/blade

eg

@auth
	Welcome {{ Auth::user()->name }}
@endauth

Sort this out first, then you can concentrate on fixing password reset

Activity icon

Replied to Laravel - Access Denied For User

and also no # characters - easier and safer to just quote the string

Activity icon

Replied to Build Relation Of Two Table And Apply OnDelete('cascade). It's Not Working

Mark Tray2's answer correct, not your own

Activity icon

Replied to RPassword Manually By Answering The Security Questions - Laravel/auth

Your error message provides vital information about WHERE the error is occuring

Its in the layouts.blade.php file - not any of the code you show here.

You are probably trying to display something about the user - perhaps their name - in the page header, but they are not logged in.

Also, in the code you do show, you have this line

$user = User::first();

Just gets the very first user in the system. Are you expecting to only have one user?

You should find the user by their email address and then get rid of the later check

$user = User::where('email', $request->email)->first();
Activity icon

Replied to Laravel- Scan QR Code For Customer To Verify

You need to make sure that the hash is suitable for encoding in a URL (only uses url safe characters)

Or, use a long random token, or signed URLs

Activity icon

Replied to Laravel- QR Code Hash

use a signed URL then you don't need a hash at all, and it is automatically checked for you

https://laravel.com/docs/7.x/urls#signed-urls

Activity icon

Replied to Impossible To Create The Root Directory

Yes, depending on if you want public visibility of the file, as per your other question.

Activity icon

Replied to How To Change The Password Reset Validation

@donclemenzo doesn't work for YOU? Why not start a question with your own circumstances and explain what 'doesn't work' means

Activity icon

Replied to Unable To Store Pdf File Into Storage Folder

If you don't need to access the PDF from a web page, then yes, put it in storage/app and not storage/app/public

Activity icon

Replied to Trying To Get Property 'orders' Of Non-object

You are overlooking the effect of multiple relations

if item has orders (plural) then you cannot chain items or product from there because there are many of them

Activity icon

Replied to Customizing The Laravel Verify Email

I did it in a Laravel 6 project and posted the code above.

I did find it was difficult to get the string to match. I had to put it all on one line.

Make sure you start with the string in the notification email of the version you are using.

Apr
01
1 day ago
Activity icon

Replied to Pass Ip And User_id In Every Store Model

You can create an observer that acts on model creating and updating

https://laravel.com/docs/7.x/eloquent#observers

Activity icon

Replied to Map Sum Of Collection

You can do this in the database, but if you don't want to do this, use reduce not map.

Activity icon

Replied to Trying To Get Property 'orders' Of Non-object

whenever you have more than one arrow in an expression, should defend against one of the objects being null.

so, if $item has no orders then your code will blow up

It may not be the first item, or the second, but could be the fourth, the tenth or the last. Any of them null and the page blows up and you don't see any.

Don't dismiss @burimb advice because it is good.

Personally, I always use the null coalesce operator, so write the line as

<td >{{$item->orders->items->product->parentProduct->id ?? ''}}</td>

even if this does not fix your problem, its still better code.

I have to say though that this chain is extremely fragile, and unless they are all one to one then your code will break.

if item has orders then this implies a 1:many relationship so you cannot get items from orders since there are many of them to choose from. Which order do you want to use?

Activity icon

Replied to Impossible To Create The Root Directory

You should write the file to storage/app/public, and then symlink it to the public/storage folder.

This is because your webserver should have permission to write to the storage folder and not the public folder

Activity icon

Replied to Please Help With Route!

Please format your code by putting 3 backticks ``` on a line before and after each code block

Activity icon

Replied to Unable To Store Pdf File Into Storage Folder

are you looking in;

storage/app/public/storage/documents/invoice

This assumes that in config/filesystems, that default disk is 'local', and this resolves to storage/app

You can confirm this by opening tinker and typing config('filesystems')

Activity icon

Replied to Add Authenticated User_id To Create Method With Validation

one way is to leverage relationships

  $origin = Auth::user()->origins()->create(request()->validate([
            'name' => 'required',
            'url' => 'required|url',
        ]));

Eloquent will automatically apply the user_id to the origin record (this assumes that user model has a origins function

clarification

this

Auth::user()->origins()

is the same as

auth()->user()->origins()

is the same as

$request->user()->origins()
Activity icon

Replied to These Credentials Do Not Match Our Records. (Log In) (Laravel)

The most likely problem is a mismatch in the number of times the password is hashed.

Its either twice when registering (thus destroying the password), or

its hashed twice when logging in so does not match the database.

This can be caused by one of the following being the case;

  • The User model has an accessor that automatically hashes the password, but you are doing it outside of the model also
  • The User model has an observer on creating that automatically hashes the password, but you are doing it outside of the model also
  • Your login script is hashing the password then passing it to the check function (when it is not required to hash first)

None of the above should be a problem when using out of the box authentication - it just works.

So, it must be something you have changed.

But first things first, you should check that your credentials are correctly being passed to the login controller.

Activity icon

Replied to The DELETE Method Is Not Supported For This Route. Supported Methods: GET, HEAD, POST.

You need to pass the ID into the modal. Not the simplest solution, so I would avoid this if you are not comfortable with Javascript.

Activity icon

Replied to Customizing The Laravel Verify Email

good. Glad you were able to sort it out. Sorry, I had gone for dinner.

Activity icon

Awarded Best Reply on Customizing The Laravel Verify Email

Hi

You have two options.

1.Publish the email templates. php artisan vendor:publish and select Notifications

review the template that is now in resources/views/vendor/notifications/email.blade.php

You will see lines

@lang('Regards')

and

@lang(
    "If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\n".
    'into your web browser: [:actionURL](:actionURL)',
    [
        'actionText' => $actionText,
        'actionURL' => $actionUrl,
    ]
)

You can just delete these lines or change them for the exact wording that you want. Bear in mind that this email template is the default for all notifications.

2.Change the strings in the translation files. see https://laravel.com/docs/7.x/localization#using-translation-strings-as-keys

I'm assuming the only language you have is english ('en') If you are using other or multiple languages, adapt to suit.

create a file en.json in the lang folder

add the translations, specifying the exact string that is in the email and its replacement

{
    "Regards": "Bestu kveðjur",

    "If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser: [:actionURL](:actionURL)":
    "Open this email :actionText in your browser mate [:actionURL](:actionURL)"

}

You only need to use method 1 or method 2, but use both methods if you need to send out the email in the user's language.

Activity icon

Replied to Customizing The Laravel Verify Email

Hi

You have two options.

1.Publish the email templates. php artisan vendor:publish and select Notifications

review the template that is now in resources/views/vendor/notifications/email.blade.php

You will see lines

@lang('Regards')

and

@lang(
    "If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\n".
    'into your web browser: [:actionURL](:actionURL)',
    [
        'actionText' => $actionText,
        'actionURL' => $actionUrl,
    ]
)

You can just delete these lines or change them for the exact wording that you want. Bear in mind that this email template is the default for all notifications.

2.Change the strings in the translation files. see https://laravel.com/docs/7.x/localization#using-translation-strings-as-keys

I'm assuming the only language you have is english ('en') If you are using other or multiple languages, adapt to suit.

create a file en.json in the lang folder

add the translations, specifying the exact string that is in the email and its replacement

{
    "Regards": "Bestu kveðjur",

    "If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser: [:actionURL](:actionURL)":
    "Open this email :actionText in your browser mate [:actionURL](:actionURL)"

}

You only need to use method 1 or method 2, but use both methods if you need to send out the email in the user's language.

Activity icon

Awarded Best Reply on Cleaner Way To Write This Code?

If the user can only be employee or admin then don't have a roles relationship. Have a single role.

If someone can be both employee and admin then these could be in either order, so roles[0] could be admin or employee, depending on the order they were created in.

If user can have multiple roles, then get the roles and see if they 'contain' the role you are looking for.

Activity icon

Replied to Cleaner Way To Write This Code?

so if the user can only have a single role, why have you set it up with a roles() relationship

sounds like the user model should have a role() method, which is a belongsTo the role model and requires a 'role_id` column on the user.

Then you don't need to use role[0] and hope its correct.

Activity icon

Replied to How To Do Insertions Correctly In Laravel 6 ?

models make it very easy to use a pivot table since you can ignore them.

Suppose you have a model User and a model Role. Since user can have many roles, and role can have many users, a Many to Many condition exists, which requires the use of a Pivot table.

A table role_user is created with user_id and role_id columns pointing to the relevant models

Each model has a relationship, belongsToMany to tell eloquent to find related models through the pivot

Assuming both $user and $role exist, one way to join them and create an entry in the pivot table would be for instance

$user->roles()->attach($role);
Activity icon

Replied to Laravel Validations Doesn't Accept Some Emails Formats

They are probably failing because of the dns element of the check. You cannot have an email address @ a top level domain

Activity icon

Replied to Are The Laracasts Php Tutorials Enough To Learn Php?

I don't think you will pick it up first go. You have to take information from multiple sources and then gradually the pieces fall into place. You may need to go over the videos again at a later date because then things make more sense.

The only real way to learn php (or any language) is to write code and read code, over and over.

Sorry if you expected a perfect solution.

Also look at tutorials on youtube; Academind, Coder's Tape, The Net Ninja, Andre Madarang to name a few

Activity icon

Awarded Best Reply on Laravel 5.5 Observer

in your observer you need to import App\Activity

use App\Activity;

at the moment it is looking for the class in its own namespace

edit: I see you have done this, but you have a typo

Activity icon

Replied to Laravel 5.5 Observer

in your observer you need to import App\Activity

use App\Activity;

at the moment it is looking for the class in its own namespace

edit: I see you have done this, but you have a typo

Activity icon

Replied to Easiest Way ??

use $request->only() and pass the function just the relevant fields

Activity icon

Replied to The DELETE Method Is Not Supported For This Route. Supported Methods: GET, HEAD, POST.

in your form, you don't say what you want to delete

<form method="POST" >
          @csrf
          @method('delete')

you should set an action and the id of the thing being deleted

Activity icon

Replied to Cleaner Way To Write This Code?

its not about how many roles you have, its about how many roles a user can have

Activity icon

Awarded Best Reply on How To Send Image Link From Laravel Storage To Frontend(angular)

open tinker

>>> $u = App\User::find(1)     //insert valid user number

>>> $u->profile_picture;

>>> asset($u->profile_picture);

what do you get

Mar
31
2 days ago
Activity icon

Replied to Relationship GroupBy In Initial Query

The other thing I thought of was a courses relationship on Location which is a hasManyThough passing through entrees, you could then simply do $location->load('courses.entrees') and not bother with the grouping

Activity icon

Replied to Relationship GroupBy In Initial Query

personally, I would probably have course as an attribute of entree, not a separate model, bit I admit, I dont have the full knowledge of what you need to do.

Activity icon

Replied to Relationship GroupBy In Initial Query

this code should not do this, as your entrees are related to a single location?

do the query in tinker, and count the results to check its as expected

Activity icon

Replied to Relationship GroupBy In Initial Query

hmm, tricky

So you want to group entrees by the course?

Its hard to visualise, it seems a bit back to front. I would probably get location with eager load entrees.course and then group entrees by its course using a collection method.

    $entrees = $location->entrees()->with('course')->get();

    $grouped = $entrees->groupBy(function($entree){
                   return $entree->course->name;
               });

similar to yours, but loading the course.

Activity icon

Replied to Relationship GroupBy In Initial Query

can you explain the relationships between the models?

Activity icon

Replied to Relationship GroupBy In Initial Query

sort or group?

Activity icon

Replied to Cleaner Way To Write This Code?

If the user can only be employee or admin then don't have a roles relationship. Have a single role.

If someone can be both employee and admin then these could be in either order, so roles[0] could be admin or employee, depending on the order they were created in.

If user can have multiple roles, then get the roles and see if they 'contain' the role you are looking for.

Activity icon

Replied to Session, Logout/Login Question, Countdown To Log Back In

Sorry to complicate things, but this breaks when the user has two tabs open. One they are working in, with 45 minutes of session left, and another tab which is saying that their session is/has expired. The timers in your pages are not linked in any way so one can be counting down and the other reset with each interaction.

Activity icon

Replied to Session, Logout/Login Question, Countdown To Log Back In

everytime you hit the back-end (for whatever reason) reset the timer back to 45 minutes, and of course when the page is reloaded.

I don't understand why you are showing server code. You cannot do anything at the server to get the session duration because as I said, it will always be reset to 45 minutes in response to a request.

The only way you can push anything different from the server is to have a websocket based presence channel and a backend job that checks for users approaching session end and sends them a notification.