Director at Novate Ltd

Member Since 6 Years Ago

Mansfield

Experience Points
2,119,785
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
1439
Lessons
Completed
Best Reply Awards
2985
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.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 50
2,119,785 XP
Jan
25
19 hours ago
Activity icon

Replied to Access Session Variables Outside Of Laravel.

Not sure why this popped up, ITS FIVE YEARS AGO

Activity icon

Replied to How To Take Previous All Year Or Data From Array In Laravel?

Write a function that returns the current financial year. If its 19 the the year is 19/20

Write a function that takes the passed in year, eg 19 and returns the start, end, text of fy eg '19/20' etc.

Don't hard code this stuff as I said yesterday

Activity icon

Replied to Laravel Redirect With Post Method

And put in some security. At present its possible for anyone to change the status of any bill

Activity icon

Replied to Laravel Redirect With Post Method

You are doing an ajax call. You should not be redirecting back at the end of the function. Return a response appropriate for your javascript to consume, eg a success or failure state

You can then show a message from your javascript.

If this is too much for you, dont use ajax, just do a regular form submission

Jan
24
1 day ago
Activity icon

Replied to Retrieve The Last Entered ID

what if the connection is pooled?

Activity icon

Replied to Retrieve The Last Entered ID

fine for a 1 user system

Activity icon

Replied to How To Eager Load A Method In Model

Meaning that if you get a collection of models and cast it to an array then it won't contain the data. To return the data you should append the new accessor value to the model.

Make sure you check the number of database queries since you can easily create n+1 issues this way.

Activity icon

Replied to Undefined Variable $categories In Tha Blade

ok, now we get useful info.

After you save the data, you return the same view, but it does not have access to the categories.

As a rule never return a view from a post route.

Instead, return a redirect back to the index route.

Activity icon

Replied to Undefined Variable $categories In Tha Blade

try

 return view('admin.category.index')->with(['categories' => Category::all()]);

I prefer

 return view('admin.category.index')->withCategories(Category::all());
Activity icon

Replied to Undefined Variable $categories In Tha Blade

by the way, NEVER delete with a plain link. Use a form.

Activity icon

Replied to Retrieve The Last Entered ID

try asking on the package issues page?

Probably get the following with the correct user id

Activity icon

Replied to How To Retrieve And Select A Value From A Menu List?

show your select element?

Activity icon

Replied to How To Eager Load A Method In Model

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

Having a foreach loop inside a model is a code smell and will not work when returning a collection of models

Activity icon

Replied to Html Code Inside Variable Not Working In Jquery

ignoring the disgusting act of having html output from your controller (aaarrrrghh), you have not quoted any of the html attributes

$service.='<input type="radio"
                               name="service_type[]"
                               class="radio-input next" 
                                value="'.$fare.'">';
Activity icon

Replied to Mobile Version Of The Onlineshop

spacing things out with <br> tags is not the best idea. Have a think about whether flexbox and grid would give you a better result.

Activity icon

Awarded Best Reply on Using Custom Sometimes() Rule In Controller's $this->validate() Method

You don't have to pass the rules in the actual method call, you could setup the rules array then pass it into the validator?

