Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [laravel]

Laravel is an open-source PHP web development framework created by Taylor Otwell. Laravel helps you create applications using simple, expressive syntax.

Filter by
Sorted by
Tagged with
0 votes
0 answers
15 views

Laravel 9 - Metadata creation using middleware?

I wrote a middleware for laravel that grabs the current metadata for the specific URL you visit. How it works: we use the $request and compare the current URL: <...
user avatar
0 votes
1 answer
34 views

Laravel controller getting results based on parameter including relationship results

I am trying to learn to improve my coding on a daily basis and this is one of the first times I am posting on here, so bear with me. I have two models, a Payment and an Expense model. A ...
user avatar
  • 367
1 vote
1 answer
95 views

Optimization of laravel pivot table relationship

I have a pivot table called invite_riskarea which is designed as follows: This table handle the permissions that have a specific user (through an invite id) to ...
user avatar
  • 127
0 votes
0 answers
65 views

PayPal payment logic in AJAX/PHP/Laravel

I've just finished setting up the PayPal checkout integration for my Laravel web app. It successfully processes a transaction and persists it in my database, and I want to make sure something as ...
user avatar
2 votes
1 answer
40 views

Retrieve config values using custom helper

I've stored a set of theme related configuration in a config file. config/theme.php ...
user avatar
0 votes
0 answers
42 views

Using configuration file to store classes

I'm using a configuration file to store tailwindcss classes. The idea is to make a dynamic component and simply call the class from configuration file base prop call on a component. eg: in config/...
user avatar
0 votes
1 answer
42 views

Search controller logic to search through models and manufacturers

I have the following Laravel controller that searches through two models - Manufacturer and SearchTerm (which contains models of manufacturers, synonyms of models as well as common misspellings) using ...
user avatar
0 votes
3 answers
73 views

table name column name from GET parameter

This is a function that reads a setting data from DB. ...
user avatar
0 votes
0 answers
62 views

Creating employee attendance report for some time period

I have written a logic which will get 2 months and get all months between them then I am looping all months and inside every month I am finding all days in that month then looping through these days. ...
user avatar
-2 votes
1 answer
57 views

How to avoid multiple query to get child relationship count in Laravel one to many Realtionship

I have 3 tables: regional with Regional Model (id,kode) status_kontrak with StatusKontrak Model (id,status,user_id,...,...) users with User Model (id, regional_id). My purpose is to get a collection ...
user avatar
4 votes
2 answers
362 views

Optimization of a Laravel controller that passes data and views

I am trying to build a website that shows events. And I use the following controller. Please note that the urls ($view and ...
user avatar
0 votes
0 answers
27 views

Controller method to store course [duplicate]

I have this controller method to add a course and it works fine but I really don't like this code because I think it's to large and a little bit ugly. : ) I was trying to do it cleaner and a little ...
user avatar
  • 1
1 vote
2 answers
65 views

Controller method to store course

I have this controller method to add a course and it works fine but I really don't like this code because I think it's too large and a little bit ugly I was trying to do it cleaner and a little bit ...
user avatar
0 votes
1 answer
66 views

A create gateway controller in Laravel

In my app users can create and soft-delete payment gateways something like Paypal. Users of a website can connect to the gateway and make payments. I've written the logic in a transaction also locking ...
user avatar
1 vote
1 answer
76 views

Choose meals for a week

I've built this complex form or at least what I would consider a complex form and it feels really dirty. It felt dirty while I was programming it but I wanted to get it working and then go back and ...
user avatar
0 votes
0 answers
60 views

query data from mapping name but use many memory

In my class the constructor queries data from the database. In the database there is a table containing more than 400k records. After the query I tested memory size- it uses more than 10m++ bytes. so ...
user avatar
  • 101
0 votes
1 answer
73 views

Eloquent eager loading deep nested relation with "where" condition

is there a more elegant way to do what the code below does without use "foreach"? I am trying to load answers from questions but only the answers that contains a direct relation with an ...
user avatar
1 vote
1 answer
74 views

Laravel CRUD Controller - code request

Here is my starting point for a laravel CRUD controller. I would appreciate it if someone could do a review and show me how an experienced developer would approach this. I do not want to progress with ...
user avatar
1 vote
1 answer
48 views

Method in Laravel to give a JSON response indicating whether the user may edit

I'm working on creating code with a nice balance between concise and readable. How would you improve this Laravel code block to make it more compact and readable? ...
user avatar
1 vote
2 answers
182 views

'Lean controller'/'Business logic on service' and filtering, sorting, pagination methods on controllers

I'm currently reading about "Lean controllers"/"Business logic on services" and trying to refactor some legacy code. However I am struggling to apply what is taught in the ...
user avatar
1 vote
1 answer
219 views

Placing store and update logic in Laravel 8 form request

I want some opinions about my code that implements store and update for a Laravel 8 form request. The make function is for storing the data and the ...
user avatar
2 votes
1 answer
117 views

Adjusting variables on change of status attribute of my Order Laravel model on the updated event in observer

