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); ..
Category : polymorphism
i’m building an api with laravel 8 , and i have posts and image table with polymorphic relation between them , i want to upload image and store post in postController , but i can’t access the image of post , Even though post and image are saved in database ,but i think my controller ..
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 ..
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 ..

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 ..

i’m building an API with laravel 8 and i have posts and images table with polymorphic relation (because i have users and i use images for it too) so i want upload multiple images and i do it in postman , so when i upload images and enter posts fields with values ,like this : ..

i’m building an API with laravel 8 . i want to store image or images for my posts with polymorphic relation between posts and images(because i have users and analysis tables too and i need image for them), but i can’t upload and store images , when i send values in postman , like this ..
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 ..
i’m building an API with laravel. i have posts , comments and replies. i have a show method for display the comment and replies and i want show all of them, but i don’t know why i just can see the reply of that comment , not the replies of replies. about parent_id : if ..
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 ..
I have an Equipment model that is a Polymorphic Many-to-Many with a few other models. Here is the issue I can’t figure out. When an equipment is added to another model, the hours will change on the equipment each time. All other fields, sn, make, model are static. I want to set this up so ..
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 ..
I’m using a polymorphic one to one relationship to have multiple types of product that share some fields in order to optimise the db structure. I have a Product parent model and a Shoe model. The problem is that each time I store a product (both the Shoe and the Product) and the relationship happens ..
I’m using Backpack to create an Admin Panel for my project. I have a SoldProduct model (basically a physical item that has been sold to a customer), a Shoe model and a Sweatshirt model. There is a polymorphic relationship between them in order to have a separate table for each one of them, avoiding the ..

couldn’t find any answer on stackoverflow yet, so imma ask it by myself. My polymorphic relationships work kinda weird. I cannot retrieve Comments from the post, but I can retrieve Post from the specific Comment. My comment: And here is my code for relationships: (I am using Thread model as well, but it isn’t important ..
Using Laravel 7.X, I have a project that is becoming more complex by the time and I am feeling that I have to reorganize the way the Models was designed, but I am stucking to find a good solution. I have some doubts and would be nice if someone help me with some guides for ..
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 ..
since i am working on existing database and can’t change Data how do i insert in the relation that the taggable_type is (Firm) and not the default (Appfirm) Thanks Sourc..
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 ..
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 ..
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 ..
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(); }); ..
I have a notes model. Which has a polymorphic ‘noteable’ method that ideally anything can use. Probably up to 5 different models such as Customers, Staff, Users etc can use. I’m looking for the best possible solution for creating the note against these, as dynamically as possible. At the moment, i’m adding on a query ..
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 ..
I have an application where an Invoice can belong to the client or supplier. Now I used the morph things in my current scenario. I want to create the proper anchor by using the morph relation But I didn’t find the best way with Laravel Client.php class Client extends Model { /** * Get the ..