Category : orm

Use of undefined constant tweet – assumed ‘tweet’ (this will throw an Error in a future version of PHP) (View: C:xampphtdocssiteWeStudyresourcesviewshome.blade.php) @extends(‘layouts.app’) @section(‘content’) <div class="container-home"> @foreach ($tweets as $tweet) <div> <p> {{tweet.users.name}} </p> <p> {{tweet.created_at}} </p> <p> {{tweet.content}} </p> </div> @endforeach </div> @endsection Sourc..

Read more

Have a model, from controller, I need access this Model db fields. Code in controller: $crud -> get() -> getAttributes(); //$crud->attributesToArray() print_r($crud); I was able to get entire table fields, but I need only fields, which are selected. Need dynamically show table with selected fields only, which can change during run time. Sourc..

Read more

Sorry if the title is confusing (feel free to edit). I’m currently working on a project on Laravel and i’m trying to contest the idea of using the pivot table for a many-to-many relation. So for instance, my GroupEvent (model,controller,schema) binds both barrels into groups (and vice versa) where barrels belong to many groups and ..

Read more

How can I select on whereHas() some columns in relation. My current query looks like as it follows Location::select([‘title’]) ->withCount([‘job’ => function($q) { return $q->where(‘language_id’, 1)->whereNull(‘deleted_at’); }])->whereHas(‘country’, function ($q) { return $q->where(‘id’, ‘=’, 80); })->get(); and I tried Location::select([‘title’, ‘id as value’])->withCount([‘job’ => function($q) { return $q->where(‘language_id’, 1)->whereNull(‘deleted_at’); }])->whereHas(‘country’, function ($q) { return $q->select(‘title’, ‘iso3’)->where(‘id’, ..

Read more

I have three models and I want to see a list of objectives filtered by subject, grouped by years. MODELS class Objective extends Model { public function subjects() { return $this->belongsTo(‘AppModelsSubject’); } public function yeargroups() { return $this->belongsTo(‘AppModelsYeargroup’); } } class Subject extends Model { public function objectives() { return $this->hasMany(‘AppModelsObjective’); } } class Yeargroup ..

Read more

Let’s say I have a model Foobar with relationships named baz and quux. I would like to query all Foobar that do not have either relationship; meaning I only want to select Foobar where BOTH baz and quux relationships are absent. I tried four different ways: // Attempt 1 Foobar::doesntHave(‘baz’)->doesntHave(‘quux’)->get(); // Attempt 2 Foobar::doesntHave(‘baz’, ‘AND’)->doesntHave(‘quux’, ..

Read more

Please see edit at bottom of question. Let’s say I have a model Foobar with relationships named baz and quux. I would like to query all Foobar that do not have either relationship; meaning I only want to select Foobar where BOTH baz and quux relationships are absent. I tried multiple different ways: // Attempt ..

Read more

i have 3 Models VideoTopic, Video, VideoProgress that the relations are as below: VideoTopic: /** * topic to videos Relation * * @return IlluminateDatabaseEloquentRelationsHasMany */ public function videos() : IlluminateDatabaseEloquentRelationsHasMany { return $this->hasMany("AppVideo", "topic_id"); } Video: /** * video to topic relation * * @return IlluminateDatabaseEloquentRelationsBelongsTo */ public function topic() : IlluminateDatabaseEloquentRelationsBelongsTo { return $this->belongsTo("AppVideoTopic", ..

Read more

In my controller I have something like this: public function getRelatedModel(Model $modelA) { return $modelA->related; } And in my "ModelA" I have a function: public function getRelatedModel() { return $this->hasOne(‘AppModelB’); } Now the problem is that my frontend expects an object that is not empty or an error from the backend, but if the ModelB ..

Read more

This question pertains to Laravel 7. I have two models, let’s say Post and Comment, in a typical one-to-many relationship. Both the relationship and its inverse are defined. When making the migrations for their database tables, I did NOT make the post_id on the Comment table nullable. I figured making it non-nullable is a reasonable ..

Read more

I just started learning laravel. I don’t know how can I fetch data inside a controller, I want to use that data inside a controller to make more rules. //Get Data From Database $db = DonorDetail::where(‘donation_id’, $paytmResponse[‘ORDERID’])->get(); $name = $db[‘donor_name’]; $email_id = $db[’email_id’]; DonorDetail is my model to connect to my database. I tried this ..

Read more

Is there a way to use additional conditions when defining an eloquent relationship in a model? Let’s say I have: public function researchtopic() { return $this->belongsTo(‘AppResearchTopic’, ‘taggable_id’); } But i want to add an additional where condition to use a 2nd column in the relationship as well. How would I add a 2nd condition for: ..

Read more

My User.php Model function is this public function send_connection_requests() { return $this->hasMany(‘AppModelsConnectionRequest’,’from_user’); } public function received_connection_requests() { return $this->hasMany(‘AppModelsConnectionRequest’,’to_user’); } and my coonectionRequest realtionship is this-> public function send_connection_requests() { return $this->belongsto(‘AppUser’,’id’); }` public function received_connection_requests() { return $this->belongsto(‘AppUser’,’id’); }` ` When I am calling function @foreach (Auth::user()->send_connection_requests as $request) {{request->to_user}} @endforech I’m only getting ..

Read more

Having a hard time understanding how to order my Laravel model by a nested relationship. Here are the Models. User.php // Has many small_groups through a pivot table public function small_groups() { return $this->belongsToMany(‘AppModelsSmallGroup’)->withPivot(‘type’)->withTimestamps(); } SmallGroup.php // Has many SmallGroupLessons public function small_group_lessons() { return $this->hasMany(‘AppModelsSmallGroupLesson’); } SmallGroupLessons.php // Has many SmallGroupLessonComments public function small_group_lesson_comments() ..

Read more

I have these two models with one to one relationship. "products" id name minimum_required "product_data" id product_id price oh_hand I want to get the count of product_data where its on_hand is less than its related product’s minimum_required. I’ve tried subqueries and I still can’t figure it out. The query I want may looks something like ..

Read more