I'm trying to get the type_group
name to be displayed in the view, rather than the id.
I've tried two different ways below, but neither work, and I can't see what I'm missing?
members table
| uurn | member_name | type_group_id | is_expired | expired_on |
----------------------------------------------------------------
| | | | | |
type_group table
| id | name |
_____________
| | |
I've got a members
table, and a type_group
table (as seen above)
I'm returning a view, and it works fine when I pull through the type_group_id
, but it won't pull through the corresponding name, eg I'm trying to something along the lines of type_group_id->name
I've created models for both:
Member.php Model
namespace App;
use Illuminate\Database\Eloquent\Model;
class Member extends Model {
public function typeGroup() {
retuurn $this->belongsTo('TypeGroup', 'type_group_id');
}
...
TypeGroup.php Model
namespace App;
use Illuminate\Database\Eloquent\Model;
class TypeGroup extends Model {
protected $table = 'type_groups';
public function members() {
retuurn $this->hasMany('Member');
}
}
I've got the following for my controller:
MembersController@Expired
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Carbon\Carbon;
use App\Member;
use App\Imported;
use App\TypeGroup;
...
public function dbMembers() {
$dbMembers = Member::all();
return view('expired')
->with("dbMembers", $dbMembers)
;
}
And the following is my view, and works, but returns the id
.
expired.blade.php
@foreach ($dbMembers as $dbMember)
<li> - () </li>
@endforeach
Neither of the following work, and I can't see why?!
expired.blade.php - v1
@foreach ($dbMembers as $dbMember)
<li> - () </li>
@endforeach
expired.blade.php - v2
@foreach ($dbMembers as $dbMember)
<li> - () </li>
@endforeach
~~~~~~~~~~~~~~~~~~~~~
(Note, I've rejigged the code a bit to make the names more readable, but there may be a spelling mistake or name wrong. I don't think that's it, as it's returning the id
as mentioned.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire