mardi 26 avril 2016

Displaying data in Blade template

in my controller, I pass my template a list of projects

$projects = Project::all();
return view('projects.index', compact('projects'));

Now a Project has one client, and a client belongs to a project. If I loop my Projects within my view, I get the following data

#attributes: array:11 [▼
    "id" => "25"
    "jobNumber" => "J0001"
    "projectName" => "Some Name"
    "clientId" => "1"
    "clientContact" => "Some Contact"
    "contactEmail" => "email@email.co.uk"
    "status" => "Email"
    "deleted_at" => null
    "created_at" => "2016-04-25 14:15:19"
    "updated_at" => "2016-04-26 10:05:06"
]

As you can see, the clientId is 1. This links to a particular client. Is there any way to get the client name using this ID? I know how to do it in the controller, but I can't pass a variable for each project which has the clients name, this would be too much. As it stands, I am passing the view all of the projects, and each of these has a clientId. Somehow I need to get the named based off this.

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire