#### Category : laravel-models

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 task_id so that the assignees of the task ..

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 to YYY, after this, they should be included. Is there any ..

i need to make the post accepts as many language as i need so i have tow models post and language in post model: public function languages(){ return $this->belongsToMany(AppModelsLanguage::class); } in my language model : public function posts() { return$this->belongsToMany(AppModelsPost::class); } post migration : Schema::create(‘posts’, function (Blueprint $table) {$table->id(); $table->string(‘title’);$table->text(‘body’); $table->boolean(‘puplished’)->default(false);$table->bigInteger(‘user_id’)->unsigned(); ..

I have a simple LIvewire component consisting of a form to create a new User, and it work, i can tell since i’ve been asked to write tests after the project already reached staging. The Livewire component use a new User instance (non presisted, i.e. user->exists is false) to store inserted data before persisting it, ..

trying to define a model mutators <?php namespace App; use IlluminateDatabaseEloquentModel; class Custom_fields extends Model { protected $table = ‘custom_fields’; public function set_contentAttribute($value){ return unserialize($value); } } accessing the field _content and unserialize the value of the field so I can get an array automatically on retrieve but seems not working. Any help, ideas? Source: .. Read more 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. Sourc..

I have two models (let’s say TestModel_1 and TestModel_2), between which there is a relationship "hasMany" TestModel_1.php: protected $fillable = [‘par_id’, ‘par_attr_1’, ‘par_attr_2’]; public function parentAttr () { return$this->hasMany(‘AppModelsTestModel_1’, ‘par_id’, ‘child_id’); } TestModel_2.php: protected $fillable = [‘child_id’, ‘child_attr_1’, ‘child_attr_2’]; public function childAttr() { return$this->belongsTo(‘AppModelsTestModel_2’, ‘par_id’, ‘par_id’); } After determining the relationship between the ..
I have two models (let’s say TestModel_1 and TestModel_2), between which there is a relationship "hasMany" TestModel_1.php: protected $fillable = [‘par_id’, ‘par_attr_1’, ‘par_attr_2’]; public function parentAttr () { return$this->hasMany(‘AppModelsTestModel_1’, ‘par_id’, ‘child_id’); } TestModel_2.php: protected $fillable = [‘child_id’, ‘child_attr_1’, ‘child_attr_2’]; public function childAttr() { return$this->belongsTo(‘AppModelsTestModel_2’, ‘par_id’, ‘par_id’); } After determining the relationship between the ..
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 table |——————————————–| | id | user_name | … | … | |——————————————–| | 1 | megamanx | … | … | | 1 .. Read more I’m using this code: AppModelsCity::create([‘name’ => ‘Los Angeles’ , ‘state’ => ‘CA’]); how to get its id? Sourc.. Read more you can see a part of my database in the image below: the goal of this design was to able the admins send alerts to users filtered by center and field(dynamically). if you think this is a bad design tell me (please say why and how should I improve my design). now if I want .. Read more I have 2 models: Invoice and InvoiceItems and these models are connected with invoice_id: Schema::create(‘invoice_items’, function (Blueprint$table) { $table->bigInteger(‘invoice_id’)->unsigned();$table->foreign(“invoice_id”)->references(‘id’)->on(‘invoices’)->onDelete(‘cascade’); }); Invoice : class Invoice extends Model { protected $fillable = [ ‘profile_id’, ‘invoice_number’, …. ]; public function invoiceItems() { return$this->hasMany(‘AppInvoiceItem’); } } And InvoiceItems class InvoiceItem extends Model { protected \$guarded = ..