Display data from 2 table - Property [name] does not exist on this collection instance
up vote
0
down vote
favorite
I try display data from table Course and Test, the relation is one-to-many.
course name | test name
___________________________
course name1 | test name 1
course name2 | test name 2
etc.
public $table = 'Course';
public function test()
{
return $this->hasMany('AppTest');
}
public $table = 'Test';
protected $fillable = ['name',];
public function course()
{
return $this->belongsTo('AppCourse');
}
TestController.php
public function courses() {
$courses = Course::with(['test'])->get();,
return view('admin.test.list_course', [
'courses' => $courses,
]);
}
list_course.blade.php
@foreach($courses as $course)
<tr>
<td>
{{ $course->name }}
</td>
<td>
{{ $course->test->name }}
</td>
</tr>
@endforeach
And I get error
Property [name] does not exist on this collection instance
Please, do you anybody know where is error? Thank you!!
php mysql laravel eloquent laravel-blade
|
show 1 more comment
up vote
0
down vote
favorite
I try display data from table Course and Test, the relation is one-to-many.
course name | test name
___________________________
course name1 | test name 1
course name2 | test name 2
etc.
public $table = 'Course';
public function test()
{
return $this->hasMany('AppTest');
}
public $table = 'Test';
protected $fillable = ['name',];
public function course()
{
return $this->belongsTo('AppCourse');
}
TestController.php
public function courses() {
$courses = Course::with(['test'])->get();,
return view('admin.test.list_course', [
'courses' => $courses,
]);
}
list_course.blade.php
@foreach($courses as $course)
<tr>
<td>
{{ $course->name }}
</td>
<td>
{{ $course->test->name }}
</td>
</tr>
@endforeach
And I get error
Property [name] does not exist on this collection instance
Please, do you anybody know where is error? Thank you!!
php mysql laravel eloquent laravel-blade
And which line in your code causes this error
– RiggsFolly
Nov 8 at 12:13
in blade {{ $course->test->name }}
– Sonya
Nov 8 at 12:16
Have you tried $course->test['name'] or $course->{'test name'}?
– Francesco Mineo
Nov 8 at 12:17
yes, i got error syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'
– Sonya
Nov 8 at 12:19
{'test name'} display empty rows
– Sonya
Nov 8 at 12:20
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I try display data from table Course and Test, the relation is one-to-many.
course name | test name
___________________________
course name1 | test name 1
course name2 | test name 2
etc.
public $table = 'Course';
public function test()
{
return $this->hasMany('AppTest');
}
public $table = 'Test';
protected $fillable = ['name',];
public function course()
{
return $this->belongsTo('AppCourse');
}
TestController.php
public function courses() {
$courses = Course::with(['test'])->get();,
return view('admin.test.list_course', [
'courses' => $courses,
]);
}
list_course.blade.php
@foreach($courses as $course)
<tr>
<td>
{{ $course->name }}
</td>
<td>
{{ $course->test->name }}
</td>
</tr>
@endforeach
And I get error
Property [name] does not exist on this collection instance
Please, do you anybody know where is error? Thank you!!
php mysql laravel eloquent laravel-blade
I try display data from table Course and Test, the relation is one-to-many.
course name | test name
___________________________
course name1 | test name 1
course name2 | test name 2
etc.
public $table = 'Course';
public function test()
{
return $this->hasMany('AppTest');
}
public $table = 'Test';
protected $fillable = ['name',];
public function course()
{
return $this->belongsTo('AppCourse');
}
TestController.php
public function courses() {
$courses = Course::with(['test'])->get();,
return view('admin.test.list_course', [
'courses' => $courses,
]);
}
list_course.blade.php
@foreach($courses as $course)
<tr>
<td>
{{ $course->name }}
</td>
<td>
{{ $course->test->name }}
</td>
</tr>
@endforeach
And I get error
Property [name] does not exist on this collection instance
Please, do you anybody know where is error? Thank you!!
php mysql laravel eloquent laravel-blade
php mysql laravel eloquent laravel-blade
edited Nov 8 at 12:11
RiggsFolly
68.6k1764109
68.6k1764109
asked Nov 8 at 12:05
Sonya
74
74
And which line in your code causes this error
– RiggsFolly
Nov 8 at 12:13
in blade {{ $course->test->name }}
– Sonya
Nov 8 at 12:16
Have you tried $course->test['name'] or $course->{'test name'}?
– Francesco Mineo
Nov 8 at 12:17
yes, i got error syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'
– Sonya
Nov 8 at 12:19
{'test name'} display empty rows
– Sonya
Nov 8 at 12:20
|
show 1 more comment
And which line in your code causes this error
– RiggsFolly
Nov 8 at 12:13
in blade {{ $course->test->name }}
– Sonya
Nov 8 at 12:16
Have you tried $course->test['name'] or $course->{'test name'}?
– Francesco Mineo
Nov 8 at 12:17
yes, i got error syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'
– Sonya
Nov 8 at 12:19
{'test name'} display empty rows
– Sonya
Nov 8 at 12:20
And which line in your code causes this error
– RiggsFolly
Nov 8 at 12:13
And which line in your code causes this error
– RiggsFolly
Nov 8 at 12:13
in blade {{ $course->test->name }}
– Sonya
Nov 8 at 12:16
in blade {{ $course->test->name }}
– Sonya
Nov 8 at 12:16
Have you tried $course->test['name'] or $course->{'test name'}?
– Francesco Mineo
Nov 8 at 12:17
Have you tried $course->test['name'] or $course->{'test name'}?
– Francesco Mineo
Nov 8 at 12:17
yes, i got error syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'
– Sonya
Nov 8 at 12:19
yes, i got error syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'
– Sonya
Nov 8 at 12:19
{'test name'} display empty rows
– Sonya
Nov 8 at 12:20
{'test name'} display empty rows
– Sonya
Nov 8 at 12:20
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Your test
relation on the Course Model is a one-to-many relation, meaning that there can be more than one test for every course, because of this the relation will return a collection
of all tests belonging to the course.
To display it in the View you could loop through all tests:
@foreach($courses as $course)
<tr>
<td>
{{ $course->name }}
</td>
<td>
@foreach($course->test as $test)
{{ $test->name }} <br>
@endforeach
</td>
</tr>
@endforeach
wohooo... thank you! work perfectly
– Sonya
Nov 8 at 12:31
Can I ask you on more thing please.. I try display question count. course name | test name | question count . I have relation between Test and Question 1:N . how can I do this, pls? In my Testcontroller, i have $courses = Course::with(['test'])->get(); $questions = $courses->question;
– Sonya
Nov 8 at 13:36
Could you accept this answer and make a completely new question, so you can explain better what the new problem is.
– Remul
Nov 8 at 13:45
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Your test
relation on the Course Model is a one-to-many relation, meaning that there can be more than one test for every course, because of this the relation will return a collection
of all tests belonging to the course.
To display it in the View you could loop through all tests:
@foreach($courses as $course)
<tr>
<td>
{{ $course->name }}
</td>
<td>
@foreach($course->test as $test)
{{ $test->name }} <br>
@endforeach
</td>
</tr>
@endforeach
wohooo... thank you! work perfectly
– Sonya
Nov 8 at 12:31
Can I ask you on more thing please.. I try display question count. course name | test name | question count . I have relation between Test and Question 1:N . how can I do this, pls? In my Testcontroller, i have $courses = Course::with(['test'])->get(); $questions = $courses->question;
– Sonya
Nov 8 at 13:36
Could you accept this answer and make a completely new question, so you can explain better what the new problem is.
– Remul
Nov 8 at 13:45
add a comment |
up vote
1
down vote
accepted
Your test
relation on the Course Model is a one-to-many relation, meaning that there can be more than one test for every course, because of this the relation will return a collection
of all tests belonging to the course.
To display it in the View you could loop through all tests:
@foreach($courses as $course)
<tr>
<td>
{{ $course->name }}
</td>
<td>
@foreach($course->test as $test)
{{ $test->name }} <br>
@endforeach
</td>
</tr>
@endforeach
wohooo... thank you! work perfectly
– Sonya
Nov 8 at 12:31
Can I ask you on more thing please.. I try display question count. course name | test name | question count . I have relation between Test and Question 1:N . how can I do this, pls? In my Testcontroller, i have $courses = Course::with(['test'])->get(); $questions = $courses->question;
– Sonya
Nov 8 at 13:36
Could you accept this answer and make a completely new question, so you can explain better what the new problem is.
– Remul
Nov 8 at 13:45
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Your test
relation on the Course Model is a one-to-many relation, meaning that there can be more than one test for every course, because of this the relation will return a collection
of all tests belonging to the course.
To display it in the View you could loop through all tests:
@foreach($courses as $course)
<tr>
<td>
{{ $course->name }}
</td>
<td>
@foreach($course->test as $test)
{{ $test->name }} <br>
@endforeach
</td>
</tr>
@endforeach
Your test
relation on the Course Model is a one-to-many relation, meaning that there can be more than one test for every course, because of this the relation will return a collection
of all tests belonging to the course.
To display it in the View you could loop through all tests:
@foreach($courses as $course)
<tr>
<td>
{{ $course->name }}
</td>
<td>
@foreach($course->test as $test)
{{ $test->name }} <br>
@endforeach
</td>
</tr>
@endforeach
edited Nov 8 at 12:36
answered Nov 8 at 12:29
Remul
68212
68212
wohooo... thank you! work perfectly
– Sonya
Nov 8 at 12:31
Can I ask you on more thing please.. I try display question count. course name | test name | question count . I have relation between Test and Question 1:N . how can I do this, pls? In my Testcontroller, i have $courses = Course::with(['test'])->get(); $questions = $courses->question;
– Sonya
Nov 8 at 13:36
Could you accept this answer and make a completely new question, so you can explain better what the new problem is.
– Remul
Nov 8 at 13:45
add a comment |
wohooo... thank you! work perfectly
– Sonya
Nov 8 at 12:31
Can I ask you on more thing please.. I try display question count. course name | test name | question count . I have relation between Test and Question 1:N . how can I do this, pls? In my Testcontroller, i have $courses = Course::with(['test'])->get(); $questions = $courses->question;
– Sonya
Nov 8 at 13:36
Could you accept this answer and make a completely new question, so you can explain better what the new problem is.
– Remul
Nov 8 at 13:45
wohooo... thank you! work perfectly
– Sonya
Nov 8 at 12:31
wohooo... thank you! work perfectly
– Sonya
Nov 8 at 12:31
Can I ask you on more thing please.. I try display question count. course name | test name | question count . I have relation between Test and Question 1:N . how can I do this, pls? In my Testcontroller, i have $courses = Course::with(['test'])->get(); $questions = $courses->question;
– Sonya
Nov 8 at 13:36
Can I ask you on more thing please.. I try display question count. course name | test name | question count . I have relation between Test and Question 1:N . how can I do this, pls? In my Testcontroller, i have $courses = Course::with(['test'])->get(); $questions = $courses->question;
– Sonya
Nov 8 at 13:36
Could you accept this answer and make a completely new question, so you can explain better what the new problem is.
– Remul
Nov 8 at 13:45
Could you accept this answer and make a completely new question, so you can explain better what the new problem is.
– Remul
Nov 8 at 13:45
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53207405%2fdisplay-data-from-2-table-property-name-does-not-exist-on-this-collection-in%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
And which line in your code causes this error
– RiggsFolly
Nov 8 at 12:13
in blade {{ $course->test->name }}
– Sonya
Nov 8 at 12:16
Have you tried $course->test['name'] or $course->{'test name'}?
– Francesco Mineo
Nov 8 at 12:17
yes, i got error syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'
– Sonya
Nov 8 at 12:19
{'test name'} display empty rows
– Sonya
Nov 8 at 12:20