98 questions
Best practices
0
votes
1
replies
37
views
Ignore parent Model Scope in a Child model
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 ==...
1
vote
0
answers
142
views
Laravel - api-platform: Full Api-platform usage example with larvel model
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 ...
2
votes
2
answers
191
views
How to handle eloquent.deleted Event for all Models right?
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 ...
0
votes
0
answers
80
views
Most efficient way of generating and storing Eloquent Model stats
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 ...
0
votes
1
answer
61
views
How to get the last entry of a Laravel model which is not NULL on a certain column (Laravel 11)
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 ...
1
vote
1
answer
56
views
how to get unique data from database using eloquent model (laravel)
here is my code -
$list = Plot::active()
->whereNotNull('user_id')
->distinct('user_id')
->with('user')
->paginate(10);
but here "...
2
votes
1
answer
1k
views
Implementing One-to-Many Relationship in Laravel Eloquent
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 ...
4
votes
1
answer
977
views
Laravel route model binding for model with UUID does not instantiate the model
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.
...
0
votes
1
answer
82
views
Should i write migrations every time i want to create table in Laravel?
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 ...
-1
votes
1
answer
51
views
How to change relational tables fields, when a field of a table changes in Laravel?
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:
+-----...
0
votes
0
answers
44
views
Laravel Relationship complex with passing dynamic value [duplicate]
I have a complex query such as
$drivers = Drivers::where('somecondition', $request->condition)
->with([
'license' => function($query) {
$query->where('is_active', 1)...
-2
votes
2
answers
72
views
Cant return $couponDetails->couponName; value in laravel [duplicate]
$couponCode = $request->couponCode;
// Get coupon details by coupon code
$coupon = Coupon::where('couponCode', $couponCode)
->get()
->first();
$couponDetails = response()->json($...
-2
votes
1
answer
104
views
Includin many models in the routes `web.php` file practice
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::...
0
votes
1
answer
972
views
boot self::creating() not working with insert in laravel
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 ...
-1
votes
1
answer
354
views
Route Model binding in Laravel
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'...
0
votes
1
answer
410
views
Custom Timestamps Field Also Updating With Created At Timestamps Laravel
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 ...
1
vote
1
answer
3k
views
Laravel relationship where clause returns all records parent
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 ...
0
votes
0
answers
87
views
nested eager loading or hasManyThrough in laravel is not working
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])->...
0
votes
3
answers
1k
views
How can i select specific field name using belongTo relationship in laravel model using eloquent?
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.
...
-1
votes
1
answer
180
views
mass update only saving one record laravel
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 $...
0
votes
2
answers
49
views
get student count in current date - laravel 8
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 ...
0
votes
1
answer
43
views
Logic to check current session if it has future session then disable button
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
...
0
votes
3
answers
722
views
Observer not running when creating in database
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 ...
0
votes
0
answers
299
views
Malformed UTF-8 characters, possibly incorrectly encoded Laravel
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 ...
0
votes
2
answers
307
views
Illuminate\Database\Eloquent\Relations\HasOne::$section_id
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 ...
0
votes
1
answer
1k
views
Laravel Model with custom column names
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
...
1
vote
1
answer
69
views
How to get conversation of given users (using where condition twice on same column)?
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. ...
3
votes
2
answers
2k
views
Use Explicit or Implicit Model Binding on Routes in Laravel Package
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 ...
0
votes
2
answers
1k
views
How Laravel Generate Model Migration Controller all command related files?
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 ...
2
votes
0
answers
1k
views
Laravel Livewire Model set default value
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 ...
5
votes
1
answer
7k
views
Laravel Model: boot on trait and model
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 ...
1
vote
1
answer
799
views
How to resolve Not unique table/alias error in laravel?
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 :-...
0
votes
1
answer
297
views
How to resolve mass assignment error in laravel?
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 ...
0
votes
1
answer
2k
views
Laravel Model is freezing the server. Timeout error
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:
...
0
votes
1
answer
137
views
casts property is not working to change date format
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-...
0
votes
0
answers
57
views
MODELS: Cannot update values in DB
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:...
1
vote
0
answers
149
views
Laravel multiple polymorphic relationship
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
...
0
votes
1
answer
892
views
How can I log notifications laravel 8 after fired?
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 ...
0
votes
1
answer
153
views
Invalid argument supplied for foreach() view returning null
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 ...
2
votes
0
answers
179
views
How to return the data of another model instance model by using joins in laravel?
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('...
0
votes
2
answers
1k
views
changing the default Laravel table names from plurals to own custom names
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 ...
3
votes
3
answers
4k
views
Laravel - Show name instead of id
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 ...
1
vote
1
answer
1k
views
Find which model method is triggering the Event
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 ...
0
votes
1
answer
646
views
laravel withCount() Cardinality violation error when relationship is hasMany
This is my models:
//project model
class Project extends Model {
.....
public function items(){
return $this->hasMany(ProjectItem::class,'project_id');
}
}
//project items model
...
1
vote
1
answer
952
views
Null Relation in Laravel Model
These are my Migrations
Type Migration
Schema::create('digital_types', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->...
3
votes
2
answers
5k
views
Laravel 8 : How to create a Pivot Model with its associated migration?
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' ...
0
votes
1
answer
23
views
How to present two tables which have a relation between them like the case of the "sales" table and "sales_content" using the laravel model
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 ...
0
votes
3
answers
7k
views
How to create multiple models in Laravel 8 using single artisan command?
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 ...
0
votes
0
answers
180
views
Laravel - Why is model not saving?
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 ...
0
votes
0
answers
394
views
Laravel 8: Relationships Between User and Posts. Outputting Data and Storing into Database
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 ...