#### Category : polymorphism

I have a unique feat I am trying to accomplish, and I was wondering if anyone else has done it, before I take on developing it myself. I am familiar with Many-to-Many Polymorphic Relations in Laravel, where multiple different Models (i.e. Post, Product) can have a relationship with one Model (Tag) through an intermediate table ..

So i’m basicly trying to do a polymorphic relationship of an other polymorphic relationship. So based on the doc’s wich give this exemple : posts id – integer name – string users id – integer name – string images id – integer url – string imageable_id – integer imageable_type – string I would like to ..

I need to map multiple "types" pointing to same model over a polymorphic relationship. This because in my application i set a laravel-permission authentication package that fails if i don’t include his model type in AppServiceProvider.php boot method. I’ve got a Resource model that has a polymorphic relationship with User model and Equipment model. Every ..

I have problem. I use four tables (example marks, cars, motobikes, autotrains) in Laravel One To Many (Polymorphic) and i want order marks list by other tables price column. How? class Car extends Model implements TranslatableContract { public function marks() { return $this->morphMany(Mark::class, ‘marksable’); } } class Motobike extends Model implements TranslatableContract { public function .. Read more I’m trying to take advantage of the Laravel’s Polymorphic Relationships I’m building an app where I have 3 tables: products, expenses and hunts. Each product, expense or hunt belongs to a category. I used to have 3 other different tables product_categories, expenses_categories and hunts_categories but I didn’t like doing it this way so I did .. Read more I have 2 tables related to creating credit notes which allows selecting multiple invoices. I was able to store the data into a database using postman(api controller), but having problems in API integration with the frontend. Database Credit Note id credit_note_group_id invoice_id code remarks amount 7 4 5 CN0006 cn remarks 150.00 8 4 8 .. Read more I have 2 tables related to creating credit notes which allows selecting multiple invoices. I was able to store the data into a database using postman(api controller), but having problems in API integration with the frontend. It returns "Internal Server Error" when I submit the form… Database Credit Note id credit_note_group_id invoice_id code remarks amount .. Read more I have Product and Hunt models in my Laravel app My current tables structure products id – integer image_url – string hunts id – integer image_url – string video_url – string I think it’s better to use Laravel Polymorphic Relationships in this case but there are three possible approaches and I’m not sure which one .. Read more I’m building an inventory management app that keeps track of sales, expenses and much more. At first I only had products and expenses tables products id – integer product_category_id – integer expenses id – integer expense_category_id – interger Then I was asked to add a feature when a user can add spying products with different .. Read more I want to create a somewhat polymorphic laravel morphTo. I want to create multiple ‘dimension’ polymorphic properties but don’t see a need to create four separate (identical) tables for their values (width, length, height, weight). The problem is, I just stumbled upon how it creates the linking and I’m not quite sure how to specify .. Read more I’m trying to setup a polymorphic relation between Users & Organizations, to Repositories. Repository.php public function owner(): MorphTo { return$this->morphTo(); } User.php public function repositories(): MorphMany { return $this->morphMany(Repository::class, ‘owner’); } Organization.php public function repositories(): MorphMany { return$this->morphMany(Repository::class, ‘owner’); } repository_has_owners table: id repository_id owner_id owner_type created_at updated_at 1 1 1 AppUser However, ..

I’m building a set of abstract models in php to describe custom products for a website. The website is currently running laravel and I’m wondering if what I want to do is possible using laravel relationships. Essentially what I want to do is have one main object (model) be capable of ‘attaching’ other sub-models with ..

I have a challenge in laravel polymorph many to many relationship. i am using this database architecture products id – integer name – string price – float articles id – integer title – string description – string tags id – integer name – string taggables tag_id – integer taggable_id – integer taggable_type – string how ..

Is it possible to get the connected items in 1 query of all the relations in laravel, so this function gets all the releations but is it also possible to query the items with it public function bookmarkItems(Bookmark $bookmark): IlluminateHttpJsonResponse { return response()->json($bookmark->items()->get()->toArray()); } the functions returns this [ 0: {id: 1, bookmark_item_id: 2, bookmark_item_type: ..

I am having some trouble wrapping my head around how to structure this, as it seems to be the "inverse" of all of the Laravel documentation and other examples I’ve found. I’m probably over-thinking it. All of the examples I’ve found assume that you have one fixed datatype (e.g. Comment) that can then be attached ..

I have this problem about "How to make a polymorphic relationship out of this?". So, here I have 4 tables. The use case is that table cashflows is used for collecting data of incomes and outcomes of venues and departments, and since there is two types of income and outcomes (venues and department), I create ..

I have a transactions table that has transaction types that morph to TopUpTransaction, DeductTransaction, etc. that holds their specific informations (as they have different fields). Now I have a transaction type SecurityDeposit that doesn’t need to have a dedicated model as it doesn’t need any extra information. I can make it work with default morph ..

I need a list of class names of all models, that have a OneToOne or OneToMany polymorphic relationship definition to another specific model. this list must not be based on the actual existing relations in the corresponding database table, but on the code definition. Example: Class A,B and C have a polymorphic one-to-one or one-to-many ..

I have 3 models, User, Member, Team. A User can have many Members belonging to it. It can then assign those members to Teams that belong to User. A Team can also have multiple Members belonging to it. I am using a polymorphic relationship with Member so that both User can create a member that ..

I am now trying to learn polymorphic type relations, but I have problems deleting the data Is there a solution to solve the problem or some reference to solved this problem ? Thank you /** * Add Comment * * @param [type] $id * @return void */ public function addCommentPost(Request$request, $id) { Post::find($id)->comments()->create([ ‘body’ ..

i want to upload multiple image in laravel 8 with API. i have polymorphic relation between posts and images and other tables (user , .. ) so my post columns are : user_id , category_id , title , body , study_time , tags and the image table : imageable_id , imageable_type , image , path ..

I’d like to create a relation for a Group Model, which can have members of different morph types through a pivot table ‘group_members’. And this is what my structure currently looks like: Classes: Class Group { public function Members() { return $this->hasMany(GroupMember::class, ‘group_id’); } // Now here is where i want to return all the .. Read more 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); ..