$rules = [
            'best_estimate' => 'nullable|integer',
            'min' => [
                        'bail',
                        'nullable',
			$request->best_estimate > 0 ? 'sometimes':null,
            ];

$this->validate($request, $rules);

or something like that.

Activity icon

Replied to Using Custom Sometimes() Rule In Controller's $this->validate() Method

You don't have to pass the rules in the actual method call, you could setup the rules array then pass it into the validator?

$rules = [
            'best_estimate' => 'nullable|integer',
            'min' => [
                        'bail',
                        'nullable',
			$request->best_estimate > 0 ? 'sometimes':null,
            ];

$this->validate($request, $rules);

or something like that.

Activity icon

Awarded Best Reply on How To Save User_id With Request All?

or better, created model through relationship

$category = Auth::user()->category()->create($request->all());

but i don't like using all()

Its impossible for anyone reviewing the code to know what might be written to the database

Activity icon

Replied to How To Calculate All Previous Amount According To Its Year?

.... and you intend to update and redeploy your code on the exactly the right day each year going forwards?

Activity icon

Replied to File Does Not Exist Or Is Not Readable.attachment Sending Error. GetRealPath(),

You have to move the file to local storage first

Activity icon

Replied to Post Image Not Found

Fix your hosting public should never appear in your urls. Period.

Articles with hacks like this should be removed from the internet but unfortunately there are too many cowboys out there

Activity icon

Replied to Cache::get() Not Working As Expected

use remember() in conjuction with the callback. this will put the value in cache if it does not exist. As @michaloravec points out, your code just uses the second parameter of get as the fallback. Nothing is being written to cache

Activity icon

Replied to Cache::get() Not Working As Expected

be wary using dd(). it terminates the current request before anything is written permanently to the cache

Activity icon

Replied to Microservice Security

Isn't passport a good solution for this?

Activity icon

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

because your input value does not match an agent slug

Activity icon

Replied to Dynamically Fill A Modal

Url should be to a route and a controller that handles the request and returns the view partial

Do not do it as a file in public

Also, your url needs to contain the id being loaded

Activity icon

Replied to CSRF Token Change On Every Reload

its because you are not maintaining session for some reason

check in your browser tools to see if cookies are being created

Jan
23
2 days ago
Activity icon

Awarded Best Reply on How Get The Attributes From A Model As An Array?

@nimrod compact is just as good as any of the 3+ ways of passing data to a view

Usually for select lists I would use pluck() which I'm surprised none of the other sharpshooters have suggested.

$countries = Country::pluck('name','id');
return view('countries.index', compact('countries'));

view

@foreach($countries as $id => $name)
	<option value="{{ $id }}">{{ $name }}</option>
@endforeach

for extra marks, in the event of validation error, don't throw away their choice

<select name="country">
@foreach($countries as $id => $name)
	<option value="{{ $id }}" {{ $id == old('country') ? 'selected': '' }}>{{ $name }}</option>
@endforeach
Activity icon

Replied to How Get The Attributes From A Model As An Array?

@nimrod compact is just as good as any of the 3+ ways of passing data to a view

Usually for select lists I would use pluck() which I'm surprised none of the other sharpshooters have suggested.

$countries = Country::pluck('name','id');
return view('countries.index', compact('countries'));

view

@foreach($countries as $id => $name)
	<option value="{{ $id }}">{{ $name }}</option>
@endforeach

for extra marks, in the event of validation error, don't throw away their choice

<select name="country">
@foreach($countries as $id => $name)
	<option value="{{ $id }}" {{ $id == old('country') ? 'selected': '' }}>{{ $name }}</option>
@endforeach
Activity icon

Replied to Laravel Redirection To Email/verify With SSL

Your `.htaccess' file should be directing all requests to index.php

if the client wants all users to be presented with the login then you need to protect the root page with auth middleware and not the others such as email verification. When the user lands on '/' they are redirected to login then when authenticated sent back to the root page.

Email verification out of the box in Laravel requires that the user is logged in - a stupid decision IMO - so I guess whether the verification page is in or out of the auth middleware depends if you are using the default verification or have your own solution.

Not sure what any of this has to do with ssl though?

Worryingly you don't seem to have ANY routes that require to be an authenticated user?

Activity icon

Awarded Best Reply on Eager Load The Following Users

Your nesting level issue is because mutual followers will keep loading each other's data.

You apply this globally to the user model so user loads followers, each of those models load their followers, each of those followers loads their followers etc etc only one mutual follow and you get into a nested loop.

A different approach is required, and I suggest you KISS it (Keep it Simple Stu..)

If a user wants to see who follows them, just load them?

$followers = Auth::user()->followers;

or the other way

$follows = Auth::user()->follows; for people this user follows.

Activity icon

Replied to Eager Load The Following Users

Your nesting level issue is because mutual followers will keep loading each other's data.

You apply this globally to the user model so user loads followers, each of those models load their followers, each of those followers loads their followers etc etc only one mutual follow and you get into a nested loop.

A different approach is required, and I suggest you KISS it (Keep it Simple Stu..)

If a user wants to see who follows them, just load them?

$followers = Auth::user()->followers;

or the other way

$follows = Auth::user()->follows; for people this user follows.

Activity icon

Replied to String Data, Right Truncated: 7 ERROR: Value Too Long For Type Character Varying(1024)

is the token (of 746 digits) then base64 encoded, encrypted or is it double-byte? dd() the length of the key just before it is written.

Activity icon

Replied to I Want To Ask If This Is My Website Being Tracked By Someone Else To Steal My Payment Account? I Don't Understand Much About The Code Please Help Me

You want to prevent the site from working?

Do you really want to use a script that uses globals and echos javascript to the view? Why are you here on a Laravel site?

Activity icon

Awarded Best Reply on Best Practice: Sum Old Value Of Wallet Amount With New Value

Ideally store lowest denomination only, ie 5 dollars and 25 cents would be stored as 525 and displayed as 5.25 in the view only.

To make sure money does not go missing, increment the number, this way another thread cannot be changing the value at the same time as this one.

ie, $wallet->increment('amount',300); adds 3 dollars

if you read the wallet, then add to the value, then save the wallet then the value can be corrupted

ie,

session 1 reads wallet, $amount = 500

Session 2 reads wallet, amount = 500

Session 1 adds 300, wallet = $800

Session 1 wallet->save(), wallet in DB = $800

Session 2 adds 250, wallet = $750

Session 2 wallet->save(), wallet in DB = $750 ! Overwrote $800

This might be a contrived example with a single user's wallet amount. But suppose this was an amount of stock in a warehouse and you have multiple shoppers buying things. Two people going through checkout at the same time can seriously screw your balances.

You need to get in the habit of thinking through situations like this, however unlikely they might be.

increment() reads, updates and writes the new value in one operation so it cannot be interspersed with other activities.

For more complex operations, consider record locking.

Activity icon

Replied to Blade Helper Cached

It will be cached when you run php artisan config:cache which you should do as part of a deployment script anyway

Activity icon

Replied to Having A Bookmark Feature On Laracasts Responses

The 'leaderboard members' have absolutely no input into the design of Laracasts. Just saying.

Either mark the question as 'Follow', then you can see it in Following or use your own personal bookmarks

Activity icon

Replied to Videogame Servers

Viewing requests, you would need something like wireshark https://www.wireshark.org/ or other network packet sniffer

Web pages use http, other technologies use all sorts of protocol, like VOIP for instance

Activity icon

Replied to Blade Helper Cached

or better php artisan view:clear

Its a pain to keep doing during development, and is a good reason to switch to components

by the way, I wrote a piece on including your commit hash in the view in this article. It might be of use;

https://talltips.novate.co.uk/laravel/versioning-your-laravel-project

With this setup, you could show the hash as {{config('version.hash')}}

Activity icon

Replied to Dynamically Fill A Modal

change this (you have only one quote), and probably needs to use $bookdays

<td onclick="showMsg('{{$bookdays->id}}'>{{$bookdays->name}}</td>

or if the id is numeric, then no quote

<td onclick="showMsg({{$bookdays->id}}>{{$bookdays->name}}</td>

console.log in your method to show it is being called with the correct id

function showMsg(id)
{
	console.log(id);

read this

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

in the then method you need to merge the returned html into the modal, then show the modal.

Bear in mind that there will be a time delay between the click and the modal showing as you make the ajax call to the server.

Activity icon

Replied to Best Practice: Sum Old Value Of Wallet Amount With New Value

Ideally store lowest denomination only, ie 5 dollars and 25 cents would be stored as 525 and displayed as 5.25 in the view only.

To make sure money does not go missing, increment the number, this way another thread cannot be changing the value at the same time as this one.

ie, $wallet->increment('amount',300); adds 3 dollars

if you read the wallet, then add to the value, then save the wallet then the value can be corrupted

ie,

session 1 reads wallet, $amount = 500

Session 2 reads wallet, amount = 500

Session 1 adds 300, wallet = $800

Session 1 wallet->save(), wallet in DB = $800

Session 2 adds 250, wallet = $750

Session 2 wallet->save(), wallet in DB = $750 ! Overwrote $800

This might be a contrived example with a single user's wallet amount. But suppose this was an amount of stock in a warehouse and you have multiple shoppers buying things. Two people going through checkout at the same time can seriously screw your balances.

You need to get in the habit of thinking through situations like this, however unlikely they might be.

increment() reads, updates and writes the new value in one operation so it cannot be interspersed with other activities.

For more complex operations, consider record locking.

Activity icon

Awarded Best Reply on Image Manipulation

Have a look at Spatie media library

You give it the uploaded file and it will store it and create any transformations you require. Then provide methods where you can ask for the URL or Path of a particular file size, eg thumb

Its a very mature package, now on version 9 and should handle all your needs.

https://spatie.be/docs/laravel-medialibrary/v9/introduction

Don't confuse it with Media Library Pro which is a paid for package and contains tools to actually manage the images (more like an asset manager)

Activity icon

Replied to Image Manipulation

Have a look at Spatie media library

You give it the uploaded file and it will store it and create any transformations you require. Then provide methods where you can ask for the URL or Path of a particular file size, eg thumb

Its a very mature package, now on version 9 and should handle all your needs.

https://spatie.be/docs/laravel-medialibrary/v9/introduction

Don't confuse it with Media Library Pro which is a paid for package and contains tools to actually manage the images (more like an asset manager)

Activity icon

Replied to Construct Url With Slugs Separated By Dash

I would go for

www.mydomain.com/product-category/12/a-pretty-long-seo-friendly-product-name

www.mydomain.com/{slug1}/{id}/{slug2}

Activity icon

Replied to API Using Laravel Jetstream And Inertiajs For 3rd Party

Yes, you need to design an api for your application, put those routes in the api.web and use something like passport or JWT to authenticate the 3rd party

Community Pillar

Earned once your experience points ranks in the top 10 of all Laracasts users.