Questions tagged [laravel-models]
91 questions
0
votes
0 answers
Laravel Relationship complex with passing dynamic value
I have a complex query such as
$drivers = Drivers::where('somecondition', $request->condition)
->with([
'license' => function($query) {
$query->where('is_active', 1);
},
'license.licenseReport' =>…

Yeak
- 2,470
- 9
- 45
- 71
0
votes
1 answer
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 not calling laravel observer method…

Sajjad Ali
- 156
- 9
0
votes
1 answer
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 SaleTarget model then the start_date filed is also…

Adnan Ali
- 61
- 6
0
votes
0 answers
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])->where('id_produk', $produk->id_produk)->get();
with…
0
votes
3 answers
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.
below is my model.

parteek kumar
- 1
- 2
0
votes
2 answers
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 table to enroll student in enrollment table.
DB…

Kael
- 161
- 2
- 13
0
votes
1 answer
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
session_type
Here's the relationship
public…

Kael
- 161
- 2
- 13
0
votes
3 answers
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 with for loop.
public function…

Kael
- 161
- 2
- 13
0
votes
0 answers
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 to JSON field.
in my model I do:
protected…

TheWebs
- 12,470
- 30
- 107
- 211
0
votes
2 answers
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…

Kael
- 161
- 2
- 13
0
votes
1 answer
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
class categorie extends Model
{
// tried by adding…

Usman Khan
- 56
- 8
0
votes
2 answers
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 files comes?

Shourov Shahadat
- 13
- 4
0
votes
1 answer
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 on…

usersuser
- 167
- 12
0
votes
1 answer
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:
PHP Fatal error: Maximum execution time of 60…

user3274489
- 186
- 2
- 4
- 15
0
votes
1 answer
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-03-13

web pakistan
- 444
- 1
- 4
- 16