Questions tagged [laravel-models]

91 questions
0
votes
1 answer

create Update Actions for pivot table attribute on laravel nova belongsToMany Relationship

I have model looks like this folowing Product model code: public class Product extends Model { public function types() { return $this->belongsToMany(Type::class) ->withPivot('published'); } } and here the Types…
naticap
  • 379
  • 1
  • 5
  • 19
0
votes
2 answers

Laravel - How to get company detail based on employee and logged user

In my Laravel 8 application, I have the following models. Company protected $fillable = [ 'id', 'name', 'website', 'company_logo', 'registration_number', 'date_established', 'address', ]; Employee protected $fillable =…
user11352561
  • 2,277
  • 12
  • 51
  • 102
0
votes
2 answers

How to get products of a "main category" if a product is related to only one "subcategory"?

How do I get all products of a “main category” if a product is related to only one “subcategory”? A product is only related to a sub-category, while a sub-category is always part of the main category. So I want to have all products in the main…
0
votes
2 answers

Change database connection when using Laravel Auth

In a multi-tenant Laravel app, each tenant has its own database connection. So after the user has selected his database, I want to authenticate the user using Auth::loginUsingId. Still, no matter what I do, I cannot change the Users Model's…
0
votes
2 answers

Laravel Eloquent Model Syntax error or access violation on groupBy

MySQL structure id key display_name value details group created_at updated_at Laravel resource index public function index() { $settings = Setting::groupBy('group')->select('id','group as name')->orderBy('id', 'ASC')->get(); …
0
votes
1 answer

Sharing Laravel Eloquent Models Between Multiple Forked Repositories is possible?

In my Laravel project, I have different types of modules like employee, customer & vendor modules. Recently I split each module into a separate repository. Now if I adding a Model means, I need to duplicate it other repositories also. Is there is…
Poovarasu
  • 3
  • 1
0
votes
1 answer

Prevent duplicate queries and N+1 problem in Laravel collection

I'm currently working on a simple Laravel project where I need to get the posts of the users I'm following. With the code below, I can get the posts but I also add a lot of duplicate queries and an N+1 issue on the Authenticated user. So it's…
Jazzman
  • 85
  • 1
  • 8
0
votes
1 answer

Query many to many relationship for a user in Laravel

I have an 'Admin' model which has a manyToMany relationship with a 'Priv' model. There is a pivot table named 'admins_privs' which links the two together, as many Admin's can have many privileges. What I need to do is to be able to do (in Blade) is…
0
votes
3 answers

How to show bank balance through transactions in laravel

I have Bank table and transaction table. The relationship is one-to-many, so a bank may have many transactions. Transaction table has the bank foreign key(bank_id). and each transaction has a column 'type' which is either credit or debit. I want to…
0
votes
1 answer

Relations in laravel with model

The first i´m sorry for this question, i know that maybe it´s very bad. I´m reading much for relation with model in laravel but i don´t understand i don´t know to apply. my problem it´s: i have one Model session and i have one model patient one…
scorpions78
  • 553
  • 4
  • 17
0
votes
1 answer

How do i get data once in model and use the same data in multiple views passing through controller in laravel 8.x

For example, I want data from 3 models to MyModel4. $model1data = MyModel1::getList(); $model2data = MyModel2::getList(); $model3data = MyModel3::getList(); Purpose of getting these data is to prepare my create view, edit view and show view based…
0
votes
2 answers

What is the bast solution in this case

I would like to get your recommend. // Solution one $total_user=User::count(); $active_user=User::where('active', 'active')->count(); // Solution two $user = User::all(); $total_user=$user->count(); …
0
votes
1 answer

How to make all column fillable by default of every newly created table in Laravel

In each Laravel model, I want to declare fillable like the following. protected $fillable = [ 'object_name','attributes','item','cost','status','category', 'object_id','status','customer_id','provider_id' ]; After that, I can insert…
user13134426
0
votes
0 answers

Laravel One to Many and Many to Many for the same Model

I am trying to make a task management system. Users can create a task and assign multiple users to the task. So the task table will have a user_id for identifying the user who created the task. There is a pivot table that consists of user_id and…
0
votes
1 answer

Laravel: active column that behave like softdelete

I have a model accounts in Laravel that uses Softdeletes. Beside that, I want another column called active, that behaves kinda the same. If its sets to XXX then all Account:: calls shouldnt include them in the return. Until I set the active value…
Introser
  • 161
  • 1
  • 12