0
votes

Comment passer une variable dans la méthode de vue de Laravel

Comment puis-je passer une variable pouvant être analysée par la méthode de vue () à Laravel?

  public function index($department_id) { 

     $employees=Employee::all();  
     $department=Department::find($department_id); 

     return view('departments.$department->department_code.index')->with('department',$department)->with('employees', $employees); 
  }


0 commentaires

3 Réponses :


0
votes

Si vous souhaitez utiliser des variables en ligne dans une chaîne, vous devez utiliser des guillemets doubles ( "). XXX


0 commentaires

2
votes
return view(sprintf('departments.%s.index', $department->department_code), [
    'departments' => $departments,
    'employees' => $employees,
]);

0 commentaires

0
votes

Vous pouvez le faire:

return view("departments.$department->department_code.index", compact('employees','department'))


0 commentaires