0 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
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.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Earned once your experience points ranks in the top 10 of all Laracasts users.
Replied to Access Session Variables Outside Of Laravel.
Not sure why this popped up, ITS FIVE YEARS AGO
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
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
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
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.
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.
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());
Replied to Undefined Variable $categories In Tha Blade
by the way, NEVER delete with a plain link. Use a form.
Replied to Retrieve The Last Entered ID
try asking on the package issues page?
Probably get the following with the correct user id
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
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.'">';
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.
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.
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.
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
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?
Replied to File Does Not Exist Or Is Not Readable.attachment Sending Error. GetRealPath(),
You have to move the file to local storage first
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
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
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
Replied to Trying To Get Property 'agent_balance' Of Non-object
because your input value does not match an agent slug
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
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
Awarded Best Reply on Livewire Charts
Here's a couple of resources that might help
https://chasingcode.dev/blog/laravel-livewire-dynamic-charts-apexcharts/
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
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
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?
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.
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.
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.
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?
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.
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
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
Looks like php from 10 years ago unfortunately...
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
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')}}
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.
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.
Replied to Livewire Charts
Here's a couple of resources that might help
https://chasingcode.dev/blog/laravel-livewire-dynamic-charts-apexcharts/
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)
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)
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}
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
Earned once your experience points ranks in the top 10 of all Laracasts users.