Category : polymorphism

This is my update method, I’m using simple polymorphic relation morphTo and morphOne. I’m having trouble in updating product model. public function update(Request $request, Product $product) { $product->name = $request->name; $product->price = $request->price; $product->discount = $request->discount; $product->category_id = $request->category; $product->brand_id = $request->brand; $product->is_active = $request->is_active; if($request->hasFile(‘url’)) { $image = $request->file(‘url’); $filename = $image->getClientOriginalName(); $image->move(public_path(‘storage/products’), $filename); ..

Read more

i have posts and images table and there is polymorphic relation between them . i want to upload image in postman, but when i send values , gives me this error : BadMethodCallException: Call to undefined method AppModelsImage::getClientOriginalName() i don’t know what is wrong with my image model image model : class Image extends Model ..

Read more

i have an API .. with posts and users .. and polymorphic relation between images and posts and users .. for posts i want to upload multiple image , so this is my store() method in postController : public function store(Request $request ) { $post = new Post; $post->category_id = $request->get(‘category_id’); $post->title = $request->get(‘title’); $post->body ..

Read more

i’m building an API with laravel 8 . i want to add posts with images , so i have two tables : images and posts. this is my post table : Schema::create(‘posts’, function (Blueprint $table) { $table->id(); $table->unsignedBigInteger(‘category_id’); $table->unsignedBigInteger(‘user_id’); $table->string(‘title’); $table->longText(‘body’); $table->string(‘video’)->nullable(); $table->string(‘study_time’); $table->integer(‘likes’)->nullable(); $table->tinyInteger(‘status’)->nullable()->comment(‘status is 1 when a post is active and it is ..

Read more

i’m building API with laravel 8 and want to add comments and replies for posts with polymorphic relation (because i have posts and analysis that they have comments.) so i created my tables. my post table : Schema::create(‘posts’, function (Blueprint $table) { $table->id(); $table->unsignedBigInteger(‘category_id’); $table->unsignedBigInteger(‘user_id’); $table->string(‘title’); $table->longText(‘body’); $table->longText(‘picture’); $table->string(‘study_time’); $table->integer(‘likes’)->nullable(); $table->tinyInteger(‘status’)->nullable()->comment(‘status is 1 when a ..

Read more

I am trying to implement a polymorphic relationship using the documentation example on the Laravel site with Posts, Pages and Comments. However, in my case, I am storing the model type in a separate table: namespace AppModels; use IlluminateDatabaseEloquentModel; class CommentModelType extends Model { protected $guarded = []; public const TYPE_POST = 1; public const ..

Read more

I have an app with following models and relations: Contact morphs many Values: public function customFieldValues() { return $this->morphMany(Value::class, ‘model’); } Value belongs to CustomField: public function customField(): BelongsTo { return $this->belongsTo(CustomField::class); } CustomField belongs to Validation: public function validation(): BelongsTo { return $this->belongsTo(Validation::class); } I wanted to add a shorthand for value validation, so ..

Read more

I’m trying to bind a scope function in the query builder from a polymorphic relationship. Here’s what I currently have class ParentModel extends Model { public function morphable() { return $this->morphTo()->withMorph([ ChildOne::class => [‘image’], ChildTwo::class => [‘item.image’] ]) } } Assume that ChildTwo has a belongTo relationship to ChildOne, and ChildOne has a relationship called ..

Read more

I would like to use a ‘userables’ table to store user relationship to various other models, such as ‘Projects’ and ‘Actions’. The user relationship also has an attribute, such as "Owner" or "Contributor". I’m having trouble syncing (and/or attaching and detaching) the relationships with this additional attribute, despite trying various similar posts and scrutinising the ..

Read more

I have an Task model but I require that a Task can have a different structure based on the type. From my research it looks like I should use a one-to-many poly relationship for the Task and Types. Tasks id – int taskable_id – int taskable_type – string completed – datetime StandardTask id – int ..

Read more

Here i want to upload multiple images for each product. i know should uses Laravel Relationships and Polymorphic. did, but can not store images in image table and store other product information in Products table. this is Images table schema: public function up() { Schema::create(‘images’, function (Blueprint $table) { $table->id(‘id’); $table->text(‘file’); $table->unsignedInteger(‘imageable_id’); $table->string(‘imageable_type’); $table->timestamps(); }); ..

Read more

I am trying to implement Laravel-style polymorphic relationships between entities (one-to-many and many-to-many). For example, one (or more) Comment entities can belong to Post and Video entities (1:n). In Laravel I can add commentable_type and commentable_id fields to the entity to establish the relationships. Does EF core provide such functionality? Of course I can manually ..

Read more