Every category in my simple CMS should be have one or multiple users as owner, this owners should be access to what category associated with them whey they are logging to system, you can suppose every category has one or many user that they can access them, for example: manager,editor or writer, each of this ..
Category : relationship
I am trying to get records which has empty fields with relationship. And my Deal model like that. <?php namespace AppModels; class Deal extends Model { use HasFactory; use SoftDeletes; protected $fillable = [ ‘id’, ‘creator_user_id’, ‘user_id’, ‘owner_name’, ‘person_id’, ‘person_name’, ‘stage_id’, ‘title’, ‘value’, ‘currency’, ‘formatted_value’, ‘status’, ‘won_time’, ‘note’, ‘source’, ‘gender’, ‘nationality’, ‘city’, ‘language’, ‘passport_number’, ‘arrival_airport’, ..
I have 2 separate many-to-many relationships, for 2 separate purposes, but they are between the same 2 tables. I’m wondering what the best practice is for organizing this? Here’s a specific example. I have a tasks table and a users table. A task can have many assignees (users), and it can also have many supervisors ..
I’m trying to return the user name who submitted an article, but unable to access this via an eloquent relationship. Models/Thing public function users() { return $this->belongsTo(User::class); } with user_id stored in the things table However this dump isn’t returning user data: dd($this->thing->users->name); Error: Attempt to read property "name" on null Sourc..
Problem 1 – Root composer.json requires gabrielbull/ups-api ^0.8.0 -> satisfiable by gabrielbull/ups-api[0.8.0]. – gabrielbull/ups-api 0.8.0 requires php ^5.5 || ^7.0 -> your php version (8.0.0) does not satisfy that requirement. Problem 2 – Root composer.json requires mehedi-iitdu/laravel-paystack dev-master -> satisfiable by mehedi-iitdu/laravel-paystack[dev-master]. – mehedi-iitdu/laravel-paystack dev-master requires php ^7.0 -> your php version (8.0.0) does not ..
I have two tables developer table and skill table which are linked with many to many relationship developer_skill table. I want to store developer_id and skill_id is in pivot table. but when developer add their skills and submit it return error. on developer table data add but in pivot table data not added. error SQLSTATE[23000]: ..
I have a Eloquent Model AppListing which belongsTo AppProduct public function product() { return $this->belongsTo(Product::class); } In the Listing Controller, I’m trying to get a specific listing with 2 columns (name, keywords) from the product table with it. public function readListing(Request $request, $listingId) { $query = Listing::query(); $item = $query->with([‘product’ => function (Builder $query) { ..
I have been trying to get all authors from collections of books. $books = Books::all(); foreach($books as $book){ $book->author … This code will work, but i want to get all author without using loop $allAuthorsThruBooks = Books::someQueryMaybe(); $allAuthorsThruBooks will show list of author. Thanks! Sourc..
I am coding CRM for a client. Data table with flexible column names requested from me. In order to achieve this, I have configured the database as follows. I can bring the columns of the projects according to the id value of the user and reflect them on the front face. But I couldn’t associate ..
2 tables – client and client_status Table client: id client_status_id name This table contains 1 record with client_status_id and name filled. Table client_status: id name This table also not empty Models for these tables: class Client extends Model { public function status() { return $this->belongsTo(ClientStatus::class); } } and class ClientStatus extends Model { protected $table ..
I have tables emails and email_attachments as follows: Schema::create(’emails’, function (Blueprint $table) { $table->id(); $table->string(’email’)->nullable(false); $table->string(‘subject’)->nullable(false); $table->text(‘body’)->nullable(false); $table->timestamps(); }); Schema::create(’email_attachments’, function (Blueprint $table) { $table->id(); $table->foreignId(’email_id’)->nullable(false); $table->string(‘file_name’)->nullable(false); $table->string(‘file_path’)->nullable(false); $table->foreign(’email_id’)->references(‘id’)->on(’emails’); }); And my models classes Email and EmailAttachment as follows: class Email extends Model { use HasFactory; protected $fillable = [’email’, ‘subject’, ‘body’]; function attachments() { ..
I am building a message system where a Team can send a message to all users and a user can send a message to one specific Team I am having trouble trying to decide the relationships between the Team, Message, User Models My idea would be to use the same table for sending messages with ..
Hello I am trying to fetch menus and its children along with permissions assigned to a role. How can i achieve this via eloquent relations. tables are roles, menus, role_menus. user will only see those menus which he have access to. here is my code: Here is My Controller way $menuList = Menu::tree()->with(‘roleMenus’)->where(‘per_select’,’=’,0); Here is ..
I have the following problem. It turns out that I want to access a relation of a model, or rather an attribute of a User relation with the model itself that I’m manipulating, but it throws me the error: Attempt to read property "name" on null. I show you my code. Image model <?php namespace ..
I am trying to make 3 tables relationship like this, users id name roles id name companies id name company_role_user user_id role_id company_id Relationships in User.php model public function companies() { return $this->belongsToMany(Company::class, ‘company_role_user’, ‘user_id’, ‘company_id’); } public function roles() { return $this->belongsToMany(Role::class, ‘company_role_user’, ‘user_id’, ‘role_id’); } public function role() { // relationship to get ..
I need to check if user id exists in foreign table. I have two three tables which are staffs, packaging and cutting. Both the tables packaging and cutting has staff_id column I need to check if the staff belongs to packaging or the cutting. So how do I achieve this. Packaging table Schema::create(‘packaging’, function (Blueprint ..
I have this platform (that uses Backpack for the Admin Cruds) in which I want to have various types of products (shoes, sweatshirts, pants, shirts…). I’m encountering a bit of problems coming out with an efficient and simple way to organize the app structure. I want to avoid having all the necessary fields for the ..
i have a problem with function attach(). I have created 3 tables. 1 table is for added movies. Table 2 applies to the movie categories. 3 table is a collection of movie ID and category ID. A combination of many to many. When i want add a new video with category from form this i ..
i have 4 database tables : Broadcasters | id | public_name | …. | Articles | id | title| …. | Comments | id | user_id| article_id | …. | users | id | login| …. | i would like to list all broadcasters with number of article of each one (broadcaster) and the totale ..
I need help. I have a problem. In this part of the code Relationship "doesntHave" doesnt work and return full list of the users $searchData = $request->searchData; $users = User::doesntHave(‘roles’)->where(‘id’,’like’, ‘%’ . $searchData . ‘%’) ->orWhere(‘name’, ‘like’, ‘%’ . $searchData . ‘%’) ->orWhere(’email’, ‘like’, ‘%’ . $searchData . ‘%’) ->limit(8) ->get(); return response()->json($users); Sourc..
Is there a way in Laravel to define a relationship that hasMany relations to one but the ids do not appear in another hasMany relation? For example, a SpecificCar hasMany AdditionalManufacturerProperties and hasMany ExcludingManufacturerProperties, so I want all properties that the SpecificCar got with the additional ones but without the excluding ones. Could anybody help? ..

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 ..
Hey community, I have two tables with three columns and would like to output the name based on the ID’s. Clienttable created_by_user updated_by_user deleted_by_user 1 4 2 Usertable id name 1 Michael 2 Tobias 3 Franz 4 Holger in frontend: {{client.created_by_user.name}} -> Michael {{client.updated_by_user.name}} -> Holger {{client.deleted_by_user.name}} -> Tobias My relaitionship: public $belongsTo = [ ..
Hey community, I have two tables with three columns and would like to output the name based on the ID’s. Clienttable created_by_user updated_by_user deleted_by_user 1 4 2 Usertable id name 1 Michael 2 Tobias 3 Franz 4 Holger in frontend: {{client.created_by_user.name}} -> Michael {{client.updated_by_user.name}} -> Holger {{client.deleted_by_user.name}} -> Tobias My relaitionship: public $belongsTo = [ ..
I defined a relationship Author – Book then i am able to create a new book by doing this $author = new author(); $author->books()->create(); that works and also doing this in my view {{$author->books()->create()}} So every time the site is loaded i create a new book. I try to embed it in a small script ..