vendredi 1 juillet 2016

passing pivot table views to laravel

I have seen some of the question here but none of them have solved my problem.I am confused. I have a many to many relation between community and idea model. it is saving values in pivot table perfectly but i am unable to fetch data to view.

Idea Model: public function communities() { return $this->belongsToMany('App\Community', "community_idea"); }

Community model:

public function ideas() {
    return $this->belongsToMany('App\Idea', "community_idea");
}

Store Post Function:

//function for creating Idea
public function storePost(IdeaRequest $request)
{
    if ($request->hasFile('idea_image')) {
        $filename = $request->file('idea_image')->getClientOriginalName();
        $moveImage = $request->file('idea_image')->move('images/', $filename);
    }
    $idea = new Idea();
    $idea->idea_title = $request->input('idea_title');
    $idea->user_id = Auth::id();
    $idea->idea_image = $moveImage;
    $idea->idea_info = $request->input('idea_info');
    $idea->idea_location = $request->input('idea_location');
    $idea->idea_goal = $request->input('idea_goal');
    $idea->idea_description = strip_tags($request->input('idea_description'));
    $idea->save();
    $idea->communities()->attach($request->input('selection'));
    Session::set('idea_id',$idea->id);
    session()->flash('flash_message', 'Your idea has been submitted for Review, Kindly Fill this Work BreakDown of You Work');
    return redirect()->route('create_wbs');
}

VIEW: When i try to use this, it throws

Undefined property: Illuminate\Pagination\LengthAwarePaginator::$communities` error @foreach($ideas->communities as $idea) @if($idea->status == 1)

     <div class="top-project-info">
     <div class="content-info-short clearfix">
     <a href="" class="thumb-img">
     <img src="" alt="">
     </a>
     <div class="wrap-short-detail">
     <h3 class="rs acticle-title"><a class="be-fc-orange" href=""><q></q></a></h3>
     <p class="rs tiny-desc">by <a href="#" class="fw-b fc-gray be-fc-orange"></a></p>
     <p class="rs title-description"></p>
     <p class="rs project-location">
     <i class="icon iLocation"></i>
     
     </p>
     </div>
    </div>
  </div>
</div>
</div><!--end: .grid_3 > .project-short-->
  @endif
@endforeach



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/29gb6O2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire