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

Read more

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

Read more

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

Read more

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

Read more

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

Read more

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() { ..

Read more

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

Read more

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

Read more

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

Read more

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

Read more

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

Read more

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

Read more