I have an order model and a client model. A client has many orders, an order belongs to a single client. In the client model I keep track of how much money a client paid (...
user avatar
1 vote
1 answer
84 views

Login using two-factor authentication

I want to make the code below prettier but I don't know what to change and how to change. I know that the controller should be easy, delegating actions related to models or to services or something ...
user avatar
2 votes
2 answers
251 views

How to reduce a POST request duplicate in Laravel/PHP for payment system?

I'm using PHP/Laravel and I have two controllers. Controllers/PaymentController Controllers/PaymentExpressControler They both create an request which is exactly the same, but it has some differences....
user avatar
  • 45
4 votes
2 answers
3k views

Laravel 8 registration and login with user profiles

I am working on a Laravel application (Github repo) that requires user registration and login. Alter registration, the users can change their registration details (except password, for which there is ...
user avatar
1 vote
2 answers
2k views

Laravel controller method to update user

I'm using Laravel and this PHP method is in a controller. It's the back-end for a edit profile page. The user can change the profile picture, reset the password, the username, and so on. I'm new in ...
user avatar
  • 173
4 votes
1 answer
59 views

Single end point REST API

I want to ask question about a better way for implementing single endpoint REST. I want to build a rest API but I want it to only have single endpoint like: graphql,...
user avatar
  • 143
2 votes
1 answer
87 views

Is it okay to use interfaces on tests?

I have created a test, also the interfaces to be implemented for each test case based on user's role because I think it would make it easier to understand what the test case will and should do, also ...
user avatar
  • 121
3 votes
0 answers
42 views

Add pivot data from the same pivot model [closed]

My project has thee models Cart, Order and Product Cart ...
user avatar
5 votes
2 answers
206 views

Queries to get unpaid and unpaid invoices

Here is my code: ...
user avatar
2 votes
1 answer
112 views

Route Improvement in Laravel 8

I have below route. I am using Laravel 8. ...
user avatar
  • 117
3 votes
1 answer
58 views

Get all routes that start with rt_

The code reads all my routes and return to my AJAX request the names of the routes without duplicates and just those that have the "rt_" prefix. ...
user avatar
1 vote
1 answer
334 views

Improvements on Laravel's base Model and FormRequest

Introduction I've improved, IMO, Laravel's base Model and FormRequest. It's working as expected. But, before actually implementing this any further in my application, i want to have my classes checked ...
user avatar
2 votes
1 answer
83 views

PHP Laravel Order generation Custom Class

Here is a custom class I use to handle different types of orders in Laravel. This question includes the code regarding Order Type A. I want to know whether I can simplify the code. I have different ...
user avatar
  • 47
4 votes
1 answer
92 views

API Client and usage implementation

I'm really bothered with my approach in this, as I'd like to use the client in multiple projects. The client extends Guzzle and I'm using a factory method to initialize the client with the necessary ...
user avatar
  • 353
1 vote
2 answers
114 views

Displaying filtered user data using Ajax and PHP

I want to get my code cleaner and more efficient. This code gets variables form a PHP file and filters it to show the selected user name, all available usergroups on a list box and the groups he is ...
user avatar
2 votes
2 answers
125 views

Structuring code logic for events on laravel controller

The code below will store a base64 image on another website and create an event to display the image on a Vue page in real time. It works fine and all. My question is, is this a good way of doing it ...
user avatar
  • 21
4 votes
2 answers
73 views

Filtering from a file to show information

I want to get my code cleanner and more efficient. This code gets variables form a PHP file and filters it to show the selected user name, all available usergroups on a list box and the groups he is ...
user avatar
3 votes
1 answer
394 views

Does PDO::quote helps me to protect me against sql injection?

I have to process raw sql user input with Laravel. I've backed them up as follows: ...
user avatar
5 votes
2 answers
848 views

Implementing Laravel old data in Vuejs

Users input their pin-code which is checked against the database and returned with the locality, district and state associated with that pin-code. Multiple localities may be returned so the options ...
user avatar
  • 71
2 votes
1 answer
99 views

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? Should I not return anything in the model ...
user avatar
1 vote
1 answer
72 views

Handling multiple try-catches in a for loop

Good day! I would like to know if this is possible to be refactored into a cleaner code. The reason I'm doing it like this is to catch the column that the error appeared on and then potentially output ...
user avatar
5 votes
1 answer
882 views

Laravel Scope get request data/param

I want to pass the param from the request on the scope method in the model and serve it as json to be rendered by select2. Which is better? 1. Pass request from the controller like this controller: <...
user avatar
4 votes
1 answer
50 views

Protecting Vue page based on the API response

If the user/visitor has access to the API route, then the status code will 200, else 401. I know that I can user Vue navigation guards, but I will need to use Vuex. This way is much simpler and faster,...
user avatar
  • 91
2 votes
1 answer
81 views

Controller in Laravel with parsing, creation and relationships

The following code represents the store method of a resource controller. A user can create an training offer on my website and can pass various information like ...
user avatar
  • 325
-2 votes
1 answer
98 views

Laravel Page Controller [closed]

Aim: To make pages located in site.com/page-1, site.com/page-2. Those pages are pretty much static so I won't use database. First, I've created the PageController. ...
user avatar
  • 105
3 votes
1 answer
73 views

Filtering multiple request parameters

This is pretty straightforward, it takes requests from the frontend, checking if it is present on the request, if it does, an action is taken for that if statement. I wonder if there is a way to ...
user avatar
  • 131
1 vote
1 answer
70 views

What would be the best way to update data from associative array?

I recieve this array in my controller: ...
user avatar
  • 123
1 vote
1 answer
51 views

Importing data from spreadsheet

Not really an issue I am stuck on (the code works) but I just really don't like some code I wrote, if you're bored in lockdown maybe you might like to help. Context: I am import some data from a ...
user avatar
  • 201
0 votes
1 answer
108 views

PHP - Importing columns from uploaded CSV file to SQL database (Laravel 5.7) [closed]

The goal is to upload the columns from the csv into the SQL Pro database. I am able to select the column names that have been uploaded from the csv file, the columns from the csv file are then ...
user avatar

1
2 3 4 5 6