9
votes
Sanitize URL string for Insertion Upon DB table via Eloquent model
Beware of re-assigning a variable. In the setter method setUrlAttribute() the variable $saneUrl is over-written numerous times:
...
7
votes
Queries to get unpaid and unpaid invoices
There seems to be a section in your code that you repeat three times. This can probably be placed in a separate function. Something like this:
...
7
votes
Accepted
Setting default of <options> in Laravel with PHP Match
Some variable assignments are excessive
Let's look at what $selected is set to:
$selected = 'selected';
Then in both of the <...
7
votes
Accepted
Sanitize URL string for Insertion Upon DB table via Eloquent model
The biggest problem here is that you are going overboard with precautions. Security is important, but it must be logical.
What ...
7
votes
Accepted
User Management API
General review
There are numerous Laravel features which could be used to simplify the controller methods - e.g. the base User model (which ships with the framework ...
6
votes
Sanitize URL string for Insertion Upon DB table via Eloquent model
As some general feedback, I would say that your unit tests are lacking. It looks like you are just checking that your filter function modifies the input in some way? One of the main jobs of tests are ...
6
votes
Laravel as client for Strava 3rd party API
Some minor points from me, just after a cursory look at the code.
My PHP is rusty, but I know unset can destroy more than one variable. Useful to know.
I would try ...
5
votes
Laravel 5.8: prevent duplicated code
I think you can DRY this up pretty well by refactoring.
This feels like a “ifs are evil” code smell to me. There are three “if” statements within that whereHas. They are packed in fairly tightly, and ...
5
votes
Accepted
How to reduce a POST request duplicate in Laravel/PHP for payment system?
Let's implements following: separate logic, refactoring of methods
Separate logic
Validate Requests/PaymentRequest.php add rule for validation
...
5
votes
Accepted
Update specific model attributes from a request
How does this look?
It looks okay. It appears to mostly adhere to PSR-12 and is easy to read. While there is only one method with a single loop it isn't very complicated. The variable names are ...
4
votes
Let users create custom blade templates
Ensure template contains required tags
The user shall be made to include the three <%X%> tags in the template code.
It is difficult to know since the code ...
4
votes
Accepted
Laravel UserController Design
First of all do not use Laravel 5.4 even if you've written some* code already, use latest 5.7, and try to always update.
*: You really need to rewrite the application if you have code like you ...
4
votes
Accepted
A PHP Controller, which feels to 'array-like', in Laravel
You could use route model binding to remove some lines from your code, but that would require changing the route so it passes the MenuItem's id.
...
4
votes
Accepted
A method to get a document's path
I'm sorry, this is not an answer to your question, but it is a partial review of your code.
It seems you've got a serious problem with choosing your names. They don't actually tell me what the ...
4
votes
Accepted
Using PHP goto Labels for code folding
The main issue I have with your approach is that it is non-standard and purely for the way that you work. Others looking at your code may be a bit confused as to what you are doing and why. In your ...
4
votes
Accepted
Laravel controller method that searches jobs using variable criteria
I'd like to recommend condensing some of your script so that it is easier on the eyes.
This:
...
4
votes
Refactor PHP | Laravel Code, Optimisation needed to make code clean
You could exploit Laravel collections to achieve what you need.
Most of your code is checking for the presence/absence of props on your arrays. Laravel internally exposes and uses the ...
4
votes
Accepted
What would be the best way to update data from associative array?
"Premature optimization is the root of all evil."
As long as this code works and causes no problem, nothing should be really done. Trying to "improve" it, most likely you will cause a severe harm to ...
4
votes
Accepted
Using method trait to return something in laravel model
I have question about scope yesterday, and someone gives an answer to don't return anything in scope. Is return something in scope really bad practice?
This is because laravel is handling "it&...
4
votes
Structuring code logic for events on laravel controller
I'm mostly a back-end guy who fusses his way through front end code. Here's my advice:
Keep the controller code as close as possible to handling the response only. Delegate the creation of objects to ...
4
votes
Laravel controller method to update user
So the above answer from Sᴀᴍ Onᴇᴌᴀ already covers quite a few points.
I've worked with Laravel for the past 4 years, so I'll go a bit further in depth on how I'd approach this, including a few ...
4
votes
Controller method to store course
You could create 2 sub-functions for the different parts in your function.
validate($request) so that long part is hidden
...
4
votes
Optimization of a Laravel controller that passes data and views
I don't use Laravel, but yes, you can greatly reduce the preparatory PHP scripting and make it more "D.R.Y.". You could use a lookup array and then null coalesce to fallback values, use a <...
4
votes
Accepted
Optimization of a Laravel controller that passes data and views
Put your repeated or complicated queries into scopes on the model class. Here I also use the helper now to avoid importing Carbon:
...
4
votes
Query to get summary of regional model with count of contracts
You can use the withCount() method to get the count of child relationships.
Such as: user::withCount['getPosts']->find(1);
...
4
votes
Accepted
Retrieve config values using custom helper
I'll review your 2nd and most recent refactor.
Your function getTheme() builds a space-delimited string of class values. Your current function name is clear about ...
4
votes
Laravel controller getting results based on parameter including relationship results
Using eloquent when() function the above code would be cleaner, especially if you add more filters in the future.
I am not sure what version of laravel you are using, but Request injection probably ...
4
votes
Accepted
Laravel 9 - Metadata creation using middleware?
Redis
If you really need to use specific data and you don't have other ways to do it you can use Redis.
Misc improvements
(Not sure if this works with Laravel 9) You also should not save direct URL ...
4
votes
Accepted
Laravel PostController
Thanks for migrating this from Stackoverflow! Let's take a look at your code:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
laravel × 271php × 256
eloquent × 33
object-oriented × 21
controller × 19
javascript × 17
mysql × 15
mvc × 14
performance × 13
authentication × 11
php5 × 11
beginner × 10
sql × 9
validation × 9
database × 8
ajax × 8
repository × 8
rest × 7
laravel-blade × 7
api × 6
unit-testing × 5
jquery × 4
design-patterns × 4
security × 4
network-file-transfer × 4