Questions tagged [laravel-models]

91 questions
0
votes
1 answer

laravel model mutators not accessing the defined field

I am trying to define a model mutator
Juliver Galleto
  • 8,831
  • 27
  • 86
  • 164
0
votes
2 answers

Laravel type hinting, id return null on model save

I am trying to use type hinting for storing the value. public function store(Model $model, ModelRequest $request) { $model->create($request->validated())->save(); dd($model->id); } But, Id is returning null.
parth
  • 1,803
  • 2
  • 19
  • 27
0
votes
0 answers

Laravel Route Model Binding Return False Owner of The Post

Good morning/afternoon/evening! I have 2 model, User and post User.php public function getRouteKeyName() { return 'user_name'; } public function posts() { return $this->hasMany(Post::class, 'by_id', 'id'); } I have two records in users…
Gwein
  • 109
  • 3
  • 14
0
votes
1 answer

Laravel active shipping methods

Table: Schema::create('shippings', function (Blueprint $table) { $table->id(); $table->string('name',64); $table->integer('price'); $table->enum('active', ['yes','no'])->default('yes'); …
Djozeph
  • 25
  • 3
0
votes
1 answer

I got error with route defined in laravel-modules

In Laravel Framework 6.18.35 I use "nwidart/laravel-modules": "^7.2", and I have an error defining a route to method wrinnten in routes. In Modules/Pages/Routes/web.php I have : Route::prefix('pages')->group(function() { Route::get('/',…
Petro Gromovo
  • 1,755
  • 5
  • 33
  • 91
0
votes
0 answers

How to optimize this query using model in Laravel

Actual Requirement. Select * from User, Student_basicinfo,Student_programs where User.id=student_basicinfo.student_id,user.id=student_programs.student_id; I want to use this query with model approach but i don't know how. there 3 different…
0
votes
1 answer

How can I make localized a non-localized model in Larvel Backpack?

I have a non-localized model: Article with the following properties: id, title, description; and I want to localize title and description. I have seen in the Laravel Backpack documentation that CRUDs can manage localized models using…
0
votes
0 answers

How to verify if an eloquent parent model exists in another connection in laravel?

I'm using the eloquent method has() to retrieve only rows where the parent exists and is not deleted and it's working well. But this doesn't work when am passing "user" as a parameter because the user is coming from a different connection. I have…
Etta
  • 339
  • 4
  • 10
-1
votes
1 answer

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…
-1
votes
1 answer

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'); } I'm trying to make this kind of URL, ex.:…
-1
votes
1 answer

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 $request) { $enrollments =…
Kael
  • 161
  • 2
  • 13
-1
votes
3 answers

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 artisan make:model Photo Staff Product The error I…
Ghulam Farid
  • 470
  • 4
  • 10
-1
votes
1 answer

How can I change a column time attribute to AM and PM for the blade view?

I have a table named time_entries and the column name is time_start. I'm inserting Carbon::now(); on it. The data stored in the column is 2021-08-26 09:51:37 and blade.php shows same result. Model TimeEntry: namespace App\Models; use…
kealaxshan
  • 338
  • 2
  • 14
-2
votes
2 answers

Cant return $couponDetails->couponName; value in laravel

$couponCode = $request->couponCode; // Get coupon details by coupon code $coupon = Coupon::where('couponCode', $couponCode) ->get() ->first(); $couponDetails = response()->json($coupon); return $couponDetails->couponName; That returns…
-2
votes
1 answer

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::get('/', function () { $data_for_view = [ …
yossi
  • 3,090
  • 7
  • 45
  • 65