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..
Category : orm
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’ve worked with laravel a little in the past, but I’m trying to learn to use the Eloquent ORM. I’m migrating an old project and the original coder used crude data-container classes for the various SQL tables. (this is old code, likely written before many ORMs existed) I want to refactor this bundle of code ..
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..
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 ..
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’, ..
I am looking at my current project that I took over, and I notice that all the models written as PHP classes that extend Eloquent’s Model class are atomic entities, or, polymorphic entities (like there’s a user model, and then there’s special types of users). I was wondering if it is common to have models ..
i have to table with one to many relation First table is status: | id | product_id | status | created_at | |—-|————|——–|———————| | 1 | 1 | 0 | 2018-01-01 00:00:00 | | 2 | 1 | 1 | 2018-02-01 00:00:00 | | 3 | 2 | 1 | 2018-01-01 00:00:00 | | 4 ..
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 ..
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’, ..
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 ..
I have a model with a one to many relationship and I want to see all records for the model grouped by the relationship. For example, I want to output something like this: One [1] Many [1] Many [2] Many [3] One [2] Many [4] Many [5] Many [6] so far with the code given ..
Let’s suppose I have these relations in my DB: Product id | name Category id | name Product-Category id | product_id | category_id I can easily build it using Eloquent’s Models using "belongsToMany" relations: Product has a "categories" public function called "categories" and Category has a "products" public function. Now, I have a page where ..
I have 2 models with a many to many relationship using Laravel and I want to insert into the relationship table upon using the save method. I have save method creating the new row for the child and I have access to the parent id. I need to insert a new row into the relationship ..
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", ..
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 ..
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 ..
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 ..
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: ..
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 ..
please what is the correct way of getting data from the MN table where one product has assigned multiple combinations of Mark / Model / Year. E.g. product with ID 1 has following in mmis table: id | product_id | mark_id | model_id | year_id 178 1 1 1 2 177 1 2 1 3 ..
i have a view which displays some places and i’m fetching this data from my API, the model places have many to many relationship with categories. Is there any way i can fetch both model data from the controller? Like i have this function to fetch all the places, how can i fetch their categories ..
Let’s say that i want to exclude certain instances of a vendor model from my queries, how can i add a global scope to that model instead of adding a where() condition to every query? Sourc..
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() ..
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 ..