Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. public function show(Project $project){
  2. ....$projectsindustries = DB::table('projects_industries')->select('*')->where('projects_id', $project->id)->get();
  3. ....$industries = Industry::all();
  4. ....return view('projects.show', compact('project', 'projectsindustries', 'industries'));
  5. }
  6.  
  7. @if($projectsindustries)
  8. ....<ul>
  9. ........@foreach($projectsindustries as $projectindustry)
  10. ............@foreach($industries as $industry)
  11. ................<li><a href="#">{{ $industry::where('id', '=', '$projectindustry->industries_id')->get()->name; }}</a></li>
  12. ............@endforeach
  13. ........@endforeach
  14. ....</ul>
  15. @else
  16. ....<p>no industries.</p>
  17. @endif
  18.  
  19. <?php namespace AppHttpControllers;
  20.  
  21. use DB;
  22. use AppProject;
  23. use AppProjectIndustry;
  24. use AppIndustry;
  25. public function show(Project $project)
  26. {
  27. $projectsindustries = ProjectIndustry::where('projects_id', '=', $project->id)
  28. ->join('industries', 'industries_id', '=', 'industries.id')->get();
  29.  
  30. return view('projects.show', compact('project', 'projectsindustries'));
  31. }
  32.  
  33. public function industries() {
  34. return $this->belongsToMany('Industry', 'projects_industries', 'projects_id', 'industries_id');
  35. }
  36.  
  37. protected $table = 'projects_industries';
  38.  
  39. public function project()
  40. {
  41. return $this->belongsTo('Project', 'id', 'projects_id');
  42. }
  43.  
  44. public function industry()
  45. {
  46. return $this->hasMany('Industry', 'id', 'industries_id');
  47. }
  48.  
  49. <?php namespace App;
  50.  
  51. use IlluminateDatabaseEloquentModel;
  52.  
  53. class Industry extends Model {
  54.  
  55. public function project()
  56. {
  57. return $this->belongsTo('Project');
  58. }
  59.  
  60. }
  61.  
  62. @if($projectsindustries)
  63. <h3>Industries:</h3>
  64. <ul>
  65. @foreach($projectsindustries as $projectindustry)
  66. <li><a href="{{ route('industries.show', $projectindustry->slug) }}">{{ $projectindustry->name }}</a></li>
  67. @endforeach
  68. </ul>
  69. @else
  70. <p>no industries.</p>
  71. @endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement