Skip to main content
Filter by
Sorted by
Tagged with
Best practices
0 votes
1 replies
37 views

I have two models with global scopes. #[ScopedBy(UserScope::class)] class User {} #[ScopedBy(ViewerScope::class)] class Viewer extends User {} The scope just checks if class instance has is_viewer ==...
Denys Siebov's user avatar
1 vote
0 answers
142 views

Can anyone provide full example usage of larvael model with api-platform. With pagination, filters, groups, etc. I use api-platform with symfony but I want to use apip with laravel as well but facing ...
Shahzaib Tariq Butt's user avatar
2 votes
2 answers
191 views

I want to run an action after any model got deleted, but currently it seems like I do something wrong.. I already get the Model before I delete it, so the event should get fired. As I do already some ...
MaxWeb's user avatar
  • 169
0 votes
0 answers
80 views

I'm building an application where users can sign petitions - each petition would have a subject attribute and a location attribute. I would have a landing page for each subject, a landing page for ...
Yev's user avatar
  • 2,081
0 votes
1 answer
61 views

I would like to get back within a with() the last entry of a modal which is not null on a certain column. I know that it is possible to simply get the last entry with the following function in the ...
Matthias's user avatar
1 vote
1 answer
56 views

here is my code - $list = Plot::active() ->whereNotNull('user_id') ->distinct('user_id') ->with('user') ->paginate(10); but here "...
mahbub's user avatar
  • 303
2 votes
1 answer
1k views

I'm working on a Laravel project and I'm trying to set up a one-to-many relationship between two models How can I create a new user and associate multiple posts with that user using Eloquent? How do ...
Harshad Kanani's user avatar
4 votes
1 answer
977 views

I've run out of ideas, so I thought I'll ask around. Here's my code: # app/Map/MapServiceProvider.php class MapServiceProvider extends ServiceProvider { /** * Bootstrap any package services. ...
Sebastian Sulinski's user avatar
0 votes
1 answer
82 views

So basicly i have started working with laravel. And to this moment i have been writing migrations and defining the fields there. And after that i should create a model related to it and define the ...
p1rate_k1ng's user avatar
-1 votes
1 answer
51 views

I have two tables in my project and there are two relationships between these two tables. One of these two relationships is one-to-one and the other one is a one-to-many relationship. My tables: +-----...
mahdi_sheykh's user avatar
0 votes
0 answers
44 views

I have a complex query such as $drivers = Drivers::where('somecondition', $request->condition) ->with([ 'license' => function($query) { $query->where('is_active', 1)...
Yeak's user avatar
  • 2,530
-2 votes
2 answers
72 views

$couponCode = $request->couponCode; // Get coupon details by coupon code $coupon = Coupon::where('couponCode', $couponCode) ->get() ->first(); $couponDetails = response()->json($...
Madusha Prasad's user avatar
-2 votes
1 answer
104 views

I have many routes, and for a single page (my homepage) I need to sample almost all of my models. I do it like that: use App\Models\Aa; use App\Models\Bb; use App\Models\Cc; // and so on ... Route::...
yossi's user avatar
  • 3,174
0 votes
1 answer
972 views

I want to insert multiple rows using Model::inset($dataArray) but it's not firing boot method. self::creating() Is there any solution ? I want to insert multiple rows at once to save time but its ...
Sajjad Ali's user avatar
-1 votes
1 answer
354 views

I have a Laravel app and a model Category. It has a relation to itself called parent Category.php public function parent(): BelongsTo { return $this->belongsTo(self::class, 'parent_uuid', 'uuid'...
Nelu Moraru's user avatar
0 votes
1 answer
410 views

I have my Model Sales Target when I create and update Sales Target, Sales Target has the start_date and end_date of the sales target the problem is that my written function which I wrote Inside my ...
Adnan Ali's user avatar
1 vote
1 answer
3k views

I have three tables, File, FileFolder and Folder. These tables all have their own Laravel Model, with their respective names. File FileFolder Folder Now, I need to retrieve all files that are in ...
daveyvdweide's user avatar
0 votes
0 answers
87 views

i want to get nama from Supplier table using PembelianDetail table through Pembelian table using this code : $detail = PembelianDetail::with('supplier')->whereBetween('tanggal',[$awal, $akhir])->...
NAUFAL NAFIDIIN's user avatar
0 votes
3 answers
1k views

I want to fetch only one columns which has name image_url from relationship table. relationship on table is belongsTO. i am confused how to fetch only single column value with belongsTo relation. ...
parteek kumar's user avatar
-1 votes
1 answer
180 views

i have method to mass update the studentSection table. This method works. But if i mass update multiple records only one record gets save. Update (latest) public function setStudentsSection(Request $...
Kael's user avatar
  • 169
0 votes
2 answers
49 views

i have method that i want to get program section by session. I have terms & sessions model program & section for pivot table program.sections then add terms & program.sections to schedules ...
Kael's user avatar
  • 169
0 votes
1 answer
43 views

Hello i have parent table and child table sessions. Which i use to create student schedule. terms ----- id name start_date end_date term_type active sessions -------- id term_id start_date end_date ...
Kael's user avatar
  • 169
0 votes
3 answers
722 views

Hello I have this method that mass create student sections Enrollment controller method this code works fine but it doesn't get in my studentSectionObserver. Although it's getting saved one by one ...
Kael's user avatar
  • 169
0 votes
0 answers
299 views

Laravel 8 I have seen a few of these questions, but the answers are either msising, not for php, or some weird hack. I have a table in the database, mariadb, with the field type of LONGTEXT - equates ...
TheWebs's user avatar
  • 13k
0 votes
2 answers
307 views

I have an observer that i want to output message wherever the enrollment has section in it. I am not sure if this is enough information. Please do not hesitate to ask me to provide more. UPDATED DB ...
Kael's user avatar
  • 169
0 votes
1 answer
1k views

I have the following DB schema Products and their categories. I have created Model for both tables in Laravel called Categorie and Product class product extends Model { use HasFactory; } categorie ...
Usman Khan's user avatar
1 vote
1 answer
69 views

I am trying to create a chat app in Laravel. When a conversation is created between users, I don't want to record a user as host user. I would like to get a conversation filtered by given users. ...
mg tint's user avatar
  • 33
3 votes
2 answers
2k views

I am migrating some app functionality into a Laravel package. The package includes Models, Controllers and routes. I am using Laravel 9 Everything is working except my Models are not biding to the ...
Kerkness's user avatar
  • 359
0 votes
2 answers
1k views

after these commands php artisan make:model 'FileName' -mcs Laravel make command files sources (Model, Controller, Migration, Seeder, Factory etc...) How all basic files generate and where from these ...
Shourov Shahadat's user avatar
2 votes
0 answers
1k views

I have a table that I am generating through an iterative loop. The issue is that there is an input field of type date. When I try to attach my livewire model, it doesn't show the value coming from the ...
DIGITAL JEDI's user avatar
  • 1,666
5 votes
1 answer
7k views

I have some Laravel models using the next Trait which is calling the model's boot method: <?php namespace App\Traits; use Illuminate\Support\Str; trait Uuids { /** * Boot function from ...
chuysbz's user avatar
  • 1,550
1 vote
1 answer
799 views

I am very new to the laravel,i am using l5-repository package for orderBy and sortedBy to sort columns ,while hitting API i am getting following error please help me to resolve the issue my API URL :-...
usersuser's user avatar
  • 167
0 votes
1 answer
297 views

I am new to the laravel, i am implementing user registration api while registering the user it's throwing an error like mass_assignment Add [first_name] to fillable property to allow mass assignment ...
usersuser's user avatar
  • 167
0 votes
1 answer
2k views

I'm having a really strange issue here. I have a user model (detailed below). It all works fine until I added the getReportsSharedAttribute function. When this is added, the server freezes and I get: ...
user3274489's user avatar
0 votes
1 answer
137 views

I am trying to change date format while fetching data in this way protected $casts = [ 'due_date' => 'date:d-m-Y', ]; Blade {{$ticket->due_date}} It is showing is like 2022-...
web pakistan's user avatar
0 votes
0 answers
57 views

I have this function to update the DB values, but one of the statements is not working. I created a relation to the table called ventas, however, it is not updating it´s value to NULL. This is my code:...
Rodri6uez's user avatar
  • 497
1 vote
0 answers
149 views

I have a database tables as followed Posts Table Comments Table Users Table Pages Table Likables Table id id id id id user_id user_id name page_name liker_id content comment email liker_type ...
drhtoo's user avatar
  • 11
0 votes
1 answer
892 views

I create a panel with laravel 8 and create some emails jobs that must send emails to specific users on specific dates it works fine. I created the database with 2 columns user_id (id of the user that ...
foad fartash's user avatar
0 votes
1 answer
153 views

When I created a variable in the Model named "statuses" and called it back in controller I got the array data. However when calling the second variable it's returning null and giving me ...
David Buik's user avatar
2 votes
0 answers
179 views

I want to return the data of Charge instance instead of User , for that i am trying to use joins ,can you please help me to acheive this thing $id=Charge::whereNotNull('created_by')->get('...
usersuser's user avatar
  • 167
0 votes
2 answers
1k views

I’m trying to change a Laravel's default table name from its model name and plural to the other custom name. From reading around I thought I had to just update that in the app/Model/User.php for ...
Chanda chewe's user avatar
3 votes
3 answers
4k views

I am trying to write some code, that displays data from a database in Laravel. But I have two table values linked to eachother with a foreign key, and when I try to show that on my page, it just shows ...
Mauro's user avatar
  • 372
1 vote
1 answer
1k views

I'm using Laravel's Event & Listener functionality to detect the following model actions and trigger some application logic. app/models/MealFood /** * The event map for the model. * * Allows ...
shAkur's user avatar
  • 1,002
0 votes
1 answer
646 views

This is my models: //project model class Project extends Model { ..... public function items(){ return $this->hasMany(ProjectItem::class,'project_id'); } } //project items model ...
dev-jim's user avatar
  • 2,574
1 vote
1 answer
952 views

These are my Migrations Type Migration Schema::create('digital_types', function (Blueprint $table) { $table->id(); $table->string('name'); $table->...
CC7052's user avatar
  • 577
3 votes
2 answers
5k views

I would like to create a model: FormsUser and the migration: forms_user To use the table as a pivot because I have problems when I create a forms I am told that the table: 'forms_users does not exist' ...
Stack Realtek's user avatar
0 votes
1 answer
23 views

I have two tables in my database, one for "sales" informations and the other for "sale content" (items). What is the best method to present this using the laravel models? For ...
mathnabit's user avatar
  • 400
0 votes
3 answers
7k views

I'm struggling to create more than one models (I don't want to run command every time to create a lot of models) using artisan command in Laravel 8 but it's giving me error. What I tried is php ...
Ghulam Farid's user avatar
0 votes
0 answers
180 views

I'm using the laravelista comments package to make comments for my site. When trying to create a comment, the POST method goes through (with the commentable model and its id properly referenced), but ...
Daniel Kennedy's user avatar
0 votes
0 answers
394 views

This is a continuation of my last question. I like to create a relationship between a user (with an account type that’s equal to a “profile”) and my job posts. What I did was create a relationship ...
Ginz77's user avatar
  • 73