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
1 vote
0 answers
43 views

Laravel seed optimize

This is my laravel seed for two table. I need an efficient and optimized way for this seeder. How can i make it efficient and standard. Give me some tips. ...
Tarikul's user avatar
  • 11
0 votes
0 answers
63 views

Manually inserting or updating a row with timestamps, without Eloquent

I need to insert or update a row that has created_at and last_update timestamps. created_at ...
pileup's user avatar
  • 361
0 votes
1 answer
87 views

Is there any sugestions how to make this script faster if its possible?

I wrote a script that uses an uploaded excel file to import data to the database. It checks for the image first if it can be downloaded without any error then insert the rest of the data. With ten or ...
Benjji's user avatar
  • 1
4 votes
1 answer
421 views

Update specific model attributes from a request

Background This is for an API and I'd like to use this Upsert action to take data from a request and only update the requested fields. I.e. These are partial updates and I will not update every field ...
Taintedmedialtd's user avatar
0 votes
0 answers
71 views

Github API based backend using Laravel

I just created a Github API based backend, this api retrieves and stores information from the github users api app/Http/Controllers/GitController.php ,I am using Requests, Actions and services ...
DeveloperX's user avatar
1 vote
1 answer
295 views

Three way Eloquent relationship definition and saving in Laravel

I'm building a Laravel app (with Vue3 and InertiaJS), and I'm attempting to create relationships between three models: User Area WorkHours where WorkHours is the ...
wonder95's user avatar
  • 111
2 votes
2 answers
179 views

Laravel Event Filtering Controller

So I am currently writing a function in laravel that handles URL parameter filters. How the code works: So we have the following two URL parameters: timeframe and <...
Nifty Matrix's user avatar
1 vote
1 answer
87 views

Laravel Eager Loading tickets from DB

So I have the following relationship in my Model: Events Model: ...
Nifty Matrix's user avatar
1 vote
1 answer
110 views

Theme picker for Laravel 8 blogging application

I am working on a blogging application in Laravel 8. The application supports themes. In a nutshell, theme support works like this: In the views directory, I have ...
Razvan Zamfir's user avatar
2 votes
2 answers
374 views

Route protection with custom middleware in Laravel 8

I am working on a blogging application in Laravel 8. The application assigns users roles and permissions. There is a many-to-many relationship between roles and permissions. I have created a custom ...
Razvan Zamfir's user avatar
3 votes
1 answer
1k views

Setting default of <options> in Laravel with PHP Match

I have a filter component that lets a user filter for events on a website. The user needs to see which category is currently selected in the filter. For this there is a URL with parameters. e.g. ...
Maximilian's user avatar
2 votes
1 answer
154 views

PHP Laravel Check if given date is a week or a regular day

I have a problem. In my project the user can copy a menu for a specific day or for a specific week. The value that will be sent to the back-end will be something like: ...
A. Vreeswijk's user avatar
2 votes
0 answers
50 views

Serving Laravel public/ contents when all Laravel files are in the same server directory

I have a Laravel 8 project hosted at xxx/laravel/ on an Apache server, where xxx is the domain. I want to serve the contents of <...
Ichi's user avatar
  • 73
1 vote
2 answers
133 views

Laravel PostController

I'm new at Laravel and I got an assessment task from company where they want me to create a mini-blog with Users and Posts. I was using following methods: index, create, show, store, edit and destroy ...
mhdev's user avatar
  • 13
0 votes
1 answer
164 views

Default to array when value is null or false

I'm working with ACF in WP which provides a get_field() function. The function can return an array of values, null or false. ...
mrmadhat's user avatar
  • 148
1 vote
2 answers
254 views

Laravel 8 blogging application

I am working on a blogging application in Laravel 8. In the FrontendController controller I have: ...
Razvan Zamfir's user avatar
1 vote
0 answers
220 views

Error handling for Laravel REST API client and server using bearer token authentication

I would like to query a REST API (which uses Bearer token authentication), handling several exceptions that might occur. Could you tell me if the following code (which I explain later in this post) is ...
JarsOfJam-Scheduler's user avatar
1 vote
2 answers
76 views

Check if a new movie session can be inserted

I have this function in my code, this way I validate if a new movie session can be inserted, it works, but I wanted to find a better way to do it. ...
Drezio's user avatar
  • 11
1 vote
1 answer
348 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: <...
Maximilian's user avatar
0 votes
1 answer
59 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 ...
Hardist's user avatar
  • 377
2 votes
1 answer
224 views

Optimization of laravel pivot table relationship

I have a pivot table called invite_riskarea which is designed as follows: This table stores the permissions that have a specific user (through an invite id) to ...
sfarzoso's user avatar
  • 137
3 votes
1 answer
48 views

Retrieve config values using custom helper

I've stored a set of theme related configuration in a config file. config/theme.php ...
shrayder's user avatar
0 votes
1 answer
58 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 ...
Hashim Aziz's user avatar
0 votes
4 answers
511 views

table name column name from GET parameter

This is a function that reads a setting data from DB. ...
flow Stack's user avatar
0 votes
0 answers
519 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. ...
Taha Malik's user avatar
-2 votes
1 answer
448 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 ...
Matius Nugroho Aryanto's user avatar
4 votes
2 answers
466 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
1 vote
2 answers
76 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
159 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 ...
Jacqueline's user avatar
1 vote
1 answer
89 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 ...
Jonathon's user avatar
  • 111
0 votes
0 answers
65 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 ...
story ks's user avatar
  • 101
0 votes
1 answer
495 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 ...
Vinicius.Silva's user avatar
1 vote
1 answer
223 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 ...
Jake Feeley's user avatar
1 vote
1 answer
70 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? ...
Lisandro's user avatar
1 vote
2 answers
212 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 ...
Marco Aurelio's user avatar
1 vote
1 answer
1k 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 ...
Zikri Munandar's user avatar
3 votes
1 answer
491 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 (...
Bogdan Ta's user avatar
1 vote
1 answer
133 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 ...
skoryi-romb's user avatar
2 votes
3 answers
2k 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....
hamon's user avatar
  • 45
4 votes
2 answers
4k views

Laravel 8 registration and login with user profiles

I am working on a Laravel application (Github repo) that requires user registration and login. After registration, the users can change their registration details (except password, for which there is ...
Razvan Zamfir's user avatar
1 vote
2 answers
4k 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 ...
Gass's user avatar
  • 183
4 votes
1 answer
106 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,...
ucup's user avatar
  • 143
2 votes
1 answer
103 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 ...
Yura's user avatar
  • 121
3 votes
0 answers
46 views

Add pivot data from the same pivot model [closed]

My project has thee models Cart, Order and Product Cart ...
Yauhen Kib's user avatar
5 votes
2 answers
265 views

Queries to get unpaid and unpaid invoices

Here is my code: ...
zecaluis's user avatar
2 votes
1 answer
326 views

Route Improvement in Laravel 8

I have below route. I am using Laravel 8. ...
Pankaj's user avatar
  • 117
3 votes
1 answer
75 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. ...
davidsi02's user avatar
  • 229
1 vote
1 answer
420 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 ...
Ramon Bakker's user avatar
2 votes
1 answer
257 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 ...
camille's user avatar
  • 147
4 votes
1 answer
111 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 ...
Repox's user avatar
  • 345

1
2 3 4 5 6