Category : eloquent–relationship

I am trying ORM one to one relationship. I dont know why it cant recognize model class phone. code as follows. Phone.php <?php namespace AppModels; use IlluminateContractsAuthMustVerifyEmail; use IlluminateDatabaseEloquentFactoriesHasFactory; use IlluminateDatabaseEloquentRelationsHasOne; use IlluminateFoundationAuthUser as Authenticatable; use IlluminateNotificationsNotifiable; class User extends Authenticatable { use HasFactory, Notifiable; /** * The attributes that are mass assignable. * * ..

Read more

this is my table => table image //This is my controller public function listUserStripeActionableRequests(Request $request) { return $model = UserRequest::whereNull(‘deleted_at’) ->with(‘oldPackage’) ->get(); } userRequest.php public function oldPackage() { return $this->hasOne(Package::class, ‘id’, ‘old_package_id’); } I need to get data according to package_type in the table if package_type == 1 then i need to get data from ..

Read more

I’m facing one problem and I can’t find the perfect and best optimized solution. So I’m kindly asking for your opinion. Here’s what bothering me. I’ve got a serialized array from DB that looks like this: a:6:{s:13:"property_type";s:1:"1";s:16:"property_feature";a:2:{i:0;s:1:"3";i:1;s:1:"4";}s:19:"property_offer_type";s:1:"5";s:19:"property_built_type";a:1:{i:0;s:2:"10";}s:24:"properties_office_phones";s:2:"13";s:15:"property_labels";a:1:{i:0;s:1:"8";}} Here is the non-serialized version for more clarity: Array( [property_type] => 1 [property_feature] => Array ( [0] => ..

Read more

How can I get the total of the by the relationship I need to display the final total of each shops instead of displaying the individual order amounts. Here’s the relationship in the Venue model //! Orders public function orders() { return $this->hasMany(AppEntitiesOrdersOrder::class); } Here’s how my Dashboard Controller function class DashboardController extends Controller { ..

Read more

I am gathering data from 2 different tables. Below is my array so far and code I am using in my controller. $resources = Resource::with(‘type’)->get(); { id: 1, title: "ab est molestiae eum ratione soluta dolores facilis", description: "Enim blanditiis necessitatibus cum. Ut ipsam sed animi. Omnis alias praesentium quia iure fuga aut.", featured: null, ..

Read more

I am using beyondcode/laravel-comments (https://github.com/beyondcode/laravel-comments) and I try to specify columns I want to get from commentator. here is the code: $comment = $post->comments()->with(‘commentator’, function ($query) { $query->select(‘commentator.name’, ‘commentator.email’); //or $query->select(‘users.name’, ‘users.email’); })->latest(); I am getting error that said Undefined table: 7 ERROR: missing FROM-clause entry for table "commentator" // or users How can I ..

Read more