I have spend days trying to figure out why my pagination stops working as soon as I apply it to a user model. Here is the scenario: I am making a website which is a note takes, a user can take notes save them and all that. On a page /notes all notes made can be seen used for me to see weather each user is able to save notes. Pagination works there without a problem. Once I made a user Dashboard and I show notes they made with their user id I get this error:
Method links does not exist …\vendor\laravel\framework\src\Illuminate\Support\Traits\Macroable.php 96
It is very frustrating as I have no clue why this is happening. When I delete the code from view: - the error goes away and so does pagination. The moment I put it in the error happens all over again.
Here is the code from my view and controllers. Anything else needed please let me know, I am desparate my last solution will be to code the whole thing from scratch but I don't want to. Please any help would be appreciated.
DashboardController:
public function index()
{
$user_id = auth()->user()->id;
$user = User::find($user_id);
$notebooks = DB::table('notebooks', $user->notebooks)->paginate(4);
return view('dashboard')->with('notebooks', $user->notebooks);
}
}
Dashboard View (with paginate links code):
@extends('layouts.app')
@section('content')
<!-- Main component for call to action -->
<div class="container text-center">
<!-- heading -->
<h1 class="pull-xs-left">Your Dashboard</h1>
<br>
<div class="pull-xs-right">
<a class="btn btn-primary" href="/notebook/create" role="button"> New Note +</a>
</div>
<div class="pull-xs-right">
<a class="btn btn-primary" href="/contacts/create" role="button"> New Contact +</a>
</div>
<div class="pull-xs-right">
<!--the dropdown menu -->
<div class="dropdown show">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Sort Notebooks By
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="">Note Number A - Z</a>
<a class="dropdown-item" href="">Note Number Z - A</a>
<a class="dropdown-item" href="">Latest Time Posted</a>
<a class="dropdown-item" href="">Oldest Time Posted</a>
</div>
</div>
</div>
<div class="clearfix">
</div>
<br>
@if(count($notebooks) > 0)
@foreach ($notebooks as $notebook)
<div class="col-sm-3 col-md-3 col-sm-6">
<div class="card" style="width: 26rem;">
<div class="card-header" >
Client:
</div>
<div class="card-block" >
<h4 class="card-title " style="height: 5rem;"><strong><a href="/notebook/" ></a></strong></h4>
<p class="card-text" style="height: 7rem;"></p>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item"><b>Last Updated:</b> </li>
<li class="list-group-item">
<a href="/notebook//edit" class="btn btn-info">Edit Note</a>
</li>
</ul>
<div class="card-block">
{!!Form::open(['action' => ['NotesController@destroy', $notebook->id], 'method' => 'POST'])!!}
{!!Form::close()!!}
</div>
</div>
</div>
@endforeach
</div>
<!-- /container -->
<hr>
<div class="container text-center">
</div>
</div>
@else
<div>
<div class="col-lg-12 no-notes">
<p>No notes found, go ahead and make your first note! :)</p>
<a class="btn btn-primary" href="/notebook/create" role="button"> Make My First Note</a>
</div>
</div>
@endif
@endsection
Just a reminder this works perfectly without the user model. I am lost as how to fit it any help would be appreciated. Using Laravel 5.5.26 as checked today.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire