#### Category : relational-database

I’m using Laravel 8 to make a basic online ordering system. And in this project, every order is submitted within a user of the user who has signed in. So there is a One To One relationship between users table and orders table. Therefore, I have added these to the Models: Order.php: public function user() ..

I have two model named as Product and Category. In the products table i have category_id as as a foreign key of categories. Both table have title column. I want to search on both title and when it is related to categories table then all products of that category will come in result but when ..

I have a simple questions but I cant find any answer in internet. class Product extends Model { use HasFactory; public function variants() { return $this->hasMany(Variant::class); } } >>>$p->variants(); => IlluminateDatabaseEloquentRelationsHasMany {#4331} >>> $p->variants; => IlluminateDatabaseEloquentCollection {#4310 all: [ AppModelsVariant {#4319 id: "1", name: "VariantOne", created_at: null, updated_at: null, quantity: "2", product_id: "1", }, .. Read more I’m facing against this problem since yesterday. I have a db table called resources have a foreign key linked to another table called category. I’m trying to retrieve the description field in my blade view, but I get this error: Trying to get property ‘description’ of non-object. My blade view: @extends(‘templates.header’) @section(‘section’) <div class="p-10 grid .. Read more I’m trying to develop role based access control system with Laravel 8. I have tables following: users: -id -… roles: -id -slug permissions: -id -slug users_roles: -user_id -role_id roles_permissions: -role_id -permission_id I expect the system to work as follows: A user can have more than one role. A permission can be attach to more than .. Read more I’m using Laravel 8 to develop my project and in this project, I have applied OneToMany relationship between User Model and Role Model like this: User.php: public function role() { return$this->belongsTo(User::class); } Role.php: public function users() { return $this->hasMany(Role::class); } Now I want to edit users, so at edit.blade.php, I added this line for .. Read more i’m trying to filter the table using "with" and "whereHas" for the relation and have it follow a second second relation. Is it possible to do it with "with" or would it only be possible with "Joins"? Ticket >> StatusHistory (Last record) >> StatusName = ‘new’ ticket -id -name status_history – ticket_id – status_name_id – .. Read more i have column in database named orders, products, and order_product with relationship i want collect data in colums order by search invoice number(not PK id), the problem is how can i get data in products column ? this Order model : use HasFactory; protected$table = ‘orders’; protected $fillable = [ ‘no’, ‘spg’, ‘nama’, ‘hp’, .. Read more Currently I have finished my project which is a Movie Storage with Laravel 8 and for this project, I tried to apply these relationships: Movie AND Actor : Many To Many Movie AND Director : Many To One Movie AND IMDB : One To One Movie AND Genre : Many To Many And I have .. Read more I have some tables in my database and I’m trying to transact between them. My aim is to show the project name and the employees in that project in the form of cards on my projects page as in the image below. (Other than the method I mentioned, if there are better ways to do .. Read more Looked everywhere but couldn’t find an answer I have a similar query to this:$users = User::with(‘contact’)->get(); This would return something like: { "id":1, "name":"Foo", "contact":[ { "number":"123" }, { "number":"456" }, { "number":"789" } ] } I want to create another query with another relation that would return entries where the number is in ..

maybe you could help me about my current issue. I have Product that got some has many relations /** Inherits from : category, subcategory and model */ Product->hasMany(CategoryAttributes, $this->category) Product->hasMany(SubCategoryAttributes,$this->subCategory) Product->hasMany(ModelAttributes, $this->model) /** */ Product->hasMany(HideForSubcategoryAttributes,$this->subCategory) Product->hasMany(IgnoreForModelAttributes, $this->model) Now I need to implement something that gives me all attributes for the Product. collect the .. Read more 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 ..

I want to make a simple project to understand better the Laravel database relationships. So I decided to make a movie storage project which is holding some movie names and some informations about that movie, it should be look like this: So I wrote the relations between these fields like this: Movie AND Actor : ..

I have two tables as events and organisations. In an organization may have multiple events .In the past i was not familier with laravel so i created Events and Organizations Model. I added foreign key in the migration of events table as $table->bigInteger(‘organization_id’)->unsigned()->default(null)->nullable(); Now i can’t change organization_id to organizations_id because there are lots of .. Read more i want to create a relation between post and user table by foreign key user_id. But it is showing that error…."Error creating foreign key on user_id (check data types)" Sourc.. Read more In my Laravel project, I have a multiple rows in my DB table, similar to each other in every thing except ID, other column called stage Stages table ID name 1 first 2 second 3 third school Table ID name country city stage_id 1 test text test2 1 2 test text test2 2 3 test .. Read more Table schema Items id name :belongsToMany(Addon) // relations Addons id name :belongsToMany(Item) // relations addon_item addon_id item_id orders id :hasMany(Item) // relations item_order item_id order_id name // extra pivot attr price // extra pivot attr qty // extra pivot attr Now how do I define relation between order->items & addons so that I can get .. Read more I have a table that is linked to multiple other tables in a many-to-many fashion. In my example, pmds (primary medical doctors) are records in the users table that have a role_id that corresponds with pmd in the roles table; AND are associated with the sites table through the intermediate table site_user; OR are associated .. Read more I’m making a forum with Laravel 8. And for this project, I have a table named questions which holds the questions of that have been asked. And I also have a table named question_user that shows which user asked which question. And this is how it looks like: Now I want to show the question .. Read more I’m making a forum with Laravel 8. And for this project, I have a table named questions which holds the questions of that have been asked. And I also have a table named question_user that show which user asked which question. And this is how it looks like: Now I want to show the question .. Read more Good afternoon everyone! In my project I have to create a new user which will be a restaurant directly in the user’s registration. Once registered, I gave the possibility to associate more types of restaurant to the logged in user. I made already migrations and relations everything is working. This is what i wrote to .. Read more I define the relation in Company table: public function country() { return$this->belongsTo(Country::class, "country_id")->withDefault([‘country’ => ‘unknown’]); } When I use the following code in the controller show function it works: // get name of country $company->country =$company->country()->pluck(‘country’); But if I use the same code in the index function in a loop, I get an ..
$posts = Post::with(‘user’)->search(‘title’,$this->search)->latest()->paginate(5); Sourc..